Ejemplo n.º 1
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || node.Parent == null || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            paragraph = null;

            if (node.HasChildren)
            {
                Table table = new Table();
                DocxTableProperties tableProperties = new DocxTableProperties();

                tableProperties.FetchTableProperties(node);
                tableProperties.ApplyTableProperties(table, node);

                foreach (DocxNode child in node.Children)
                {
                    if (string.Compare(child.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        node.CopyExtentedStyles(child);
                        ProcessTr(child, table, tableProperties);
                    }
                    else if (tableProperties.IsGroupElement(child.Tag))
                    {
                        node.CopyExtentedStyles(child);
                        ProcessGroupElement(child, table, tableProperties);
                    }
                }

                node.Parent.Append(table);
            }
        }
Ejemplo n.º 2
0
        private void ProcessNonLinkText(DocxNode node, ref Paragraph paragraph)
        {
            foreach (DocxNode child in node.Children)
            {
                if (child.IsText)
                {
                    if (paragraph == null)
                    {
                        paragraph = node.Parent.AppendChild(new Paragraph());
                        OnParagraphCreated(node.ParagraphNode, paragraph);
                    }

                    if (!IsEmptyText(child.InnerHtml))
                    {
                        Run run = paragraph.AppendChild<Run>(new Run(new Text()
                         {
                             Text = ClearHtml(child.InnerHtml),
                             Space = SpaceProcessingModeValues.Preserve
                         }));

                        RunCreated(node, run);
                    }
                }
                else
                {
                    child.ParagraphNode = node.ParagraphNode;
                    child.Parent = node.Parent;
                    node.CopyExtentedStyles(child);
                    ProcessChild(child, ref paragraph);
                }
            }
        }
Ejemplo n.º 3
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            paragraph = null;

            if (node.HasChildren)
            {
                numberFormat = GetNumberFormat(node);

                InitNumberDefinitions(numberFormat);

                foreach (DocxNode child in node.Children)
                {
                    if (string.Compare(child.Tag, liName, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        node.CopyExtentedStyles(child);
                        ProcessLi(child, node.Parent, numberFormat);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        internal override void Process(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties)
        {
            if (node.IsNull() || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            paragraph = null;
            int levelIndex = properties.ContainsKey(levelIndexName) ? Convert.ToInt32(properties[levelIndexName]) : 0;

            if (node.HasChildren)
            {
                short numberId = gNumberId = ++context.ListNumberId;

                InitNumberDefinitions(levelIndex);

                var newProperties = properties.ToDictionary(x => x.Key, x => x.Value);
                newProperties[levelIndexName] = levelIndex + 1;

                foreach (DocxNode child in node.Children)
                {
                    //Dirty hack to maintain the level since these elements are singleton. When it traverse to inner html elements, the level will increment
                    //then, when it goes back to more root elements, we have to reset the level to its previous state.
                    gLevelIndex = levelIndex;
                    gNumberId   = numberId;

                    if (string.Compare(child.Tag, liName, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        node.CopyExtentedStyles(child);
                        ProcessLi(child, node.Parent, newProperties);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void ProcessChild(DocxNode node, Dictionary <string, object> properties)
        {
            if (node.IsNull())
            {
                return;
            }

            Paragraph paragraph = node.Parent.AppendChild(new Paragraph());

            OnParagraphCreated(node, paragraph);

            foreach (DocxNode child in node.Children)
            {
                if (child.IsText && !IsEmptyText(child.InnerHtml))
                {
                    Run run = paragraph.AppendChild(new Run(new Text()
                    {
                        Text  = ClearHtml(child.InnerHtml),
                        Space = SpaceProcessingModeValues.Preserve
                    }));

                    RunCreated(node, run);
                }
                else
                {
                    child.ParagraphNode = node;
                    child.Parent        = node.Parent;
                    node.CopyExtentedStyles(child);
                    ProcessChild(child, ref paragraph, properties);
                }
            }
        }
Ejemplo n.º 6
0
        private void ProcessNonLinkText(DocxNode node, ref Paragraph paragraph)
        {
            foreach (DocxNode child in node.Children)
            {
                if (child.IsText)
                {
                    if (paragraph == null)
                    {
                        paragraph = node.Parent.AppendChild(new Paragraph());
                        OnParagraphCreated(node.ParagraphNode, paragraph);
                    }

                    if (!IsEmptyText(child.InnerHtml))
                    {
                        Run run = paragraph.AppendChild <Run>(new Run(new Text()
                        {
                            Text  = ClearHtml(child.InnerHtml),
                            Space = SpaceProcessingModeValues.Preserve
                        }));

                        RunCreated(node, run);
                    }
                }
                else
                {
                    child.ParagraphNode = node.ParagraphNode;
                    child.Parent        = node.Parent;
                    node.CopyExtentedStyles(child);
                    ProcessChild(child, ref paragraph);
                }
            }
        }
Ejemplo n.º 7
0
        private void ProcessTr(DocxNode tr, Table table, DocxTableProperties tableProperties)
        {
            if (tr.HasChildren)
            {
                TableRow row = new TableRow();

                DocxTableRowStyle style = new DocxTableRowStyle();
                style.Process(row, tableProperties);

                int colIndex = 0;

                foreach (DocxNode td in tr.Children)
                {
                    ProcessVerticalSpan(ref colIndex, row, tableProperties);

                    tableProperties.IsCellHeader = string.Compare(td.Tag, DocxTableProperties.thName, StringComparison.InvariantCultureIgnoreCase) == 0;

                    if (string.Compare(td.Tag, DocxTableProperties.tdName, StringComparison.InvariantCultureIgnoreCase) == 0 || tableProperties.IsCellHeader)
                    {
                        tr.CopyExtentedStyles(td);
                        ProcessTd(colIndex++, td, row, tableProperties);
                    }
                }

                if (colIndex < tableProperties.RowSpanInfo.Count)
                {
                    ProcessVerticalSpan(ref colIndex, row, tableProperties);
                }

                table.Append(row);
            }
        }
Ejemplo n.º 8
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || IsHidden(node))
            {
                return;
            }

            string link = node.ExtractAttributeValue(href);

            link = CleanUrl(link);

            if (Uri.IsWellFormedUriString(link, UriKind.Absolute))
            {
                Uri uri = new Uri(link);

                var relationship = context.MainDocumentPart.AddHyperlinkRelationship(uri, uri.IsAbsoluteUri);

                var hyperLink = new Hyperlink()
                {
                    History = true, Id = relationship.Id
                };

                foreach (DocxNode child in node.Children)
                {
                    if (child.IsText)
                    {
                        if (!IsEmptyText(child.InnerHtml))
                        {
                            Run run = hyperLink.AppendChild <Run>(new Run(new Text()
                            {
                                Text  = ClearHtml(child.InnerHtml),
                                Space = SpaceProcessingModeValues.Preserve
                            }));

                            run.RunProperties = new RunProperties((new RunStyle()
                            {
                                Val = "Hyperlink"
                            }));
                            RunCreated(node, run);
                        }
                    }
                    else
                    {
                        child.Parent = hyperLink;
                        node.CopyExtentedStyles(child);
                        ProcessTextElement(child);
                    }
                }

                CreateParagraph(node, ref paragraph);
                paragraph.Append(hyperLink);
            }
            else
            {
                ProcessNonLinkText(node, ref paragraph);
            }
        }
Ejemplo n.º 9
0
 private void ProcessGroupElement(DocxNode tbody, Table table, DocxTableProperties tableProperties)
 {
     foreach (DocxNode tr in tbody.Children)
     {
         if (string.Compare(tr.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0)
         {
             tbody.CopyExtentedStyles(tr);
             ProcessTr(tr, table, tableProperties);
         }
     }
 }
Ejemplo n.º 10
0
        internal override void Process(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties)
        {
            if (node.IsNull() || node.Parent == null || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            if (!node.HasChildren)
            {
                return;
            }

            paragraph = null;

            //Add an empty paragraph to set default margin top
            SetMarginTop(node.Parent);

            foreach (DocxNode child in node.Children)
            {
                if (string.Compare(child.Tag, "dt", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    child.Parent = node.Parent;
                    node.CopyExtentedStyles(child);
                    ProcessChild(child, properties);
                }
                else if (string.Compare(child.Tag, "dd", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    node.CopyExtentedStyles(child);
                    SetDDProperties(child);
                    child.Parent = node.Parent;
                    ProcessChild(child, properties);
                }
            }

            //Add an empty paragraph at the end to set default margin bottom
            SetMarginBottom(node.Parent);
        }
Ejemplo n.º 11
0
 protected void ProcessElement(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties)
 {
     foreach (DocxNode child in node.Children)
     {
         if (child.IsText)
         {
             ProcessParagraph(child, node, node.ParagraphNode, ref paragraph);
         }
         else
         {
             child.ParagraphNode = node.ParagraphNode;
             child.Parent        = node.Parent;
             node.CopyExtentedStyles(child);
             ProcessChild(child, ref paragraph, properties);
         }
     }
 }
Ejemplo n.º 12
0
 protected void ProcessBlockElement(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties)
 {
     foreach (DocxNode child in node.Children)
     {
         if (child.IsText)
         {
             ProcessParagraph(child, node, node, ref paragraph);
         }
         else
         {
             //ProcessChild forwards the incomming parent to the child element. So any div element inside this div
             //creates a new paragraph on the parent element.
             child.ParagraphNode = node;
             child.Parent        = node.Parent;
             node.CopyExtentedStyles(child);
             ProcessChild(child, ref paragraph, properties);
         }
     }
 }
Ejemplo n.º 13
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || node.Parent == null || IsHidden(node))
            {
                return;
            }

            foreach (DocxNode child in node.Children)
            {
                if (child.IsText)
                {
                    if (!IsEmptyText(child.InnerHtml))
                    {
                        ApplyOpenQuoteIfEmpty(node, ref paragraph);

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

                        RunCreated(node, run);
                    }
                }
                else
                {
                    child.ParagraphNode = node.ParagraphNode;
                    child.Parent        = node.Parent;
                    node.CopyExtentedStyles(child);
                    ApplyOpenQuoteIfEmpty(node, ref paragraph);
                    ProcessChild(child, ref paragraph);
                }
            }

            if (paragraph != null && hasOpenQuote)
            {
                paragraph.AppendChild(new Run(new Text()
                {
                    Text = "\""
                }));
            }
        }
Ejemplo n.º 14
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || node.Parent == null || IsHidden(node))
            {
                return;
            }

            foreach (DocxNode child in node.Children)
            {
                if (child.IsText)
                {
                    if (!IsEmptyText(child.InnerHtml))
                    {
                        ApplyOpenQuoteIfEmpty(node, ref paragraph);

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

                        RunCreated(node, run);
                    }
                }
                else
                {
                    child.ParagraphNode = node.ParagraphNode;
                    child.Parent = node.Parent;
                    node.CopyExtentedStyles(child);
                    ApplyOpenQuoteIfEmpty(node, ref paragraph);
                    ProcessChild(child, ref paragraph);
                }
            }

            if (paragraph != null && hasOpenQuote)
            {
                paragraph.AppendChild(new Run(new Text() { Text = "\"" }));
            }
        }
Ejemplo n.º 15
0
        protected void ProcessTextChild(DocxNode node)
        {
            foreach (DocxNode child in node.Children)
            {
                if (child.IsText && !IsEmptyText(child.InnerHtml))
                {
                    Run run = node.Parent.AppendChild(new Run(new Text()
                    {
                        Text = ClearHtml(child.InnerHtml),
                        Space = SpaceProcessingModeValues.Preserve
                    }));

                    RunCreated(node, run);
                }
                else
                {
                    child.Parent = node.Parent;
                    node.CopyExtentedStyles(child);
                    ProcessTextElement(child);
                }
            }
        }
Ejemplo n.º 16
0
 private void ProcessChildren(DocxNode currentNode, DocxNode newNode, Run run)
 {
     foreach (DocxNode child in currentNode.Children)
     {
         if (child.IsText)
         {
             if (!IsEmptyText(child.InnerHtml))
             {
                 run.AppendChild(new Text()
                 {
                     Text = ClearHtml(child.InnerHtml),
                     Space = SpaceProcessingModeValues.Preserve
                 });
             }
         }
         else
         {
             currentNode.CopyExtentedStyles(newNode);
             ProcessTextElement(newNode);
         }
     }
 }
Ejemplo n.º 17
0
        internal override void Process(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties)
        {
            if (node.IsNull() || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            paragraph = null;
            int levelIndex = properties.ContainsKey(levelIndexName) ? Convert.ToInt32(properties[levelIndexName]) : 0;

            if (abstractNum == null)
            {
                InitNumberDefinitions();
            }

            if (node.HasChildren)
            {
                NumberFormatValues numberFormat = GetNumberFormat(node);

                int levelId = gLevelId = gNextLevelId++;

                DefineLevel(numberFormat, levelIndex);

                var newProperties = properties.ToDictionary(x => x.Key, x => x.Value);
                newProperties[levelIndexName] = levelIndex + 1;

                foreach (DocxNode child in node.Children)
                {
                    gLevelIndex = levelIndex;
                    gLevelId    = levelId;

                    if (string.Compare(child.Tag, liName, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        node.CopyExtentedStyles(child);
                        ProcessLi(child, node.Parent, newProperties);
                    }
                }
            }
        }
Ejemplo n.º 18
0
 private void ProcessChildren(DocxNode currentNode, DocxNode newNode, Run run)
 {
     foreach (DocxNode child in currentNode.Children)
     {
         if (child.IsText)
         {
             if (!IsEmptyText(child.InnerHtml))
             {
                 run.AppendChild(new Text()
                 {
                     Text  = ClearHtml(child.InnerHtml),
                     Space = SpaceProcessingModeValues.Preserve
                 });
             }
         }
         else
         {
             currentNode.CopyExtentedStyles(newNode);
             ProcessTextElement(newNode);
         }
     }
 }
Ejemplo n.º 19
0
        protected void ProcessTextChild(DocxNode node, Dictionary <string, object> properties)
        {
            foreach (DocxNode child in node.Children)
            {
                if (child.IsText && !IsEmptyText(child.InnerHtml))
                {
                    Run run = node.Parent.AppendChild(new Run(new Text()
                    {
                        Text  = ClearHtml(child.InnerHtml),
                        Space = SpaceProcessingModeValues.Preserve
                    }));

                    RunCreated(node, run);
                }
                else
                {
                    child.Parent = node.Parent;
                    node.CopyExtentedStyles(child);
                    ProcessTextElement(child, properties);
                }
            }
        }
Ejemplo n.º 20
0
        private void ProcessLi(DocxNode li, OpenXmlElement parent, NumberFormatValues numberFormat)
        {
            Paragraph paragraph = null;

            isParagraphCreated = false;

            ParagraphCreated = OnOLParagraphCreated;

            foreach (DocxNode child in li.Children)
            {
                if (child.IsText)
                {
                    if (!IsEmptyText(child.InnerHtml))
                    {
                        if (paragraph == null)
                        {
                            paragraph = CreateParagraph(li, parent);
                        }

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

                        RunCreated(li, run);
                    }
                }
                else
                {
                    child.ParagraphNode = li;
                    child.Parent        = parent;
                    li.CopyExtentedStyles(child);
                    ProcessChild(child, ref paragraph);
                }
            }
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
0
 protected void ProcessElement(DocxNode node, ref Paragraph paragraph)
 {
     foreach (DocxNode child in node.Children)
     {
         if (child.IsText)
         {
             ProcessParagraph(child, node, node.ParagraphNode, ref paragraph);
         }
         else
         {
             child.ParagraphNode = node.ParagraphNode;
             child.Parent = node.Parent;
             node.CopyExtentedStyles(child);
             ProcessChild(child, ref paragraph);
         }
     }
 }
Ejemplo n.º 23
0
 protected void ProcessBlockElement(DocxNode node, ref Paragraph paragraph)
 {
     foreach (DocxNode child in node.Children)
     {
         if (child.IsText)
         {
             ProcessParagraph(child, node, node, ref paragraph);
         }
         else
         {
             //ProcessChild forwards the incomming parent to the child element. So any div element inside this div
             //creates a new paragraph on the parent element.
             child.ParagraphNode = node;
             child.Parent = node.Parent;
             node.CopyExtentedStyles(child);
             ProcessChild(child, ref paragraph);
         }
     }
 }
Ejemplo n.º 24
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);
        }
Ejemplo n.º 25
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            paragraph = null;

            if (node.HasChildren)
            {
                numberFormat = GetNumberFormat(node);

                InitNumberDefinitions(numberFormat);

                foreach (DocxNode child in node.Children)
                {
                    if (string.Compare(child.Tag, liName, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        node.CopyExtentedStyles(child);
                        ProcessLi(child, node.Parent, numberFormat);
                    }
                }
            }
        }
Ejemplo n.º 26
0
        private void ProcessLi(DocxNode li, OpenXmlElement parent, NumberFormatValues numberFormat)
        {
            Paragraph paragraph = null;
            isParagraphCreated = false;

            ParagraphCreated = OnOLParagraphCreated;

            foreach (DocxNode child in li.Children)
            {
                if (child.IsText)
                {
                    if (!IsEmptyText(child.InnerHtml))
                    {
                        if (paragraph == null)
                        {
                            paragraph = CreateParagraph(li, parent);
                        }

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

                        RunCreated(li, run);
                    }
                }
                else
                {
                    child.ParagraphNode = li;
                    child.Parent = parent;
                    li.CopyExtentedStyles(child);
                    ProcessChild(child, ref paragraph);
                }
            }
        }
Ejemplo n.º 27
0
        private void ProcessTr(DocxNode tr, Table table, DocxTableProperties tableProperties)
        {
            if (tr.HasChildren)
            {
                TableRow row = new TableRow();

                DocxTableRowStyle style = new DocxTableRowStyle();
                style.Process(row, tableProperties);

                int colIndex = 0;

                foreach (DocxNode td in tr.Children)
                {
                    ProcessVerticalSpan(ref colIndex, row, tableProperties);

                    tableProperties.IsCellHeader = string.Compare(td.Tag, DocxTableProperties.thName, StringComparison.InvariantCultureIgnoreCase) == 0;

                    if (string.Compare(td.Tag, DocxTableProperties.tdName, StringComparison.InvariantCultureIgnoreCase) == 0 || tableProperties.IsCellHeader)
                    {
                        tr.CopyExtentedStyles(td);
                        ProcessTd(colIndex++, td, row, tableProperties);
                    }
                }

                if (colIndex < tableProperties.RowSpanInfo.Count)
                {
                    ProcessVerticalSpan(ref colIndex, row, tableProperties);
                }

                table.Append(row);
            }
        }
Ejemplo n.º 28
0
 private void ProcessTBody(DocxNode tbody, Table table, DocxTableProperties tableProperties)
 {
     foreach (DocxNode tr in tbody.Children)
     {
         if (string.Compare(tr.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0)
         {
             tbody.CopyExtentedStyles(tr);
             ProcessTr(tr, table, tableProperties);
         }
     }
 }
Ejemplo n.º 29
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || node.Parent == null || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            paragraph = null;

            if (node.HasChildren)
            {
                Table table = new Table();
                DocxTableProperties tableProperties = new DocxTableProperties();

                tableProperties.FetchTableProperties(node);
                tableProperties.ApplyTableProperties(table, node);

                foreach (DocxNode child in node.Children)
                {
                    if (string.Compare(child.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        node.CopyExtentedStyles(child);
                        ProcessTr(child, table, tableProperties);
                    }
                    else if (string.Compare(child.Tag, DocxTableProperties.tbody, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        node.CopyExtentedStyles(child);
                        ProcessTBody(child, table, tableProperties);
                    }
                }

                node.Parent.Append(table);
            }
        }
Ejemplo n.º 30
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || IsHidden(node))
            {
                return;
            }

            string link = node.ExtractAttributeValue(href);

            link = CleanUrl(link);

            if (Uri.IsWellFormedUriString(link, UriKind.Absolute))
            {
                Uri uri = new Uri(link);

                var relationship = context.MainDocumentPart.AddHyperlinkRelationship(uri, uri.IsAbsoluteUri);

                var hyperLink = new Hyperlink() { History = true, Id = relationship.Id };

                foreach (DocxNode child in node.Children)
                {
                    if (child.IsText)
                    {
                        if (!IsEmptyText(child.InnerHtml))
                        {
                            Run run = hyperLink.AppendChild<Run>(new Run(new Text()
                             {
                                 Text = ClearHtml(child.InnerHtml),
                                 Space = SpaceProcessingModeValues.Preserve
                             }));

                            run.RunProperties = new RunProperties((new RunStyle() { Val = "Hyperlink" }));
                            RunCreated(node, run);
                        }
                    }
                    else
                    {
                        child.Parent = hyperLink;
                        node.CopyExtentedStyles(child);
                        ProcessTextElement(child);
                    }
                }

                CreateParagraph(node, ref paragraph);
                paragraph.Append(hyperLink);
            }
            else
            {
                ProcessNonLinkText(node, ref paragraph);
            }
        }
Ejemplo n.º 31
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || node.Parent == null || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            if (!node.HasChildren)
            {
                return;
            }

            paragraph = null;

            //Add an empty paragraph to set default margin top
            SetMarginTop(node.Parent);

            foreach (DocxNode child in node.Children)
            {
                if (string.Compare(child.Tag, "dt", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    child.Parent = node.Parent;
                    node.CopyExtentedStyles(child);
                    ProcessChild(child);
                }
                else if (string.Compare(child.Tag, "dd", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    node.CopyExtentedStyles(child);
                    SetDDProperties(child);
                    child.Parent = node.Parent;
                    ProcessChild(child);
                }
            }

            //Add an empty paragraph at the end to set default margin bottom
            SetMarginBottom(node.Parent);
        }