public void TestParagraphPAPXNoParent45877() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Bug45877.doc"); Assert.AreEqual(17, doc.GetRange().NumParagraphs); Assert.AreEqual("First paragraph\r", doc.GetRange().GetParagraph(0).Text); Assert.AreEqual("After Crashing Part\r", doc.GetRange().GetParagraph(13).Text); }
public ToxyDocument Parse() { if (!File.Exists(Context.Path)) { throw new FileNotFoundException("File " + Context.Path + " is not found"); } bool extractHeader = false; if (Context.Properties.ContainsKey("ExtractHeader")) { extractHeader = Utility.IsTrue(Context.Properties["ExtractHeader"]); } bool extractFooter = false; if (Context.Properties.ContainsKey("ExtractFooter")) { extractFooter = Utility.IsTrue(Context.Properties["ExtractFooter"]); } ToxyDocument rdoc = new ToxyDocument(); using (FileStream stream = File.OpenRead(Context.Path)) { HWPFDocument worddoc = new HWPFDocument(stream); if (extractHeader && worddoc.GetHeaderStoryRange() != null) { StringBuilder sb = new StringBuilder(); rdoc.Header = worddoc.GetHeaderStoryRange().Text; } if (extractFooter && worddoc.GetFootnoteRange() != null) { StringBuilder sb = new StringBuilder(); rdoc.Footer = worddoc.GetFootnoteRange().Text; } for (int i = 0; i < worddoc.GetRange().NumParagraphs; i++) { Paragraph para = worddoc.GetRange().GetParagraph(i); string text = para.Text; ToxyParagraph p = new ToxyParagraph(); p.Text = text; //var runs = para.Runs; p.StyleID = para.GetStyleIndex().ToString(); //for (int i = 0; i < runs.Count; i++) //{ // var run = runs[i]; //} rdoc.Paragraphs.Add(p); } } return(rdoc); }
/// <summary> /// 搜索doc文档 /// </summary> /// <param name="targetStr"></param> /// <param name="fileFullPath"></param> /// <returns></returns> private bool SearchDoc(string targetStr, FileStream fs) { POIFSFileSystem pOIFS = new POIFSFileSystem(fs); HWPFDocument document = new HWPFDocument(pOIFS); for (int i = 0; i < document.GetRange().NumParagraphs; i++) { if (document.GetRange().GetParagraph(i).Text.Contains(targetStr)) { return(true); } } return(false); }
/** * Test that we can replace text in our Range with Unicode text. */ public void TestRangeReplacementAll() { HWPFDocument daDoc = HWPFTestDataSamples.OpenSampleFile(illustrativeDocFile); Range range = daDoc.GetRange(); Assert.AreEqual(1, range.NumSections); Section section = range.GetSection(0); Assert.AreEqual(5, section.NumParagraphs); Paragraph para = section.GetParagraph(2); String text = para.Text; Assert.AreEqual(originalText, text); range.ReplaceText(searchText, ReplacementText); Assert.AreEqual(1, range.NumSections); section = range.GetSection(0); Assert.AreEqual(5, section.NumParagraphs); para = section.GetParagraph(2); text = para.Text; Assert.AreEqual(expectedText2, text); para = section.GetParagraph(3); text = para.Text; Assert.AreEqual(expectedText3, text); }
public void Test49820() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Bug49820.doc"); Range documentRange = doc.GetRange(); StyleSheet styleSheet = doc.GetStyleSheet(); // JUnit asserts assertLevels(documentRange, styleSheet, 0, 0, 0); assertLevels(documentRange, styleSheet, 1, 1, 1); assertLevels(documentRange, styleSheet, 2, 2, 2); assertLevels(documentRange, styleSheet, 3, 3, 3); assertLevels(documentRange, styleSheet, 4, 4, 4); assertLevels(documentRange, styleSheet, 5, 5, 5); assertLevels(documentRange, styleSheet, 6, 6, 6); assertLevels(documentRange, styleSheet, 7, 7, 7); assertLevels(documentRange, styleSheet, 8, 8, 8); assertLevels(documentRange, styleSheet, 9, 9, 9); assertLevels(documentRange, styleSheet, 10, 9, 0); assertLevels(documentRange, styleSheet, 11, 9, 4); // output to console for (int i = 0; i < documentRange.NumParagraphs; i++) { Paragraph par = documentRange.GetParagraph(i); int styleLvl = styleSheet.GetParagraphStyle(par.GetStyleIndex()).GetLvl(); int parLvl = par.GetLvl(); Console.WriteLine("Style level: " + styleLvl + ", paragraph level: " + parLvl + ", text: " + par.Text); } }
public void TestDocStructure() { HWPFDocument daDoc = HWPFTestDataSamples.OpenSampleFile(illustrativeDocFile); Range range = daDoc.GetRange(); Assert.AreEqual(1, range.NumSections); Section section = range.GetSection(0); Assert.AreEqual(3, section.NumParagraphs); Paragraph para = section.GetParagraph(2); Assert.AreEqual(originalText, para.Text); Assert.AreEqual(3, para.NumCharacterRuns); String text = para.GetCharacterRun(0).Text + para.GetCharacterRun(1).Text + para.GetCharacterRun(2).Text ; Assert.AreEqual(originalText, text); Assert.AreEqual(insertionPoint, para.StartOffset); }
public void TestIndentedText() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Lists.doc"); Range r = doc.GetRange(); Assert.AreEqual(40, r.NumParagraphs); Assert.AreEqual("Finally we want some indents, to tell the difference\r", r.GetParagraph(34).Text); Assert.AreEqual("Indented once\r", r.GetParagraph(35).Text); Assert.AreEqual("Indented twice\r", r.GetParagraph(36).Text); Assert.AreEqual("Indented three times\r", r.GetParagraph(37).Text); Assert.AreEqual("The end!\r", r.GetParagraph(38).Text); Assert.AreEqual(9, r.GetParagraph(34).GetLvl()); Assert.AreEqual(9, r.GetParagraph(35).GetLvl()); Assert.AreEqual(9, r.GetParagraph(36).GetLvl()); Assert.AreEqual(9, r.GetParagraph(37).GetLvl()); Assert.AreEqual(9, r.GetParagraph(38).GetLvl()); Assert.AreEqual(9, r.GetParagraph(39).GetLvl()); Assert.AreEqual(0, r.GetParagraph(34).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(35).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(36).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(37).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(38).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(39).GetIlvl()); // TODO Test the indent }
public void TestOrderedLists() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Lists.doc"); Range r = doc.GetRange(); Assert.AreEqual(40, r.NumParagraphs); Assert.AreEqual("Next up is an ordered list:\r", r.GetParagraph(5).Text); Assert.AreEqual("Ordered list 1\r", r.GetParagraph(6).Text); Assert.AreEqual("OL 2\r", r.GetParagraph(7).Text); Assert.AreEqual("OL 3\r", r.GetParagraph(8).Text); Assert.AreEqual("Now for an un-ordered list with a different bullet style:\r", r.GetParagraph(9).Text); Assert.AreEqual(9, r.GetParagraph(5).GetLvl()); Assert.AreEqual(9, r.GetParagraph(6).GetLvl()); Assert.AreEqual(9, r.GetParagraph(7).GetLvl()); Assert.AreEqual(9, r.GetParagraph(8).GetLvl()); Assert.AreEqual(9, r.GetParagraph(9).GetLvl()); Assert.AreEqual(0, r.GetParagraph(5).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(6).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(7).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(8).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(9).GetIlvl()); }
private Dictionary <string, string> getFileDict(string docFileName, out string dh) { dh = ""; var dict = new Dictionary <string, string>(); if (File.Exists(docFileName)) { using (Stream stream = new FileStream(docFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { HWPFDocument hd = new HWPFDocument(stream); var paraTable = hd.ParagraphTable; Range rang = hd.GetRange(); int paragraphCount = rang.NumParagraphs; for (int i = 0; i < paragraphCount; i++) { var pph = rang.GetParagraph(i); var text = pph.Text.Replace(":", ":").Replace(" ", "").Trim(); if (text.StartsWith("档号:")) { dh = text.Replace("档号:", "").Trim(); break; } } rang = hd.GetRange(); TableIterator it = new TableIterator(rang); while (it.HasNext()) { NPOI.HWPF.UserModel.Table tb = (NPOI.HWPF.UserModel.Table)it.Next(); for (int i = 0; i < tb.NumRows; i++) { var row = tb.GetRow(i); var cellCount = row.numCells(); if (cellCount > 1) { var key = row.GetCell(0).Text.Trim().Replace("\a", ""); var value = row.GetCell(1).Text.Trim().Replace("\a", ""); if (!dict.ContainsKey(key)) { dict.Add(key, value); } } } } } } return(dict); }
public void TestRangeDeleteOne() { HWPFDocument daDoc = HWPFTestDataSamples.OpenSampleFile(illustrativeDocFile); Range range = daDoc.GetOverallRange(); Assert.AreEqual(1, range.NumSections); Section section = range.GetSection(0); Assert.AreEqual(5, section.NumParagraphs); Paragraph para = section.GetParagraph(2); String text = para.Text; Assert.AreEqual(originalText, text); int offset = text.IndexOf(searchText); Assert.AreEqual(192, offset); int absOffset = para.StartOffset + offset; Range subRange = new Range(absOffset, (absOffset + searchText.Length), para.GetDocument()); Assert.AreEqual(searchText, subRange.Text); subRange.Delete(); // we need to let the model re-calculate the Range before we Evaluate it range = daDoc.GetRange(); Assert.AreEqual(1, range.NumSections); section = range.GetSection(0); Assert.AreEqual(5, section.NumParagraphs); para = section.GetParagraph(2); text = para.Text; Assert.AreEqual(expectedText2, text); // this can lead to a StringBuilderOutOfBoundsException, so we will add it // even though we don't have an assertion for it Range daRange = daDoc.GetRange(); text = daRange.Text; }
public void TestMultiLevelLists() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Lists.doc"); Range r = doc.GetRange(); Assert.AreEqual(40, r.NumParagraphs); Assert.AreEqual("Multi-level un-ordered list:\r", r.GetParagraph(12).Text); Assert.AreEqual("ML 1:1\r", r.GetParagraph(13).Text); Assert.AreEqual("ML 1:2\r", r.GetParagraph(14).Text); Assert.AreEqual("ML 2:1\r", r.GetParagraph(15).Text); Assert.AreEqual("ML 2:2\r", r.GetParagraph(16).Text); Assert.AreEqual("ML 2:3\r", r.GetParagraph(17).Text); Assert.AreEqual("ML 3:1\r", r.GetParagraph(18).Text); Assert.AreEqual("ML 4:1\r", r.GetParagraph(19).Text); Assert.AreEqual("ML 5:1\r", r.GetParagraph(20).Text); Assert.AreEqual("ML 5:2\r", r.GetParagraph(21).Text); Assert.AreEqual("ML 2:4\r", r.GetParagraph(22).Text); Assert.AreEqual("ML 1:3\r", r.GetParagraph(23).Text); Assert.AreEqual("Multi-level ordered list:\r", r.GetParagraph(24).Text); Assert.AreEqual("OL 1\r", r.GetParagraph(25).Text); Assert.AreEqual("OL 2\r", r.GetParagraph(26).Text); Assert.AreEqual("OL 2.1\r", r.GetParagraph(27).Text); Assert.AreEqual("OL 2.2\r", r.GetParagraph(28).Text); Assert.AreEqual("OL 2.2.1\r", r.GetParagraph(29).Text); Assert.AreEqual("OL 2.2.2\r", r.GetParagraph(30).Text); Assert.AreEqual("OL 2.2.2.1\r", r.GetParagraph(31).Text); Assert.AreEqual("OL 2.2.3\r", r.GetParagraph(32).Text); Assert.AreEqual("OL 3\r", r.GetParagraph(33).Text); Assert.AreEqual("Finally we want some indents, to tell the difference\r", r.GetParagraph(34).Text); for (int i = 12; i <= 34; i++) { Assert.AreEqual(9, r.GetParagraph(12).GetLvl()); } Assert.AreEqual(0, r.GetParagraph(12).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(13).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(14).GetIlvl()); Assert.AreEqual(1, r.GetParagraph(15).GetIlvl()); Assert.AreEqual(1, r.GetParagraph(16).GetIlvl()); Assert.AreEqual(1, r.GetParagraph(17).GetIlvl()); Assert.AreEqual(2, r.GetParagraph(18).GetIlvl()); Assert.AreEqual(3, r.GetParagraph(19).GetIlvl()); Assert.AreEqual(4, r.GetParagraph(20).GetIlvl()); Assert.AreEqual(4, r.GetParagraph(21).GetIlvl()); Assert.AreEqual(1, r.GetParagraph(22).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(23).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(24).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(25).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(26).GetIlvl()); Assert.AreEqual(1, r.GetParagraph(27).GetIlvl()); Assert.AreEqual(1, r.GetParagraph(28).GetIlvl()); Assert.AreEqual(2, r.GetParagraph(29).GetIlvl()); Assert.AreEqual(2, r.GetParagraph(30).GetIlvl()); Assert.AreEqual(3, r.GetParagraph(31).GetIlvl()); Assert.AreEqual(2, r.GetParagraph(32).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(33).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(34).GetIlvl()); }
public void TestOuterTableCellsDetection() { HWPFDocument hwpfDocument = new HWPFDocument(POIDataSamples .GetDocumentInstance().OpenResourceAsStream("innertable.doc")); hwpfDocument.GetRange(); Range documentRange = hwpfDocument.GetRange(); Paragraph startOfOuterTable = documentRange.GetParagraph(0); Table outerTable = documentRange.GetTable(startOfOuterTable); Assert.AreEqual(3, outerTable.NumRows); Assert.AreEqual(3, outerTable.GetRow(0).NumCells()); Assert.AreEqual(3, outerTable.GetRow(1).NumCells()); Assert.AreEqual(3, outerTable.GetRow(2).NumCells()); }
public void TestWriteRead() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Lists.doc"); doc = HWPFTestDataSamples.WriteOutAndReadBack(doc); Range r = doc.GetRange(); // Check a couple at random Assert.AreEqual(4, r.GetParagraph(21).GetIlvl()); Assert.AreEqual(1, r.GetParagraph(22).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(23).GetIlvl()); }
public void TestRangeDelete() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Bug28627.doc"); Range range = doc.GetRange(); int numParagraphs = range.NumParagraphs; int totalLength = 0, deletedLength = 0; for (int i = 0; i < numParagraphs; i++) { Paragraph para = range.GetParagraph(i); String text = para.Text; totalLength += text.Length; if (text.IndexOf("{delete me}") > -1) { para.Delete(); deletedLength += text.Length; } } // check the text length after deletion int newLength = 0; range = doc.GetRange(); numParagraphs = range.NumParagraphs; for (int i = 0; i < numParagraphs; i++) { Paragraph para = range.GetParagraph(i); String text = para.Text; newLength += text.Length; } Assert.AreEqual(newLength, totalLength - deletedLength); }
static void Main(string[] args) { // POI apparently can't create a document from scratch, // so we need an existing empty dummy document POIFSFileSystem fs = new POIFSFileSystem(File.OpenRead("empty.doc")); HWPFDocument doc = new HWPFDocument(fs); // centered paragraph with large font size Range range = doc.GetRange(); CharacterRun run1 = range.InsertAfter("one"); //par1.SetSpacingAfter(200); //par1.SetJustification((byte)1); // justification: 0=left, 1=center, 2=right, 3=left and right //CharacterRun run1 = par1.InsertAfter("one"); run1.SetFontSize(2 * 18); // font size: twice the point size // paragraph with bold typeface Paragraph par2 = run1.InsertAfter(new ParagraphProperties(), 0); par2.SetSpacingAfter(200); CharacterRun run2 = par2.InsertAfter("two two two two two two two two two two two two two"); run2.SetBold(true); // paragraph with italic typeface and a line indent in the first line Paragraph par3 = run2.InsertAfter(new ParagraphProperties(), 0); par3.SetFirstLineIndent(200); par3.SetSpacingAfter(200); CharacterRun run3 = par3.InsertAfter("three three three three three three three three three " + "three three three three three three three three three three three three three three " + "three three three three three three three three three three three three three three"); run3.SetItalic(true); // add a custom document property (needs POI 3.5; POI 3.2 doesn't save custom properties) DocumentSummaryInformation dsi = doc.DocumentSummaryInformation; CustomProperties cp = dsi.CustomProperties; if (cp == null) { cp = new CustomProperties(); } cp.Put("myProperty", "foo bar baz"); doc.Write(File.OpenWrite("new-hwpf-file.doc")); }
public void TestContents() { HWPFDocument doc = docAscii; for (int run = 0; run < 3; run++) { Range r; // Now check the real ranges r = doc.GetRange(); Assert.AreEqual( a_page_1 + page_break + "\r" + a_page_2, r.Text ); r = doc.GetHeaderStoryRange(); Assert.AreEqual( headerDef + a_header + footerDef + a_footer + endHeaderFooter, r.Text ); r = doc.GetOverallRange(); Assert.AreEqual( a_page_1 + page_break + "\r" + a_page_2 + headerDef + a_header + footerDef + a_footer + endHeaderFooter + "\r", r.Text ); // Write out and read back in again, Ready for // the next run of the Test // TODO run more than once if (run < 1) { doc = HWPFTestDataSamples.WriteOutAndReadBack(doc); } } }
public void Test50075() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Bug50075.doc"); Range range = doc.GetRange(); Assert.AreEqual(1, range.NumParagraphs); Paragraph para1 = (Paragraph)range.GetParagraph(0); ListEntry entry = new ListEntry(para1._paragraphs[0], (Range)para1._parent, doc.GetListTables()); ListFormatOverride override1 = doc.GetListTables().GetOverride(entry.GetIlfo()); ListLevel level = doc.GetListTables().GetLevel(override1.GetLsid(), entry.GetIlvl()); // the bug reproduces, if this call fails with NullPointerException level.GetNumberText(); }
public string Parse() { if (!File.Exists(Context.Path)) { throw new FileNotFoundException("File " + Context.Path + " is not found"); } StringBuilder sb = new StringBuilder(); using (FileStream stream = File.OpenRead(Context.Path)) { HWPFDocument worddoc = new HWPFDocument(stream); return(worddoc.GetRange().Text); } }
public void TestReadParagraphsAfterReplaceText() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Bug45269.doc"); Range range = doc.GetRange(); String toFind = "campo1"; String longer = " foi porraaaaa "; String shorter = " foi "; //check replace with longer text for (int x = 0; x < range.NumParagraphs; x++) { Paragraph para = range.GetParagraph(x); int offset = para.Text.IndexOf(toFind); if (offset >= 0) { para.ReplaceText(toFind, longer, offset); Assert.AreEqual(offset, para.Text.IndexOf(longer)); } } doc = HWPFTestDataSamples.OpenSampleFile("Bug45269.doc"); range = doc.GetRange(); //check replace with shorter text for (int x = 0; x < range.NumParagraphs; x++) { Paragraph para = range.GetParagraph(x); int offset = para.Text.IndexOf(toFind); if (offset >= 0) { para.ReplaceText(toFind, shorter, offset); Assert.AreEqual(offset, para.Text.IndexOf(shorter)); } } }
public void TestBasics() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Lists.doc"); Range r = doc.GetRange(); Assert.AreEqual(40, r.NumParagraphs); Assert.AreEqual("Heading Level 1\r", r.GetParagraph(0).Text); Assert.AreEqual("This document has different lists in it for testing\r", r.GetParagraph(1).Text); Assert.AreEqual("The end!\r", r.GetParagraph(38).Text); Assert.AreEqual("\r", r.GetParagraph(39).Text); Assert.AreEqual(9, r.GetParagraph(0).GetLvl()); Assert.AreEqual(9, r.GetParagraph(1).GetLvl()); Assert.AreEqual(9, r.GetParagraph(38).GetLvl()); Assert.AreEqual(9, r.GetParagraph(39).GetLvl()); }
public void Test() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Bug49908.doc"); Range range = doc.GetRange(); Assert.IsTrue(range.NumCharacterRuns >= 2); CharacterRun chr = range.GetCharacterRun(0); Assert.AreEqual(false, chr.IsSymbol()); chr = range.GetCharacterRun(1); Assert.AreEqual(true, chr.IsSymbol()); Assert.AreEqual("\u0028", chr.Text); Assert.AreEqual("Wingdings", chr.GetSymbolFont().GetMainFontName()); Assert.AreEqual(0xf028, chr.GetSymbolCharacter()); }
public void TestBuildTableCellEdgesArray() { HWPFDocument document = HWPFTestDataSamples .OpenSampleFile("table-merges.doc"); Range range = document.GetRange(); Table table = range.GetTable(range.GetParagraph(0)); int[] result = AbstractWordUtils.BuildTableCellEdgesArray(table); Assert.AreEqual(6, result.Length); Assert.AreEqual(0000, result[0]); Assert.AreEqual(1062, result[1]); Assert.AreEqual(5738, result[2]); Assert.AreEqual(6872, result[3]); Assert.AreEqual(8148, result[4]); Assert.AreEqual(9302, result[5]); }
public void TestExtractFromModel() { Range r = doc.GetRange(); String[] text = new String[r.NumParagraphs]; for (int i = 0; i < r.NumParagraphs; i++) { Paragraph p = r.GetParagraph(i); text[i] = p.Text; } Assert.AreEqual(p_text.Length, text.Length); for (int i = 0; i < p_text.Length; i++) { Assert.AreEqual(p_text[i], text[i]); } }
public void TestSprmAIOOB() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("AIOOB-Tap.doc"); Range r = doc.GetRange(); StyleSheet styleSheet = doc.GetStyleSheet(); for (int x = 0; x < r.NumSections; x++) { Section s = r.GetSection(x); for (int y = 0; y < s.NumParagraphs; y++) { Paragraph paragraph = s.GetParagraph(y); // Console.WriteLine(paragraph.GetCharacterRun(0).Text); } } }
public void TestUnorderedLists() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Lists.doc"); Range r = doc.GetRange(); Assert.AreEqual(40, r.NumParagraphs); // Normal bullet points Assert.AreEqual("This document has different lists in it for testing\r", r.GetParagraph(1).Text); Assert.AreEqual("Unordered list 1\r", r.GetParagraph(2).Text); Assert.AreEqual("UL 2\r", r.GetParagraph(3).Text); Assert.AreEqual("UL 3\r", r.GetParagraph(4).Text); Assert.AreEqual("Next up is an ordered list:\r", r.GetParagraph(5).Text); Assert.AreEqual(9, r.GetParagraph(1).GetLvl()); Assert.AreEqual(9, r.GetParagraph(2).GetLvl()); Assert.AreEqual(9, r.GetParagraph(3).GetLvl()); Assert.AreEqual(9, r.GetParagraph(4).GetLvl()); Assert.AreEqual(9, r.GetParagraph(5).GetLvl()); Assert.AreEqual(0, r.GetParagraph(1).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(2).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(3).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(4).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(5).GetIlvl()); // Tick bullets Assert.AreEqual("Now for an un-ordered list with a different bullet style:\r", r.GetParagraph(9).Text); Assert.AreEqual("Tick 1\r", r.GetParagraph(10).Text); Assert.AreEqual("Tick 2\r", r.GetParagraph(11).Text); Assert.AreEqual("Multi-level un-ordered list:\r", r.GetParagraph(12).Text); Assert.AreEqual(9, r.GetParagraph(9).GetLvl()); Assert.AreEqual(9, r.GetParagraph(10).GetLvl()); Assert.AreEqual(9, r.GetParagraph(11).GetLvl()); Assert.AreEqual(9, r.GetParagraph(12).GetLvl()); Assert.AreEqual(0, r.GetParagraph(9).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(10).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(11).GetIlvl()); Assert.AreEqual(0, r.GetParagraph(12).GetIlvl()); // TODO Test for tick not bullet }
private static String RunExtract(String sampleName) { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile(sampleName); StringBuilder out1 = new StringBuilder(); Range globalRange = doc.GetRange(); for (int i = 0; i < globalRange.NumParagraphs; i++) { Paragraph p = globalRange.GetParagraph(i); out1.Append(p.Text); out1.Append("\n"); for (int j = 0; j < p.NumCharacterRuns; j++) { CharacterRun characterRun = p.GetCharacterRun(j); string a = characterRun.Text; } } return(out1.ToString()); }
private void TestInnerTable(HWPFDocument hwpfDocument) { Range range = hwpfDocument.GetRange(); for (int p = 0; p < range.NumParagraphs; p++) { Paragraph paragraph = range.GetParagraph(p); char first = paragraph.Text.ToLower()[0]; if ('1' <= first && first < '4') { Assert.IsTrue(paragraph.IsInTable()); Assert.AreEqual(2, paragraph.GetTableLevel()); } if ('a' <= first && first < 'z') { Assert.IsTrue(paragraph.IsInTable()); Assert.AreEqual(1, paragraph.GetTableLevel()); } } }
public void TestRangeInsert() { HWPFDocument daDoc = HWPFTestDataSamples.OpenSampleFile(illustrativeDocFile); //if (false) //{ // TODO - delete or resurrect this code // Range range1 = daDoc.GetRange(); // Section section1 = range1.GetSection(0); // Paragraph para1 = section1.GetParagraph(2); // String text1 = para1.GetCharacterRun(0).Text + para1.GetCharacterRun(1).Text + // para1.GetCharacterRun(2).Text; // Console.WriteLine(text1); //} Range range = new Range(insertionPoint, (insertionPoint + 2), daDoc); range.InsertBefore(textToInsert); // we need to let the model re-calculate the Range before we Evaluate it range = daDoc.GetRange(); Assert.AreEqual(1, range.NumSections); Section section = range.GetSection(0); Assert.AreEqual(3, section.NumParagraphs); Paragraph para = section.GetParagraph(2); Assert.AreEqual((textToInsert + originalText), para.Text); Assert.AreEqual(3, para.NumCharacterRuns); String text = para.GetCharacterRun(0).Text + para.GetCharacterRun(1).Text + para.GetCharacterRun(2).Text ; // Console.WriteLine(text); Assert.AreEqual((textToInsert + originalText), text); }
public void TestFloatingPictures() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("FloatingPictures.doc"); PicturesTable pictures = doc.GetPicturesTable(); // There are 19 images in the picture, but some are // duplicate floating ones Assert.AreEqual(17, pictures.GetAllPictures().Count); int plain8s = 0; int escher8s = 0; int image1s = 0; Range r = doc.GetRange(); for (int np = 0; np < r.NumParagraphs; np++) { Paragraph p = r.GetParagraph(np); for (int nc = 0; nc < p.NumCharacterRuns; nc++) { CharacterRun cr = p.GetCharacterRun(nc); if (pictures.HasPicture(cr)) { image1s++; } else if (pictures.HasEscherPicture(cr)) { escher8s++; } else if (cr.Text.StartsWith("\u0008")) { plain8s++; } } } // Total is 20, as the 4 escher 8s all reference // the same regular image Assert.AreEqual(16, image1s); Assert.AreEqual(4, escher8s); Assert.AreEqual(0, plain8s); }
public void TestRangeReplacementOne() { HWPFDocument daDoc = HWPFTestDataSamples.OpenSampleFile(illustrativeDocFile); // Has one section Range range = daDoc.GetRange(); Assert.AreEqual(1, range.NumSections); // The first section has 5 paragraphs Section section = range.GetSection(0); Assert.AreEqual(5, section.NumParagraphs); // Change some text Paragraph para = section.GetParagraph(2); String text = para.Text; Assert.AreEqual(originalText, text); int offset = text.IndexOf(searchText); Assert.AreEqual(181, offset); para.ReplaceText(searchText, ReplacementText, offset); // Ensure we still have one section, 5 paragraphs Assert.AreEqual(1, range.NumSections); section = range.GetSection(0); Assert.AreEqual(5, section.NumParagraphs); para = section.GetParagraph(2); // Ensure the text is what we should now have text = para.Text; Assert.AreEqual(expectedText2, text); }