Пример #1
0
        public ToxyDocument Parse()
        {
            if (!File.Exists(Context.Path))
            {
                throw new FileNotFoundException("File " + Context.Path + " is not found");
            }

            bool extractHeader = false;

            if (Context.Properties.ContainsKey("ExtractHeader"))
            {
                extractHeader = Utility.IsTrue(Context.Properties["ExtractHeader"]);
            }
            bool extractFooter = false;

            if (Context.Properties.ContainsKey("ExtractFooter"))
            {
                extractFooter = Utility.IsTrue(Context.Properties["ExtractFooter"]);
            }

            ToxyDocument rdoc = new ToxyDocument();


            using (FileStream stream = File.OpenRead(Context.Path))
            {
                HWPFDocument worddoc = new HWPFDocument(stream);
                if (extractHeader && worddoc.GetHeaderStoryRange() != null)
                {
                    StringBuilder sb = new StringBuilder();
                    rdoc.Header = worddoc.GetHeaderStoryRange().Text;
                }
                if (extractFooter && worddoc.GetFootnoteRange() != null)
                {
                    StringBuilder sb = new StringBuilder();
                    rdoc.Footer = worddoc.GetFootnoteRange().Text;
                }
                for (int i = 0; i < worddoc.GetRange().NumParagraphs; i++)
                {
                    Paragraph     para = worddoc.GetRange().GetParagraph(i);
                    string        text = para.Text;
                    ToxyParagraph p    = new ToxyParagraph();
                    p.Text = text;
                    //var runs = para.Runs;
                    p.StyleID = para.GetStyleIndex().ToString();

                    //for (int i = 0; i < runs.Count; i++)
                    //{
                    //    var run = runs[i];

                    //}
                    rdoc.Paragraphs.Add(p);
                }
            }
            return(rdoc);
        }
Пример #2
0
        public void TestContents()
        {
            HWPFDocument doc = docAscii;

            for (int run = 0; run < 3; run++)
            {
                Range r;

                // Now check the real ranges
                r = doc.GetRange();
                Assert.AreEqual(
                    a_page_1 +
                    page_break + "\r" +
                    a_page_2,
                    r.Text
                    );

                r = doc.GetHeaderStoryRange();
                Assert.AreEqual(
                    headerDef +
                    a_header +
                    footerDef +
                    a_footer +
                    endHeaderFooter,
                    r.Text
                    );

                r = doc.GetOverallRange();
                Assert.AreEqual(
                    a_page_1 +
                    page_break + "\r" +
                    a_page_2 +
                    headerDef +
                    a_header +
                    footerDef +
                    a_footer +
                    endHeaderFooter +
                    "\r",
                    r.Text
                    );

                // Write out and read back in again, Ready for
                //  the next run of the Test
                // TODO run more than once
                if (run < 1)
                {
                    doc = HWPFTestDataSamples.WriteOutAndReadBack(doc);
                }
            }
        }
Пример #3
0
        public HeaderStories(HWPFDocument doc)
        {
            this.headerStories = doc.GetHeaderStoryRange();
            FileInformationBlock fib = doc.GetFileInformationBlock();

            // If there's no PlcfHdd, nothing to do
            if (fib.GetCcpHdd() == 0)
            {
                return;
            }
            if (fib.GetPlcfHddSize() == 0)
            {
                return;
            }

            // Handle the PlcfHdd
            plcfHdd = new PlexOfCps(
                    doc.GetTableStream(), fib.GetPlcfHddOffset(),
                    fib.GetPlcfHddSize(), 0
            );
        }
Пример #4
0
        public HeaderStories(HWPFDocument doc)
        {
            this.headerStories = doc.GetHeaderStoryRange();
            FileInformationBlock fib = doc.GetFileInformationBlock();

            // If there's no PlcfHdd, nothing to do
            if (fib.GetCcpHdd() == 0)
            {
                return;
            }
            if (fib.GetPlcfHddSize() == 0)
            {
                return;
            }

            // Handle the PlcfHdd
            plcfHdd = new PlexOfCps(
                doc.GetTableStream(), fib.GetPlcfHddOffset(),
                fib.GetPlcfHddSize(), 0
                );
        }
Пример #5
0
        public void TestContentsUnicode()
        {
            Range r;

            // Now check the real ranges
            r = docUnicode.GetRange();
            Assert.AreEqual(
                u_page_1 +
                page_break + "\r" +
                u_page_2,
                r.Text
                );

            r = docUnicode.GetHeaderStoryRange();
            Assert.AreEqual(
                headerDef +
                u_header +
                footerDef +
                u_footer +
                endHeaderFooter,
                r.Text
                );

            r = docUnicode.GetOverallRange();
            Assert.AreEqual(
                u_page_1 +
                page_break + "\r" +
                u_page_2 +
                headerDef +
                u_header +
                footerDef +
                u_footer +
                endHeaderFooter +
                "\r",
                r.Text
                );
        }