В основном у меня все получилось. работает, но в выходном файле получаю странные результаты.
Мой текущий код:
Код: Выделить всё
String fileNameDocx = "/documentTemplates/template.docx";
FileOutputStream fos= new FileOutputStream("C:\\temp\\output.docx"); //this is just to test how it works
InputStream is = getClass().getClassLoader().getResourceAsStream(fileNameDocx);
XWPFDocument document = new XWPFDocument(is);
List paragraphs = document.getParagraphs();
for (XWPFParagraph para : paragraphs) {
System.out.println(para.getText()); //this works fine
}
for (XWPFTable table : document.getTables()) {
for (XWPFTableRow row : table.getRows()) {
for (XWPFTableCell cell : row.getTableCells()) {
System.out.println("cell text: " + cell.getText()); //this works fine as well
if (cell.getText().startsWith(someSymbol) && cell.getText().endsWith(anotherSymbol)) {
//this correctly finds the cell I want to replace
cell.setText("justTesting");
System.out.println("new cell text: " + cell.getText()); //for some reason, this outputs the old cell content
}
}
}
}
document.write(fos);
is.close();
fos.close();
Подробнее здесь: https://stackoverflow.com/questions/791 ... ed-results