private void ApplyStyle(DocxNode node) { string fontFamily = node.ExtractOwnStyleValue(DocxFontStyle.fontFamily); if (string.IsNullOrEmpty(fontFamily)) { string face = node.ExtractAttributeValue("face"); if (!string.IsNullOrEmpty(face)) { node.SetExtentedStyle(DocxFontStyle.fontFamily, face); } } string fontSize = node.ExtractOwnStyleValue(DocxFontStyle.fontSize); if (string.IsNullOrEmpty(fontSize)) { SetFontSize(node); } string color = node.ExtractOwnStyleValue(DocxColor.color); if (string.IsNullOrEmpty(color)) { color = node.ExtractAttributeValue("color"); if (!string.IsNullOrEmpty(color)) { node.SetExtentedStyle(DocxColor.color, color); } } }
private void ApplyStyle(DocxNode node) { string fontFamily = node.ExtractOwnStyleValue(DocxFontStyle.fontFamily); if (string.IsNullOrEmpty(fontFamily)) { string face = node.ExtractAttributeValue("face"); if (!string.IsNullOrEmpty(face)) { node.SetExtentedStyle(DocxFontStyle.fontFamily, face); } } string fontSize = node.ExtractOwnStyleValue(DocxFontStyle.fontSize); if (string.IsNullOrEmpty(fontSize)) { SetFontSize(node); } string color = node.ExtractOwnStyleValue(DocxColor.color); if(string.IsNullOrEmpty(color)) { color = node.ExtractAttributeValue("color"); if(!string.IsNullOrEmpty(color)) { node.SetExtentedStyle(DocxColor.color, color); } } }
internal void FetchTableProperties(DocxNode node) { this.HasDefaultBorder = node.ExtractAttributeValue(DocxBorder.borderName) == "1"; if (short.TryParse(node.ExtractAttributeValue(cellSpacingName), out short value)) { this.CellSpacing = value; } if (short.TryParse(node.ExtractAttributeValue(cellPaddingName), out value)) { this.CellPadding = value; } }
private void ProcessTableBorder(DocxNode node, DocxTableProperties docxProperties, TableProperties tableProperties) { string borderStyle = node.ExtractAttributeValue(DocxBorder.borderName); if (borderStyle == "1") { TableBorders tableBorders = new TableBorders(); DocxBorder.ApplyDefaultBorders(tableBorders); tableProperties.Append(tableBorders); } else { borderStyle = node.ExtractStyleValue(DocxBorder.borderName); string leftBorder = node.ExtractStyleValue(DocxBorder.leftBorderName); string topBorder = node.ExtractStyleValue(DocxBorder.topBorderName); string rightBorder = node.ExtractStyleValue(DocxBorder.rightBorderName); string bottomBorder = node.ExtractStyleValue(DocxBorder.bottomBorderName); TableBorders tableBorders = new TableBorders(); DocxBorder.ApplyBorders(tableBorders, borderStyle, leftBorder, topBorder, rightBorder, bottomBorder, docxProperties.HasDefaultBorder); if (tableBorders.HasChildren) { tableProperties.Append(tableBorders); } } }
private void SetFontSize(DocxNode node) { string size = node.ExtractAttributeValue("size"); if (string.IsNullOrEmpty(size)) { return; } Match match = Regex.Match(size, "^\\d+"); Int32 sizeValue; Int32 fontSizeValue = 0; if (!match.Success || !Int32.TryParse(match.Value, out sizeValue)) { return; } if (!fontSizes.TryGetValue(sizeValue, out fontSizeValue)) { if (sizeValue > 7) { fontSizeValue = 48; } } if (fontSizeValue != 0) { node.SetExtentedStyle(DocxFontStyle.fontSize, string.Concat(fontSizeValue.ToString(), "px")); } }
void ITextElement.Process(DocxNode node) { if (IsHidden(node)) { return; } string contentType; string progId; string data = node.ExtractAttributeValue("data"); if (IsImage(data)) { var interchanger = context.GetInterchanger(); interchanger.ProcessImage(context, data, node); } else if (TryFormat(data, out contentType, out progId)) { EmbeddedObject embeddedObject = ProcessObject(data, contentType, progId); if (embeddedObject != null) { Run run = node.Parent.AppendChild(new Run(embeddedObject)); RunCreated(node, run); } } }
internal override void Process(DocxNode node, ref Paragraph paragraph) { if (IsHidden(node)) { return; } string contentType; string progId; string data = node.ExtractAttributeValue("data"); if (IsImage(data)) { var interchanger = context.GetInterchanger(); interchanger.ProcessImage(context, data, node, ref paragraph); } else if (TryFormat(data, out contentType, out progId)) { EmbeddedObject embeddedObject = ProcessObject(data, contentType, progId); if (embeddedObject != null) { if (paragraph == null) { paragraph = node.Parent.AppendChild(new Paragraph()); OnParagraphCreated(node, paragraph); } Run run = paragraph.AppendChild(new Run(embeddedObject)); RunCreated(node, run); } } }
private void SetFontSize(DocxNode node) { string size = node.ExtractAttributeValue("size"); if (string.IsNullOrEmpty(size)) { return; } Match match = Regex.Match(size, "^\\d+"); if (!match.Success || !Int32.TryParse(match.Value, out int sizeValue)) { return; } if (!fontSizes.TryGetValue(sizeValue, out int fontSizeValue)) { if (sizeValue > 7) { fontSizeValue = 48; } } if (fontSizeValue != 0) { node.SetExtentedStyle(DocxFontStyle.fontSize, string.Concat(fontSizeValue.ToString(), "px")); } }
internal override void Process(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties) { if (IsHidden(node)) { return; } string src = node.ExtractAttributeValue("src"); if (!string.IsNullOrEmpty(src)) { try { Drawing drawing = PrepareImage(src); if (drawing != null) { if (paragraph == null) { paragraph = node.Parent.AppendChild(new Paragraph()); OnParagraphCreated(node, paragraph); } Run run = paragraph.AppendChild(new Run(drawing)); RunCreated(node, run); } } catch { return;//fails silently? } } }
void ITextElement.Process(DocxNode node, Dictionary <string, object> properties) { if (IsHidden(node)) { return; } string src = node.ExtractAttributeValue("src"); if (!string.IsNullOrEmpty(src)) { try { Drawing drawing = PrepareImage(src); if (drawing != null) { Run run = node.Parent.AppendChild(new Run(drawing)); RunCreated(node, run); } } catch { return;//fails silently? } } }
private NumberFormatValues GetNumberFormat(DocxNode node) { NumberFormatValues numberFormat = NumberFormatValues.Decimal; string type = node.ExtractAttributeValue("type"); if (!string.IsNullOrEmpty(type)) { switch (type) { case "1": numberFormat = NumberFormatValues.Decimal; break; case "a": numberFormat = NumberFormatValues.LowerLetter; break; case "A": numberFormat = NumberFormatValues.UpperLetter; break; case "i": numberFormat = NumberFormatValues.LowerRoman; break; case "I": numberFormat = NumberFormatValues.UpperRoman; break; } } return(numberFormat); }
private void ProcessWidth(DocxNode node, TableProperties tableProperties) { string width = node.ExtractAttributeValue(DocxUnits.width); string styleWidth = node.ExtractStyleValue(DocxUnits.width); if (!string.IsNullOrEmpty(styleWidth)) { width = styleWidth; } if (!string.IsNullOrEmpty(width)) { decimal value; TableWidthUnitValues unit; if (DocxUnits.TableUnitsFromStyle(width, out value, out unit)) { TableWidth tableWidth = new TableWidth() { Width = value.ToString(), Type = unit }; tableProperties.Append(tableWidth); } } }
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); } }
private void ProcessColSpan(DocxNode node, TableCellProperties cellProperties) { Int32 value; if (Int32.TryParse(node.ExtractAttributeValue(colspan), out value)) { if (value > 1) { cellProperties.Append(new GridSpan() { Val = value }); } } }
private void ProcessColSpan(DocxNode node, TableCellProperties cellProperties) { if (Int32.TryParse(node.ExtractAttributeValue(colspan), out int value)) { if (value > 1) { cellProperties.Append(new GridSpan() { Val = value }); } } }
private Int32 GetTdCount(DocxNode table) { int count = 0; if (table != null && table.HasChildren) { foreach (DocxNode tr in table.Children) { if (string.Compare(tr.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0) { foreach (DocxNode td in tr.Children) { if (string.Compare(td.Tag, DocxTableProperties.tdName, StringComparison.InvariantCultureIgnoreCase) == 0 || string.Compare(td.Tag, DocxTableProperties.thName, StringComparison.InvariantCultureIgnoreCase) == 0) { string colSpan = table.ExtractAttributeValue("colspan"); Int32 colspanValue; if (!string.IsNullOrEmpty(colspan) && Int32.TryParse(colspan, out colspanValue)) { count += colspanValue; } else { ++count; } } } //Counted first row's td count. Thus exiting break; } } } return(count); }
internal void FetchTableProperties(DocxNode node) { this.HasDefaultBorder = node.ExtractAttributeValue(DocxBorder.borderName) == "1"; Int16 value; if (Int16.TryParse(node.ExtractAttributeValue(cellSpacingName), out value)) { this.CellSpacing = value; } if (Int16.TryParse(node.ExtractAttributeValue(cellPaddingName), out value)) { this.CellPadding = value; } }
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); } }
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); }
private NumberFormatValues GetNumberFormat(DocxNode node) { NumberFormatValues numberFormat = NumberFormatValues.Decimal; string type = node.ExtractAttributeValue("type"); if (!string.IsNullOrEmpty(type)) { switch (type) { case "1": numberFormat = NumberFormatValues.Decimal; break; case "a": numberFormat = NumberFormatValues.LowerLetter; break; case "A": numberFormat = NumberFormatValues.UpperLetter; break; case "i": numberFormat = NumberFormatValues.LowerRoman; break; case "I": numberFormat = NumberFormatValues.UpperRoman; break; } } return numberFormat; }
void ITextElement.Process(DocxNode node) { if (IsHidden(node)) { return; } string src = node.ExtractAttributeValue("src"); if (!string.IsNullOrEmpty(src)) { try { Drawing drawing = PrepareImage(src); if (drawing != null) { Run run = node.Parent.AppendChild(new Run(drawing)); RunCreated(node, run); } } catch { return;//fails silently? } } }
internal override void Process(DocxNode node, ref Paragraph paragraph) { if (IsHidden(node)) { return; } string src = node.ExtractAttributeValue("src"); if (!string.IsNullOrEmpty(src)) { try { Drawing drawing = PrepareImage(src); if (drawing != null) { if (paragraph == null) { paragraph = node.Parent.AppendChild(new Paragraph()); OnParagraphCreated(node, paragraph); } Run run = paragraph.AppendChild(new Run(drawing)); RunCreated(node, run); } } catch { return;//fails silently? } } }
private Int32 GetTdCount(DocxNode table) { int count = 0; if (table != null && table.HasChildren) { foreach (DocxNode tr in table.Children) { if (string.Compare(tr.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0) { foreach (DocxNode td in tr.Children) { if (string.Compare(td.Tag, DocxTableProperties.tdName, StringComparison.InvariantCultureIgnoreCase) == 0 || string.Compare(td.Tag, DocxTableProperties.thName, StringComparison.InvariantCultureIgnoreCase) == 0) { string colSpan = table.ExtractAttributeValue("colspan"); Int32 colspanValue; if (!string.IsNullOrEmpty(colspan) && Int32.TryParse(colspan, out colspanValue)) { count += colspanValue; } else { ++count; } } } //Counted first row's td count. Thus exiting break; } } } return count; }