示例#1
0
        private void ProcessTd(int colIndex, DocxNode td, TableRow row, DocxTableProperties tableProperties)
        {
            TableCell cell       = new TableCell();
            bool      hasRowSpan = false;

            string rowSpan = td.ExtractAttributeValue(DocxTableProperties.rowSpan);
            Int32  rowSpanValue;

            if (Int32.TryParse(rowSpan, out rowSpanValue))
            {
                tableProperties.RowSpanInfo[colIndex] = rowSpanValue - 1;
                hasRowSpan = true;
            }

            DocxTableCellStyle style = new DocxTableCellStyle();

            style.HasRowSpan = hasRowSpan;
            style.Process(cell, tableProperties, td);

            if (td.HasChildren)
            {
                Paragraph para = null;

                //If the cell is th header, apply font-weight:bold to the text
                if (tableProperties.IsCellHeader)
                {
                    SetThStyleToRun(td);
                }

                foreach (DocxNode child in td.Children)
                {
                    td.CopyExtentedStyles(child);

                    if (child.IsText)
                    {
                        if (!IsEmptyText(child.InnerHtml))
                        {
                            if (para == null)
                            {
                                para = cell.AppendChild(new Paragraph());
                                OnParagraphCreated(DocxTableCellStyle.GetHtmlNodeForTableCellContent(td), para);
                            }

                            Run run = para.AppendChild(new Run(new Text()
                            {
                                Text  = ClearHtml(child.InnerHtml),
                                Space = SpaceProcessingModeValues.Preserve
                            }));

                            RunCreated(child, run);
                        }
                    }
                    else
                    {
                        child.ParagraphNode = DocxTableCellStyle.GetHtmlNodeForTableCellContent(td);
                        child.Parent        = cell;
                        td.CopyExtentedStyles(child);
                        ProcessChild(child, ref para);
                    }
                }
            }

            //The last element of the table cell must be a paragraph.
            var lastElement = cell.Elements().LastOrDefault();

            if (lastElement == null || !(lastElement is Paragraph))
            {
                cell.AppendChild(new Paragraph());
            }

            row.Append(cell);
        }
示例#2
0
        private void ProcessTd(int colIndex, DocxNode td, TableRow row, DocxTableProperties tableProperties)
        {
            TableCell cell = new TableCell();
            bool hasRowSpan = false;

            string rowSpan = td.ExtractAttributeValue(DocxTableProperties.rowSpan);
            Int32 rowSpanValue;
            if (Int32.TryParse(rowSpan, out rowSpanValue))
            {
                tableProperties.RowSpanInfo[colIndex] = rowSpanValue - 1;
                hasRowSpan = true;
            }

            DocxTableCellStyle style = new DocxTableCellStyle();
            style.HasRowSpan = hasRowSpan;
            style.Process(cell, tableProperties, td);

            if (td.HasChildren)
            {
                Paragraph para = null;

                //If the cell is th header, apply font-weight:bold to the text
                if (tableProperties.IsCellHeader)
                {
                    SetThStyleToRun(td);
                }

                foreach (DocxNode child in td.Children)
                {
                    td.CopyExtentedStyles(child);
                    
                    if (child.IsText)
                    {
                        if (!IsEmptyText(child.InnerHtml))
                        {
                            if (para == null)
                            {
                                para = cell.AppendChild(new Paragraph());
                                OnParagraphCreated(DocxTableCellStyle.GetHtmlNodeForTableCellContent(td), para);
                            }

                            Run run = para.AppendChild(new Run(new Text()
                            {
                                Text = ClearHtml(child.InnerHtml),
                                Space = SpaceProcessingModeValues.Preserve
                            }));

                            RunCreated(child, run);
                        }
                    }
                    else
                    {
                        child.ParagraphNode = DocxTableCellStyle.GetHtmlNodeForTableCellContent(td);
                        child.Parent = cell;
                        td.CopyExtentedStyles(child);
                        ProcessChild(child, ref para);
                    }
                }
            }

            //The last element of the table cell must be a paragraph.
            var lastElement = cell.Elements().LastOrDefault();

            if (lastElement == null || !(lastElement is Paragraph))
            {
                cell.AppendChild(new Paragraph());
            }

            row.Append(cell);
        }