public void SinglePRedColor() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<p style='color:red'>test</p>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Paragraph paragraph = doc.Document.Body.ChildElements[0] as Paragraph; Run run = paragraph.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); Assert.IsNotNull(run.RunProperties); Word.Color color = run.RunProperties.ChildElements[0] as Word.Color; Assert.AreEqual("FF0000", color.Val.Value); Word.Text text = run.ChildElements[1] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void OnePTag() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser(TestUtility.GetHtmlFromFile("Html\\oneptag.htm"))); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Paragraph para = doc.Document.Body.ChildElements[0] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(1, run.ChildElements.Count); Word.Text text = run.ChildElements[0] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("Test", text.InnerText.Trim()); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); errors.PrintValidationErrors(); Assert.AreEqual(0, errors.Count()); } }
public void DivFontBold() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<div style='font-weight:bold'>test</div>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); OpenXmlElement para = doc.Document.Body.ChildElements[0]; Assert.IsTrue(para is Paragraph); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); Assert.IsNotNull(run.RunProperties); Assert.AreEqual(1, run.RunProperties.ChildElements.Count); Bold bold = run.RunProperties.ChildElements[0] as Bold; Assert.IsNotNull(bold); Word.Text text = run.ChildElements[1] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void iTag() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<i>test</i>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); OpenXmlElement para = doc.Document.Body.ChildElements[0]; Assert.IsTrue(para is Paragraph); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); Assert.IsNotNull(run.RunProperties); Assert.AreEqual(1, run.RunProperties.ChildElements.Count); Italic italic = run.RunProperties.ChildElements[0] as Italic; Assert.IsNotNull(italic); Word.Text text = run.ChildElements[1] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void MinimumStyle() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<div style='font:10px verdana'><div style='font-family:arial'>test</div></div>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); OpenXmlElement para = doc.Document.Body.ChildElements[0]; Assert.IsTrue(para is Paragraph); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); Assert.IsNotNull(run.RunProperties); Assert.AreEqual(2, run.RunProperties.ChildElements.Count); RunFonts fonts = run.RunProperties.ChildElements[0] as RunFonts; Assert.IsNotNull(fonts); Assert.AreEqual("arial", fonts.Ascii.Value); FontSize fontSize = run.RunProperties.ChildElements[1] as FontSize; Assert.IsNotNull(fontSize); Assert.AreEqual("20", fontSize.Val.Value); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void DivRGBColorRed() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<div style='color:rgb(255,0,0)'>test</div>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); OpenXmlElement para = doc.Document.Body.ChildElements[0]; Assert.IsTrue(para is Paragraph); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); Assert.IsNotNull(run.RunProperties); Assert.IsNotNull(run.RunProperties.Color); Assert.AreEqual("FF0000", run.RunProperties.Color.Val.Value); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void SingleDivXXLargeFontSize() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<div style='font-size:xx-large'>test</div>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Paragraph paragraph = doc.Document.Body.ChildElements[0] as Paragraph; Run run = paragraph.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); Assert.IsNotNull(run.RunProperties); FontSize fontSize = run.RunProperties.ChildElements[0] as FontSize; Assert.AreEqual("48", fontSize.Val.Value); Word.Text text = run.ChildElements[1] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void SimpleText() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("test")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); OpenXmlElement para = doc.Document.Body.ChildElements[0]; Assert.IsTrue(para is Paragraph); Assert.AreEqual(1, para.ChildElements.Count); OpenXmlElement run = para.ChildElements[0]; Assert.IsTrue(run is Run); Assert.AreEqual(1, run.ChildElements.Count); OpenXmlElement text = run.ChildElements[0] as DocumentFormat.OpenXml.Wordprocessing.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void UlWithH1() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<ul><li><h1>test</h1></li></ul>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Paragraph para = doc.Document.Body.ChildElements[0] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(2, para.ChildElements.Count); ParagraphProperties properties = para.ChildElements[0] as ParagraphProperties; Assert.IsNotNull(properties); Assert.AreEqual(2, properties.ChildElements.Count); ParagraphStyleId paragraphStyleId = properties.ChildElements[0] as ParagraphStyleId; Assert.IsNotNull(paragraphStyleId); Assert.AreEqual("ListParagraph", paragraphStyleId.Val.Value); NumberingProperties numberingProperties = properties.ChildElements[1] as NumberingProperties; Assert.IsNotNull(numberingProperties); Assert.AreEqual(2, numberingProperties.ChildElements.Count); NumberingLevelReference numberingLevelReference = numberingProperties.ChildElements[0] as NumberingLevelReference; Assert.IsNotNull(numberingLevelReference); Assert.AreEqual(0, numberingLevelReference.Val.Value); NumberingId numberingId = numberingProperties.ChildElements[1] as NumberingId; Assert.IsNotNull(numberingId); Assert.AreEqual((Int32)NumberFormatValues.Bullet, numberingId.Val.Value); Run run = para.ChildElements[1] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); RunProperties runProperties = run.ChildElements[0] as RunProperties; Assert.IsNotNull(runProperties); Bold bold = runProperties.ChildElements[0] as Bold; Assert.IsNotNull(bold); FontSize fontSize = runProperties.ChildElements[1] as FontSize; Assert.IsNotNull(fontSize); Assert.AreEqual("48", fontSize.Val.Value); Word.Text text = run.ChildElements[1] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void EmptyBody() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<body></body>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(0, doc.Document.Body.ChildElements.Count); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void MaximumStyle() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<div style='font:italic normal bold 10px/5px verdana'><div style='font-size:20px'>test</div></div>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); OpenXmlElement para = doc.Document.Body.ChildElements[0]; Assert.IsTrue(para is Paragraph); Assert.AreEqual(2, para.ChildElements.Count); ParagraphProperties paraProperties = para.ChildElements[0] as ParagraphProperties; Assert.IsNotNull(paraProperties); SpacingBetweenLines space = paraProperties.ChildElements[0] as SpacingBetweenLines; Assert.IsNotNull(space); Assert.AreEqual("100", space.Line.Value); Run run = para.ChildElements[1] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); Assert.IsNotNull(run.RunProperties); Assert.AreEqual(4, run.RunProperties.ChildElements.Count); RunFonts fonts = run.RunProperties.ChildElements[0] as RunFonts; Assert.IsNotNull(fonts); Assert.AreEqual("verdana", fonts.Ascii.Value); Bold bold = run.RunProperties.ChildElements[1] as Bold; Assert.IsNotNull(bold); Italic italic = run.RunProperties.ChildElements[2] as Italic; Assert.IsNotNull(italic); FontSize fontSize = run.RunProperties.ChildElements[3] as FontSize; Assert.IsNotNull(fontSize); Assert.AreEqual("40", fontSize.Val.Value); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void StyleElement() { using (MemoryStream mem = new MemoryStream()) { string html = "<style type=\"text/css\">.cls{font-size:10px;}</style>"; WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser(html)); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(0, doc.Document.Body.ChildElements.Count); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void ScriptElement() { using (MemoryStream mem = new MemoryStream()) { string html = "<script type=\"text/javascript\">console.log('ok');</script>"; WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser(html)); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(0, doc.Document.Body.ChildElements.Count); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void EmptyHtmlBody() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser(TestUtility.GetHtmlFromFile("Html\\emptybody.htm"))); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(0, doc.Document.Body.ChildElements.Count); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); errors.PrintValidationErrors(); Assert.AreEqual(0, errors.Count()); } }
public void FontTagWithAttributes() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<font face=\"Arial\" size=\"3\" color=\"red\">test</font>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Paragraph para = doc.Document.Body.ChildElements[0] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); RunProperties properties = run.ChildElements[0] as RunProperties; Assert.IsNotNull(properties); Assert.AreEqual(3, properties.ChildElements.Count); RunFonts fonts = properties.ChildElements[0] as RunFonts; Assert.IsNotNull(fonts); Assert.AreEqual("Arial", fonts.Ascii.Value); Word.Color color = properties.ChildElements[1] as Word.Color; Assert.AreEqual("FF0000", color.Val.Value); FontSize fontSize = properties.ChildElements[2] as FontSize; Assert.IsNotNull(fontSize); Assert.AreEqual("32", fontSize.Val.Value); var text = run.ChildElements[1] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void OwnStyleOverride() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser(TestUtility.GetHtmlFromFile("Html\\ownstyleoverride.htm"))); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Paragraph para = doc.Document.Body.ChildElements[0] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); RunProperties properties = run.ChildElements[0] as RunProperties; Assert.IsNotNull(properties); Assert.AreEqual(2, properties.ChildElements.Count); Bold bold = properties.ChildElements[0] as Bold; Assert.IsNotNull(bold); FontSize fontSize = properties.ChildElements[1] as FontSize; Assert.IsNotNull(fontSize); Assert.AreEqual("46", fontSize.Val.Value); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); errors.PrintValidationErrors(); Assert.AreEqual(0, errors.Count()); } }
public void SinglePBackGround() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<p style='background-color:#000'>test</p>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Paragraph paragraph = doc.Document.Body.ChildElements[0] as Paragraph; Assert.AreEqual(2, paragraph.ChildElements.Count); Assert.IsNotNull(paragraph.ParagraphProperties); Assert.IsNotNull(paragraph.ParagraphProperties.Shading); Assert.AreEqual("000000", paragraph.ParagraphProperties.Shading.Fill.Value); Assert.AreEqual(Word.ShadingPatternValues.Clear, paragraph.ParagraphProperties.Shading.Val.Value); Run run = paragraph.ChildElements[1] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); RunProperties runProperties = run.ChildElements[0] as RunProperties; Assert.IsNotNull(runProperties); Assert.AreEqual("000000", runProperties.Shading.Fill.Value); Word.Text text = run.ChildElements[1] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void TableCellStyleInheritance() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table><tr><td style='border:1px solid #000;background-color:red'>test</td></tr></table>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Word.Table table = doc.Document.Body.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Assert.AreEqual(3, table.ChildElements.Count); TableRow row = table.ChildElements[2]as TableRow; Assert.IsNotNull(row); Assert.AreEqual(1, row.ChildElements.Count); TableCell cell = row.ChildElements[0]as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(2, cell.ChildElements.Count); TableCellProperties cellProperties = cell.ChildElements[0]as TableCellProperties; Assert.IsNotNull(cellProperties); Assert.AreEqual(2, cellProperties.ChildElements.Count); TableCellBorders borders = cellProperties.ChildElements[0]as TableCellBorders; Assert.IsNotNull(borders); Assert.AreEqual(4, borders.ChildElements.Count); TopBorder topBorder = borders.ChildElements[0] as TopBorder; Assert.IsNotNull(topBorder); TestUtility.TestBorder<TopBorder>(topBorder, BorderValues.Single, "000000", 1U); LeftBorder leftBorder = borders.ChildElements[1] as LeftBorder; Assert.IsNotNull(leftBorder); TestUtility.TestBorder<LeftBorder>(leftBorder, BorderValues.Single, "000000", 1U); BottomBorder bottomBorder = borders.ChildElements[2] as BottomBorder; Assert.IsNotNull(bottomBorder); TestUtility.TestBorder<BottomBorder>(bottomBorder, BorderValues.Single, "000000", 1U); RightBorder rightBorder = borders.ChildElements[3] as RightBorder; Assert.IsNotNull(rightBorder); TestUtility.TestBorder<RightBorder>(rightBorder, BorderValues.Single, "000000", 1U); Word.Shading backgroundColor = cellProperties.ChildElements[1]as Word.Shading; Assert.IsNotNull(backgroundColor); Assert.AreEqual("FF0000", backgroundColor.Fill.Value); Paragraph para = cell.ChildElements[1] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(2, para.ChildElements.Count); ParagraphProperties properties = para.ChildElements[0]as ParagraphProperties; Assert.IsNotNull(properties); Assert.AreEqual(1, properties.ChildElements.Count); Word.Shading shading = properties.ChildElements[0] as Word.Shading; Assert.AreEqual("FF0000", shading.Fill.Value); Run run = para.ChildElements[1]as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); RunProperties runProperties = run.ChildElements[0] as RunProperties; Assert.IsNotNull(runProperties); shading = runProperties.ChildElements[0] as Word.Shading; Assert.AreEqual("FF0000", shading.Fill.Value); Word.Text text = run.ChildElements[1]as Word.Text; Assert.IsNotNull(text); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void TableInsideAnotherTable() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table><tr><td><table><tr><td>test</td></tr></table></td></tr></table>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Word.Table table = doc.Document.Body.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Assert.AreEqual(3, table.ChildElements.Count); TableRow row = table.ChildElements[2] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(1, row.ChildElements.Count); TableCell cell = row.ChildElements[0] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(2, cell.ChildElements.Count); table = cell.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Paragraph para = cell.ChildElements[1] as Paragraph; Assert.IsNotNull(para); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void EmptyCell() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table><tr><td></td></tr></table>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Word.Table table = doc.Document.Body.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Assert.AreEqual(3, table.ChildElements.Count); TableProperties tableProperties = table.ChildElements[0] as TableProperties; Assert.IsNotNull(tableProperties); Assert.AreEqual(1, tableProperties.ChildElements.Count); TableStyle tableStyle = tableProperties.ChildElements[0]as TableStyle; Assert.IsNotNull(tableStyle); Assert.AreEqual("TableGrid", tableStyle.Val.Value); TableGrid tableGrid = table.ChildElements[1] as TableGrid; Assert.IsNotNull(tableGrid); TableRow row = table.ChildElements[2] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(1, row.ChildElements.Count); TableCell cell = row.ChildElements[0] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(1, cell.ChildElements.Count); Paragraph para = cell.ChildElements[0] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(0, para.ChildElements.Count); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void RowSpan() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table><tr><td rowspan='2'></td><td></td></tr><tr><td></td></tr></table>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Word.Table table = doc.Document.Body.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Assert.AreEqual(4, table.ChildElements.Count); TableProperties tableProperties = table.ChildElements[0] as TableProperties; Assert.IsNotNull(tableProperties); Assert.AreEqual(1, tableProperties.ChildElements.Count); TableGrid tableGrid = table.ChildElements[1] as TableGrid; Assert.IsNotNull(tableGrid); TableRow row = table.ChildElements[2] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(2, row.ChildElements.Count); TableCell cell = row.ChildElements[0] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(2, cell.ChildElements.Count); TableCellProperties cellProperties = cell.ChildElements[0] as TableCellProperties; Assert.IsNotNull(cellProperties); Assert.AreEqual(1, cellProperties.ChildElements.Count); VerticalMerge verticalMerge = cellProperties.ChildElements[0]as VerticalMerge; Assert.IsNotNull(verticalMerge); Assert.AreEqual(MergedCellValues.Restart, verticalMerge.Val.Value); Paragraph para = cell.ChildElements[1]as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(0, para.ChildElements.Count); cell = row.ChildElements[1] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(1, cell.ChildElements.Count); para = cell.ChildElements[0]as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(0, para.ChildElements.Count); row = table.ChildElements[3] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(2, row.ChildElements.Count); cell = row.ChildElements[0] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(2, cell.ChildElements.Count); cellProperties = cell.ChildElements[0] as TableCellProperties; Assert.IsNotNull(cellProperties); Assert.AreEqual(1, cellProperties.ChildElements.Count); verticalMerge = cellProperties.ChildElements[0]as VerticalMerge; Assert.IsNotNull(verticalMerge); Assert.AreEqual(false, verticalMerge.HasChildren); para = cell.ChildElements[1]as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(0, para.ChildElements.Count); cell = row.ChildElements[1] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(1, cell.ChildElements.Count); para = cell.ChildElements[0]as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(0, para.ChildElements.Count); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void TableCellWidth() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table style='width:500px'><tr><td style='width:250px'>1</td><td style='width:250px'>2</td></tr></table>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Word.Table table = doc.Document.Body.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Assert.AreEqual(3, table.ChildElements.Count); TableProperties tableProperties = table.ChildElements[0] as TableProperties; Assert.IsNotNull(tableProperties); Assert.AreEqual(2, tableProperties.ChildElements.Count); TableStyle tableStyle = tableProperties.ChildElements[0]as TableStyle; Assert.IsNotNull(tableStyle); Assert.AreEqual("TableGrid", tableStyle.Val.Value); TableWidth tableWidth = tableProperties.ChildElements[1]as TableWidth; Assert.IsNotNull(tableWidth); Assert.AreEqual("10000", tableWidth.Width.Value); Assert.AreEqual(TableWidthUnitValues.Dxa, tableWidth.Type.Value); TableRow row = table.ChildElements[2] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(2, row.ChildElements.Count); TableCell cell = row.ChildElements[0] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(2, cell.ChildElements.Count); TableCellProperties cellProperties = cell.ChildElements[0] as TableCellProperties; Assert.IsNotNull(cellProperties); TableCellWidth cellWidth = cellProperties.ChildElements[0] as TableCellWidth; Assert.IsNotNull(cellWidth); Assert.AreEqual("5000", cellWidth.Width.Value); Assert.AreEqual(TableWidthUnitValues.Dxa, cellWidth.Type.Value); Paragraph para = cell.ChildElements[1] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(1, run.ChildElements.Count); Word.Text text = run.ChildElements[0] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("1", text.InnerText); cell = row.ChildElements[1] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(2, cell.ChildElements.Count); cellProperties = cell.ChildElements[0] as TableCellProperties; Assert.IsNotNull(cellProperties); cellWidth = cellProperties.ChildElements[0] as TableCellWidth; Assert.IsNotNull(cellWidth); Assert.AreEqual("5000", cellWidth.Width.Value); Assert.AreEqual(TableWidthUnitValues.Dxa, cellWidth.Type.Value); para = cell.ChildElements[1] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(1, para.ChildElements.Count); run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(1, run.ChildElements.Count); text = run.ChildElements[0] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("2", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void TableAllProperties() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table border='1' style='width:500px' cellpadding='2'><tr><td>1</td><td>2</td></tr><tr><td colspan='2'>1</td></tr></table>")); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); errors.PrintValidationErrors(); Assert.AreEqual(0, errors.Count()); } }
public void TableThColSpan() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table><tr><td>Id</td><td>Name</td></tr><tr><td colspan='2'>1</td></tr></table>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Word.Table table = doc.Document.Body.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Assert.AreEqual(4, table.ChildElements.Count); TableRow row = table.ChildElements[2] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(2, row.ChildElements.Count); TableCell cell = row.ChildElements[0] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(1, cell.ChildElements.Count); cell.TestTableCell(1, "Id"); cell = row.ChildElements[1] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(1, cell.ChildElements.Count); cell.TestTableCell(1, "Name"); row = table.ChildElements[3] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(1, row.ChildElements.Count); cell = row.ChildElements[0] as TableCell; Assert.IsNotNull(cell); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void TableThColSpanAdv() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table border='1'><tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr><tr><td colspan='2'>one</td><td>three</td><td colspan='2'>five</td></tr></table>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Word.Table table = doc.Document.Body.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Assert.AreEqual(4, table.ChildElements.Count); TableRow row = table.ChildElements[2] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(5, row.ChildElements.Count); row = table.ChildElements[3] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(3, row.ChildElements.Count); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void TableThCellStyles() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table><tr><th>Id</th></tr><tr><td>1</td></tr></table>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Word.Table table = doc.Document.Body.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Assert.AreEqual(4, table.ChildElements.Count); TableProperties tableProperties = table.ChildElements[0] as TableProperties; Assert.IsNotNull(tableProperties); TableStyle tableStyle = tableProperties.ChildElements[0]as TableStyle; Assert.IsNotNull(tableStyle); Assert.AreEqual("TableGrid", tableStyle.Val.Value); TableGrid tableGrid = table.ChildElements[1] as TableGrid; Assert.IsNotNull(tableGrid); Assert.AreEqual(1, tableGrid.ChildElements.Count); TableRow row = table.ChildElements[2] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(1, row.ChildElements.Count); TableCell cell = row.ChildElements[0] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(1, cell.ChildElements.Count); Paragraph para = cell.ChildElements[0] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(2, run.ChildElements.Count); Assert.IsNotNull(run.RunProperties); Bold bold = run.RunProperties.ChildElements[0] as Bold; Assert.IsNotNull(bold); Word.Text text = run.ChildElements[1] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("Id", text.InnerText); row = table.ChildElements[3] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(1, row.ChildElements.Count); cell = row.ChildElements[0] as TableCell; cell.TestTableCell(1, "1"); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void TableCellPadding() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table cellpadding='5'><tr><td>test</td></tr></table>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Word.Table table = doc.Document.Body.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Assert.AreEqual(3, table.ChildElements.Count); TableProperties tableProperties = table.ChildElements[0] as TableProperties; Assert.IsNotNull(tableProperties); Assert.IsNotNull(tableProperties.TableCellMarginDefault); Assert.AreEqual(100, tableProperties.TableCellMarginDefault.TableCellLeftMargin.Width.Value); Assert.AreEqual(TableWidthValues.Dxa, tableProperties.TableCellMarginDefault.TableCellLeftMargin.Type.Value); Assert.AreEqual("100", tableProperties.TableCellMarginDefault.TopMargin.Width.Value); Assert.AreEqual(TableWidthUnitValues.Dxa, tableProperties.TableCellMarginDefault.TopMargin.Type.Value); Assert.AreEqual(100, tableProperties.TableCellMarginDefault.TableCellRightMargin.Width.Value); Assert.AreEqual(TableWidthValues.Dxa, tableProperties.TableCellMarginDefault.TableCellRightMargin.Type.Value); Assert.AreEqual("100", tableProperties.TableCellMarginDefault.BottomMargin.Width.Value); Assert.AreEqual(TableWidthUnitValues.Dxa, tableProperties.TableCellMarginDefault.BottomMargin.Type.Value); TableRow row = table.ChildElements[2] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(1, row.ChildElements.Count); TableCell cell = row.ChildElements[0] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(1, cell.ChildElements.Count); Paragraph para = cell.ChildElements[0] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(1, run.ChildElements.Count); Word.Text text = run.ChildElements[0] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void TableBorder() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<table border='1'><tr><td>test</td></tr></table>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Word.Table table = doc.Document.Body.ChildElements[0] as Word.Table; Assert.IsNotNull(table); Assert.AreEqual(3, table.ChildElements.Count); TableProperties tableProperties = table.ChildElements[0] as TableProperties; Assert.IsNotNull(tableProperties); TableStyle tableStyle = tableProperties.ChildElements[0]as TableStyle; Assert.IsNotNull(tableStyle); Assert.AreEqual("TableGrid", tableStyle.Val.Value); TableBorders tableBorders = tableProperties.ChildElements[1] as TableBorders; Assert.IsNotNull(tableBorders); Assert.AreEqual(4, tableBorders.ChildElements.Count); TopBorder topBorder = tableBorders.ChildElements[0] as TopBorder; Assert.IsNotNull(topBorder); TestUtility.TestBorder<TopBorder>(topBorder, BorderValues.Single, "auto", 4U); LeftBorder leftBorder = tableBorders.ChildElements[1] as LeftBorder; Assert.IsNotNull(leftBorder); TestUtility.TestBorder<LeftBorder>(leftBorder, BorderValues.Single, "auto", 4U); BottomBorder bottomBorder = tableBorders.ChildElements[2] as BottomBorder; Assert.IsNotNull(bottomBorder); TestUtility.TestBorder<BottomBorder>(bottomBorder, BorderValues.Single, "auto", 4U); RightBorder rightBorder = tableBorders.ChildElements[3] as RightBorder; Assert.IsNotNull(rightBorder); TestUtility.TestBorder<RightBorder>(rightBorder, BorderValues.Single, "auto", 4U); TableRow row = table.ChildElements[2] as TableRow; Assert.IsNotNull(row); Assert.AreEqual(1, row.ChildElements.Count); TableCell cell = row.ChildElements[0] as TableCell; Assert.IsNotNull(cell); Assert.AreEqual(2, cell.ChildElements.Count); TableCellProperties cellProperties = cell.ChildElements[0] as TableCellProperties; Assert.IsNotNull(cellProperties); Assert.AreEqual(1, cellProperties.ChildElements.Count); TableCellBorders cellBorders = cellProperties.ChildElements[0] as TableCellBorders; Assert.IsNotNull(cellBorders); Assert.AreEqual(4, cellBorders.ChildElements.Count); topBorder = cellBorders.ChildElements[0] as TopBorder; Assert.IsNotNull(topBorder); TestUtility.TestBorder<TopBorder>(topBorder, BorderValues.Single, "auto", 4U); leftBorder = cellBorders.ChildElements[1] as LeftBorder; Assert.IsNotNull(leftBorder); TestUtility.TestBorder<LeftBorder>(leftBorder, BorderValues.Single, "auto", 4U); bottomBorder = cellBorders.ChildElements[2] as BottomBorder; Assert.IsNotNull(bottomBorder); TestUtility.TestBorder<BottomBorder>(bottomBorder, BorderValues.Single, "auto", 4U); rightBorder = cellBorders.ChildElements[3] as RightBorder; Assert.IsNotNull(rightBorder); TestUtility.TestBorder<RightBorder>(rightBorder, BorderValues.Single, "auto", 4U); Paragraph para = cell.ChildElements[1] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(1, run.ChildElements.Count); Word.Text text = run.ChildElements[0] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void SinglePAllBorder() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<p style='border:1px solid #000'>test</p>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Paragraph paragraph = doc.Document.Body.ChildElements[0] as Paragraph; Assert.IsNotNull(paragraph); Assert.AreEqual(2, paragraph.ChildElements.Count); ParagraphProperties paragraphProperties = paragraph.ChildElements[0] as ParagraphProperties; ParagraphBorders paragraphBorders = paragraphProperties.ChildElements[0] as ParagraphBorders; Assert.IsNotNull(paragraphBorders); Assert.AreEqual(4, paragraphBorders.ChildElements.Count); TopBorder topBorder = paragraphBorders.ChildElements[0] as TopBorder; Assert.IsNotNull(topBorder); Assert.AreEqual(BorderValues.Single, topBorder.Val.Value); Assert.AreEqual("000000", topBorder.Color.Value); Assert.AreEqual(1, topBorder.Size.Value); LeftBorder leftBorder = paragraphBorders.ChildElements[1] as LeftBorder; Assert.IsNotNull(leftBorder); Assert.AreEqual(BorderValues.Single, leftBorder.Val.Value); Assert.AreEqual("000000", leftBorder.Color.Value); Assert.AreEqual(1, leftBorder.Size.Value); BottomBorder bottomBorder = paragraphBorders.ChildElements[2] as BottomBorder; Assert.IsNotNull(bottomBorder); Assert.AreEqual(BorderValues.Single, bottomBorder.Val.Value); Assert.AreEqual("000000", bottomBorder.Color.Value); Assert.AreEqual(1, bottomBorder.Size.Value); RightBorder rightBorder = paragraphBorders.ChildElements[3] as RightBorder; Assert.IsNotNull(rightBorder); Assert.AreEqual(BorderValues.Single, rightBorder.Val.Value); Assert.AreEqual("000000", rightBorder.Color.Value); Assert.AreEqual(1, rightBorder.Size.Value); Run run = paragraph.ChildElements[1] as Run; Assert.IsNotNull(run); Assert.AreEqual(1, run.ChildElements.Count); Word.Text text = run.ChildElements[0] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual(0, text.ChildElements.Count); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }
public void SpanDefault() { using (MemoryStream mem = new MemoryStream()) { WordDocument doc = new WordDocument(mem); doc.Process(new HtmlParser("<span>test</span>")); Assert.IsNotNull(doc.Document.Body); Assert.AreEqual(1, doc.Document.Body.ChildElements.Count); Paragraph para = doc.Document.Body.ChildElements[0] as Paragraph; Assert.IsNotNull(para); Assert.AreEqual(1, para.ChildElements.Count); Run run = para.ChildElements[0] as Run; Assert.IsNotNull(run); Assert.AreEqual(1, run.ChildElements.Count); var text = run.ChildElements[0] as Word.Text; Assert.IsNotNull(text); Assert.AreEqual("test", text.InnerText); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(doc.WordprocessingDocument); Assert.AreEqual(0, errors.Count()); } }