How to create new paragraph in determinate position with Apache poi? - java

I need to insert new paragraphs in diferents positiins in docx.
My code insert new paragraph but not in determinate position
XWFParagraph.
para=docx.createParagraph();
XWPFRun run =para.createRun();
run.setText("example
paragraph");

Related

Add toc on 3rd page using apache XWPF [duplicate]

This question already has answers here:
Creating a Table of Contents for a XWPFDocument with page numbers' indication
(5 answers)
Closed 5 years ago.
I want to add table of contents(toc) on 3rd page of Doc using apache XWPF.
Here is the code below :
XWPFDocument doc = new XWPFDocument();
CTSdtBlock block = doc.getDocument().getBody().addNewSdt();
TOC toc = new TOC(block);
toc.addRow(3, "toc", 3, "16283778");
doc.write(new FileOutputStream(new File("toc.docx")));
I think you should create a paragraph in your document with a run. That way you can add BreakType.PAGE to your paragraphs.
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.addBreak(BreakType.PAGE);
BreakType.PAGE skips a page

How to write html content in excel sheet cell using displaytag ExcelHssfView class

I want to write html content to a cell in excel using displaytag ExcelHssfView class. Following is my code snippet
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("NewSheet");
sheet.addMergedRegion(new CellRangeAddress(3,15,1,20));
HSSFRow xlsRow2 = sheet.createRow(sheet.getMergedRegion(1).getFirstRow());
HSSFCell cell = xlsRow2.createCell(1);
writeCell("Type:<ol><li>Sedan<ul style='list-style-type:disc'></ul></li><li>SUV<ul style='list-style-type:disc'></ul></li><li>Hatchback<ul style='list-style-type:disc'></ul></li></ol>", cell);
The problem is that the html content displays as such in the cell with the tags. Is it possible to write the html content properly in the cells?
Process the text in java before writing to cell. For example, replace ul tag with \t and unicode for bullet, ie \t\t\t\u2022 which excel recognizes and presents the text in the same way ul tag does in browser.

Paragraph leading inside table cell

I have a table with cells set up like this:
Paragraph p = new Paragraph(content,font);
p.setLeading(30);
PdfPCell c = new PdfPCell(p);
My problem is that the paragraph leading is ignored. Can someone please tell me how to set the paragraph leading when inside a table cell? It works perfectly when not inside a cell.
Thanks.
Google for the difference between "text mode" and "composite mode".
You are using "text mode": the leading of the cell is taken into
account; the leading of the paragraph is ignored.
If you use "composite mode", it's the other way round.
Try:
PdfPCell c = new PdfPCell();
c.addElement(p);

Content invisible using Itext in Java

I'm using the iText library with Java and I have an issue, let me explain:
I have a Word file converted into a PDF and i want to add a table at the end of the document, this works perfectly except when the Word file hasn’t active the feature "No Color" at the tab "Page Layout", the table adds it as "invisible".
I've already tried to change the property Font from the Chunk object that created the content, but it does not work, the table continues showing as "invisible".
How I can solve this
The following code is the one that I use to create the table:
Font font = new Font(1,fontSize, Font.BOLD);
font.setColor(0,0,0);
Chunk name = new Chunk(v_emp.getNombre(),font);
Chunk tipo = new Chunk(v_emp.getDireccion(),font);
Paragraph paragraph = new Paragraph();
paragraph.add(tipo);
paragraph.add(new Chunk("\n"));
paragraph.add(name);
PdfPCell cell1 = new PdfPCell(paragraph);
cell1.setPadding(2);
table.addCell(cell1);
Try selecting the table in PDF with your mouse and see if the table is there and still it is invisible.
If it is there, go to the file menu and do print as pdf.

JasperReports, export to docx - footer formatting

I am new to JasperReports.
How can I make word document more user friendly with JasperReports?
I create simple document, and convert in docx.
Footer still not have absolute position. If you focus in content and insert new column above/below,
the footer will move to the next page.
How to create static/absolute footer in JR report? (.docx extension report)
Jasper Reports uses tables to render docx format, if you select all your document and enable all cells boundaries you'll note each page is a table.
http://www.smartjava.org/content/create-complex-word-docx-documents-programatically-docx4j
Probably you'll need to read an excel file and fill into a docx with programatically with docx4j library in order to mantain header and footer in a word template.

Categories