txt.append("<w:p><w:r></w:r></w:p>");//Empty Paragraph }else{ txt.append(Paragraph.with(cellValue).create().getContent());
txt.append("<w:p><w:r></w:r></w:p>");//Empty Paragraph }else{ txt.append(Paragraph.with(cellValue).create().getContent());
/*** * This is for situation where you pass the Paragraph so template can't have one * */ private void processMiddleForParagraph(StringBuilder th, ITableItemStrategy item, Paragraph... cols) { String templateWithoutParagraph = " <w:tc> " +"\n <w:tcPr> " +"\n <w:tcW w:w=\"4258\" w:type=\"dxa\"/> " +"\n </w:tcPr> " +"\n {value} " +"\n </w:tc> " ; for (int i = 0; i < cols.length; i++) { if(cols[i] != null && cols[i].getContent() != ""){ th.append("\n" + templateWithoutParagraph.replace("{value}", cols[i].getContent())); } else { //th.append("\n" + this.getMyMiddle().replace("{value}", "")); th.append("\n" + item.getMiddle().replace("{value}", Paragraph.with("").create().getContent() )); } } }
/*** * This is for situation where you pass the Paragraph so template can't have one * */ private void processMiddleForParagraph(StringBuilder th, ITableItemStrategy item, Paragraph... cols) { String templateWithoutParagraph = " <w:tc> " +"\n <w:tcPr> " +"\n <w:tcW w:w=\"4258\" w:type=\"dxa\"/> " +"\n </w:tcPr> " +"\n {value} " +"\n </w:tc> " ; for (int i = 0; i < cols.length; i++) { if(cols[i] != null && cols[i].getContent() != ""){ th.append("\n" + templateWithoutParagraph.replace("{value}", cols[i].getContent())); } else { //th.append("\n" + this.getMyMiddle().replace("{value}", "")); th.append("\n" + item.getMiddle().replace("{value}", Paragraph.with("").create().getContent() )); } } }
@Test public void sanityTest03() { IElement par = Paragraph.withPieces(ParagraphPiece.with(null)).create(); assertEquals(par.getContent(), ""); }
@Test public void testParagraphSanity() { Table tbl = new Table(); tbl.addTableEle(TableEle.TD, Paragraph.with("Flamengo").create()); tableBasicCheckings(tbl.getContent()); assertEquals(1, TestUtils.regexCount(tbl.getContent(), "<w:t>Flamengo</w:t>")); }
@Test public void testTab(){ Paragraph p01 = Paragraph.withPieces( ParagraphPiece.with("Bloc 1 Price :").withStyle().font(Font.CALIBRI).fontSize(Integer.toString(2*11)).create(), ParagraphPiece.with(" \t 3 200,00 $").withStyle().font(Font.CALIBRI).fontSize(Integer.toString(2*11)).create() ).addTab(TabAlign.RIGHT, 8931).create(); assertEquals(2, TestUtils.regexCount(p01.getContent(), "<w:pPr>")); assertEquals(1, TestUtils.regexCount(p01.getContent(), "<w:tabs>")); assertEquals(1, TestUtils.regexCount(p01.getContent(), "</w:tabs>")); assertEquals(2, TestUtils.regexCount(p01.getContent(), "</w:pPr>")); }
@Test public void testEmptyParagraph() { Table tbl = new Table(); tbl.addTableEle(TableEle.TD, Paragraph.with("").create()); tableBasicCheckings(tbl.getContent()); assertEquals(1, TestUtils.regexCount(tbl.getContent(), "<w:tr")); assertEquals(1, TestUtils.regexCount(tbl.getContent(), "</w:tr>")); assertEquals(1, TestUtils.regexCount(tbl.getContent(), "<w:t></w:t> ")); }
@Test public void testHeader() { IDocument myDoc = new Document2004(); assertEquals("", myDoc.getHeader().getContent()); myDoc.getHeader().addEle(Paragraph.with("paragraph01").create()); assertEquals(1, TestUtils.regexCount(myDoc.getHeader().getContent(), "<w:hdr w:type=\"odd\">")); assertEquals(1, TestUtils.regexCount(myDoc.getHeader().getContent(), "<w:p wsp:rsidR=\"008979E8\" wsp:rsidRDefault=\"00000000\">")); assertEquals(1, TestUtils.regexCount(myDoc.getHeader().getContent(), "<w:t>paragraph01</w:t>")); assertEquals(1, TestUtils.regexCount(myDoc.getHeader().getContent(), "</w:hdr>")); }
@Test public void testFooter() { IDocument myDoc = new Document2004(); assertEquals("", myDoc.getFooter().getContent()); myDoc.getFooter().addEle(Paragraph.with("paragraph01").create()); assertEquals(1, TestUtils.regexCount(myDoc.getFooter().getContent(), "<w:ftr w:type=\"odd\">")); assertEquals(1, TestUtils.regexCount(myDoc.getFooter().getContent(), "<w:p wsp:rsidR=\"008979E8\" wsp:rsidRDefault=\"00000000\">")); assertEquals(1, TestUtils.regexCount(myDoc.getFooter().getContent(), "<w:t>paragraph01</w:t>")); assertEquals(1, TestUtils.regexCount(myDoc.getFooter().getContent(), "</w:ftr>")); }
tbl.addRow( TableRow.with( TableCell.with(Paragraph.with("TableCell- Style to the whole cell, Par").create()), "Simple String" ).withStyle().bold().create() ); tbl.addRow( TableRow.with("Style to the whole cell, Str", "String").withStyle().bold().create() ); tbl.addRow( TableRow.with( TableCell.with(Paragraph.with("TableRowV2 with merge").create()).withStyle().gridSpan(2).create() ).withStyle().bold().create() ); tbl.addRow( TableRow.with( TableCell.with(Paragraph.withPieces( ParagraphPiece.with("Paragraph with Style inside TableCell").withStyle().bold().fontSize("20").create() ).create()).withStyle().bgColor("00FFFF").create(), "String" ));
myDoc.addEle(Paragraph .with("This doc has been generated by the unit test testJava2wordAllInOne() in the class DocumentTest2004Test.java.") .create()); myDoc.addEle(BreakLine.times(1).create()); + "I realised that is very dificult to keep the doucmentation updated " + "so this is where I will demostrate how to do some cool things with Java2word!") .create()); myDoc.addEle(Paragraph.with("I am a very simple paragraph.").create()); myParPiece03).create()); myParPieceAgile).create()); ParagraphPiece.with("This is a manual 'bold' and 'italic'") .withStyle().font(Font.COURIER).bold().italic() .create()).create()); myDoc.addEle(Paragraph .withPieces( .with("This is the SAME as the above line but with 'Smart' Bold/Italic ") .withStyle().font(Font.COURIER_BOLD_ITALIC) .create()).create()); myDoc.addEle(BreakLine.times(1).create()); myDoc.addEle(Paragraph.with("Remember to scape special characters like empsersand &").create()); .with("By default everything is added to the Body when you do 'myDoc.addEle(...)'."