Esempio n. 1
0
        protected override void ProcessTable(HWPFDocumentCore wordDocument, XmlElement flow,
                Table table)
        {
            XmlElement tableHeader = foDocumentFacade.CreateTableHeader();
            XmlElement tableBody = foDocumentFacade.CreateTableBody();

            int[] tableCellEdges = WordToHtmlUtils.BuildTableCellEdgesArray(table);
            int tableRows = table.NumRows;

            int maxColumns = int.MinValue;
            for (int r = 0; r < tableRows; r++)
            {
                maxColumns = Math.Max(maxColumns, table.GetRow(r).NumCells());
            }

            for (int r = 0; r < tableRows; r++)
            {
                TableRow tableRow = table.GetRow(r);

                XmlElement tableRowElement = foDocumentFacade.CreateTableRow();
                WordToFoUtils.SetTableRowProperties(tableRow, tableRowElement);

                // index of current element in tableCellEdges[]
                int currentEdgeIndex = 0;
                int rowCells = tableRow.NumCells();
                for (int c = 0; c < rowCells; c++)
                {
                    TableCell tableCell = tableRow.GetCell(c);

                    if (tableCell.IsVerticallyMerged() && !tableCell.IsFirstVerticallyMerged())
                    {
                        currentEdgeIndex += getTableCellEdgesIndexSkipCount(table,
                                r, tableCellEdges, currentEdgeIndex, c, tableCell);
                        continue;
                    }

                    XmlElement tableCellElement = foDocumentFacade.CreateTableCell();
                    WordToFoUtils.SetTableCellProperties(tableRow, tableCell,
                            tableCellElement, r == 0, r == tableRows - 1, c == 0,
                            c == rowCells - 1);

                    int colSpan = GetNumberColumnsSpanned(tableCellEdges,
                            currentEdgeIndex, tableCell);
                    currentEdgeIndex += colSpan;

                    if (colSpan == 0)
                        continue;

                    if (colSpan != 1)
                        tableCellElement.SetAttribute("number-columns-spanned", (colSpan).ToString());

                    int rowSpan = GetNumberRowsSpanned(table, r, c, tableCell);
                    if (rowSpan > 1)
                        tableCellElement.SetAttribute("number-rows-spanned", (rowSpan).ToString());

                    ProcessParagraphes(wordDocument, tableCellElement, tableCell,
                            table.TableLevel);

                    if (!tableCellElement.HasChildNodes)
                    {
                        tableCellElement.AppendChild(foDocumentFacade
                                .CreateBlock());
                    }

                    tableRowElement.AppendChild(tableCellElement);
                }

                if (tableRowElement.HasChildNodes)
                {
                    if (tableRow.isTableHeader())
                    {
                        tableHeader.AppendChild(tableRowElement);
                    }
                    else
                    {
                        tableBody.AppendChild(tableRowElement);
                    }
                }
            }

            XmlElement tableElement = foDocumentFacade.CreateTable();
            tableElement.SetAttribute("table-layout", "fixed");
            if (tableHeader.HasChildNodes)
            {
                tableElement.AppendChild(tableHeader);
            }
            if (tableBody.HasChildNodes)
            {
                tableElement.AppendChild(tableBody);
                flow.AppendChild(tableElement);
            }
            else
            {
                logger.Log(POILogger.WARN, "Table without body starting on offset " + table.StartOffset + " -- " + table.EndOffset);
            }
        }
Esempio n. 2
0
        protected override void ProcessParagraph(HWPFDocumentCore hwpfDocument,
                XmlElement parentFopElement, int currentTableLevel,
                Paragraph paragraph, String bulletText)
        {
            XmlElement block = foDocumentFacade.CreateBlock();
            parentFopElement.AppendChild(block);

            WordToFoUtils.SetParagraphProperties(paragraph, block);

            int charRuns = paragraph.NumCharacterRuns;

            if (charRuns == 0)
            {
                return;
            }

            bool haveAnyText = false;

            if (!string.IsNullOrEmpty(bulletText))
            {
                XmlElement inline = foDocumentFacade.CreateInline();
                block.AppendChild(inline);

                XmlText textNode = foDocumentFacade.CreateText(bulletText);
                inline.AppendChild(textNode);

                haveAnyText |= bulletText.Trim().Length != 0;
            }

            haveAnyText = ProcessCharacters(hwpfDocument, currentTableLevel, paragraph, block);

            if (!haveAnyText)
            {
                XmlElement leader = foDocumentFacade.CreateLeader();
                block.AppendChild(leader);
            }

            WordToFoUtils.CompactInlines(block);
            return;
        }
Esempio n. 3
0
        protected override void ProcessSection(HWPFDocumentCore wordDocument,
                NPOI.HWPF.UserModel.Section section, int sectionCounter)
        {
            String regularPage = CreatePageMaster(section, "page", sectionCounter);

            XmlElement pageSequence = foDocumentFacade.AddPageSequence(regularPage);
            XmlElement flow = foDocumentFacade.AddFlowToPageSequence(pageSequence, "xsl-region-body");

            ProcessParagraphes(wordDocument, flow, section, int.MinValue);

            if (endnotes != null && endnotes.Count != 0)
            {
                foreach (XmlElement endnote in endnotes)
                    flow.AppendChild(endnote);
                endnotes.Clear();
            }
        }
Esempio n. 4
0
        protected override void ProcessPageBreak(HWPFDocumentCore wordDocument, XmlElement flow)
        {
            XmlElement block = null;
            XmlNodeList childNodes = flow.ChildNodes;
            if (childNodes.Count > 0)
            {
                XmlNode lastChild = childNodes[childNodes.Count - 1];
                if (lastChild is XmlElement)
                {
                    XmlElement lastElement = (XmlElement)lastChild;
                    if (!lastElement.HasAttribute("break-after"))
                    {
                        block = lastElement;
                    }
                }
            }

            if (block == null)
            {
                block = foDocumentFacade.CreateBlock();
                flow.AppendChild(block);
            }
            block.SetAttribute("break-after", "page");
        }
Esempio n. 5
0
        protected override void ProcessPageref(HWPFDocumentCore hwpfDocument,
                XmlElement currentBlock, Range textRange, int currentTableLevel,
                String pageref)
        {
            XmlElement basicLink = foDocumentFacade
                    .CreateBasicLinkInternal("bookmark_" + pageref);
            currentBlock.AppendChild(basicLink);

            if (textRange != null)
                ProcessCharacters(hwpfDocument, currentTableLevel, textRange,
                        basicLink);
        }
Esempio n. 6
0
        protected override void ProcessBookmarks(HWPFDocumentCore wordDocument,
                XmlElement currentBlock, Range range, int currentTableLevel,
                IList<Bookmark> rangeBookmarks)
        {
            XmlElement parent = currentBlock;
            foreach (Bookmark bookmark in rangeBookmarks)
            {
                XmlElement bookmarkElement = foDocumentFacade.CreateInline();
                String idName = "bookmark_" + bookmark.Name;
                // make sure ID used once
                if (SetId(bookmarkElement, idName))
                {
                    /*
                     * if it just empty fo:inline without "id" attribute doesn't
                     * making sense to add it to DOM
                     */
                    parent.AppendChild(bookmarkElement);
                    parent = bookmarkElement;
                }
            }

            if (range != null)
                ProcessCharacters(wordDocument, currentTableLevel, range, parent);
        }
Esempio n. 7
0
        protected override void ProcessHyperlink(HWPFDocumentCore wordDocument,
                XmlElement currentBlock, Range textRange, int currentTableLevel,
                String hyperlink)
        {
            XmlElement basicLink = foDocumentFacade
                    .CreateBasicLinkExternal(hyperlink);
            currentBlock.AppendChild(basicLink);

            if (textRange != null)
                ProcessCharacters(wordDocument, currentTableLevel, textRange, basicLink);
        }
        protected override void ProcessTable(HWPFDocumentCore wordDocument, XmlElement flow,
                Table table)
        {
            int tableRows = table.NumRows;
            for (int r = 0; r < tableRows; r++)
            {
                TableRow tableRow = table.GetRow(r);

                XmlElement tableRowElement = textDocumentFacade.CreateTableRow();

                int rowCells = tableRow.NumCells();
                for (int c = 0; c < rowCells; c++)
                {
                    TableCell tableCell = tableRow.GetCell(c);

                    XmlElement tableCellElement = textDocumentFacade.CreateTableCell();

                    if (c != 0)
                        tableCellElement.AppendChild(textDocumentFacade
                                .CreateText("\t"));
                    ProcessCharacters(wordDocument, table.TableLevel, tableCell, tableCellElement);
                    tableRowElement.AppendChild(tableCellElement);
                }

                tableRowElement.AppendChild(textDocumentFacade.CreateText("\n"));
                flow.AppendChild(tableRowElement);
            }
        }
 public static String GetText(HWPFDocumentCore wordDocument)
 {
     WordToTextConverter wordToTextConverter = new WordToTextConverter(new XmlDocument());
     wordToTextConverter.ProcessDocument(wordDocument);
     return wordToTextConverter.GetText();
 }
Esempio n. 10
0
 protected override void ProcessParagraph(HWPFDocumentCore wordDocument,
         XmlElement parentElement, int currentTableLevel, Paragraph paragraph,
         String bulletText)
 {
     XmlElement pElement = textDocumentFacade.CreateParagraph();
     pElement.AppendChild(textDocumentFacade.CreateText(bulletText));
     ProcessCharacters(wordDocument, currentTableLevel, paragraph, pElement);
     pElement.AppendChild(textDocumentFacade.CreateText("\n"));
     parentElement.AppendChild(pElement);
 }
Esempio n. 11
0
 protected override void ProcessSection(HWPFDocumentCore wordDocument,
         NPOI.HWPF.UserModel.Section section, int s)
 {
     XmlElement sectionElement = textDocumentFacade.CreateBlock();
     ProcessParagraphes(wordDocument, sectionElement, section, int.MinValue);
     sectionElement.AppendChild(textDocumentFacade.CreateText("\n"));
     textDocumentFacade.Body.AppendChild(sectionElement);
 }
Esempio n. 12
0
 protected override void ProcessPageref(HWPFDocumentCore wordDocument,
         XmlElement currentBlock, Range textRange, int currentTableLevel,
         String pageref)
 {
     ProcessCharacters(wordDocument, currentTableLevel, textRange,
             currentBlock);
 }
Esempio n. 13
0
 protected override void ProcessPageBreak(HWPFDocumentCore wordDocument, XmlElement flow)
 {
     XmlElement block = textDocumentFacade.CreateBlock();
     block.AppendChild(textDocumentFacade.CreateText("\n"));
     flow.AppendChild(block);
 }
Esempio n. 14
0
        protected override void ProcessHyperlink(HWPFDocumentCore wordDocument,
                XmlElement currentBlock, Range textRange, int currentTableLevel,
                String hyperlink)
        {
            ProcessCharacters(wordDocument, currentTableLevel, textRange,
                    currentBlock);

            currentBlock.AppendChild(textDocumentFacade.CreateText(" ("
                    + UNICODECHAR_ZERO_WIDTH_SPACE
                    + hyperlink.Replace("\\/", UNICODECHAR_ZERO_WIDTH_SPACE
                            + "\\/" + UNICODECHAR_ZERO_WIDTH_SPACE)
                    + UNICODECHAR_ZERO_WIDTH_SPACE + ")"));
        }
Esempio n. 15
0
 protected override void ProcessDocumentPart(HWPFDocumentCore wordDocument,
         Range range)
 {
     base.ProcessDocumentPart(wordDocument, range);
     AfterProcess();
 }
Esempio n. 16
0
 protected override void ProcessBookmarks(HWPFDocumentCore wordDocument,
         XmlElement currentBlock, Range range, int currentTableLevel,
         IList<Bookmark> rangeBookmarks)
 {
     ProcessCharacters(wordDocument, currentTableLevel, range, currentBlock);
 }