HI dears,
kindly i need your help to know How to Write Table or Paragrph in Spcific page ? by (JAVA)Code
for example : i need to create Table in page 2 or Page 3 ,, not page 1 by (JAVA)Code
Document doc=new Document();
//Load the document
doc.loadFromFile("test.docx");
//Get the second section
Section section=doc.getSections().get(1);
//Add a paragraph
Paragraph paragraph=section.addParagraph();
paragraph.setText("Add a new paragraph");
String[] header = {"name", "sex"};
String[][] data =
{
new String[]{"Winny", "f"},
new String[]{"Lois", "f"},
new String[]{"Jois", "m"},
new String[]{"Moon", "f"},
new String[]{"Vinit", "f"},
};
//Add table
Table table = section.addTable(true);
table.resetCells(data.length + 1, header.length);
//Set the first row as the header
TableRow row = table.getRows().get(0);
row.isHeader(true);
for (int i = 0; i < header.length; i++) {
Paragraph p = row.getCells().get(i).addParagraph();
TextRange range1 = p.appendText(header[i]);
range1.getCharacterFormat().setFontName("Arial");
range1.getCharacterFormat().setFontSize(12f);
}
//Add data to other rows
for (int r = 0; r < data.length; r++) {
TableRow dataRow = table.getRows().get(r + 1);
for (int c = 0; c < data[r].length; c++) {
TextRange range2 = dataRow.getCells().get(c).addParagraph().appendText(data[r][c]);
range2.getCharacterFormat().setFontName("Arial");
range2.getCharacterFormat().setFontSize(10f);
}
}
//Save the document
doc.saveToFile("output.docx", FileFormat.Docx_2013);
Document doc=new Document();
//Load the document
doc.loadFromFile("Scope.docx");
//Get the second section
Section section=doc.getSections().get(1); ////// Error ,, will work only by " get(0) "
//Add a paragraph
Paragraph paragraph=section.addParagraph();
paragraph.setText("Add a new paragraph");