Microsoft Word 2007 ドキュメントに取り組んでいます。
私の目的は満たすことです:
- 表のセル。
- 段落行。
したがって、私のコードはこの作業を行いますが、問題は FileOutputStream を使用してファイルを書き込むときに、目的の 1 つだけを書き込むことです (最後の変更のみ)。
ヘッダーの画像は次のとおりです。
ここに私が使用したコードがあります:
try{
InputStream input = new FileInputStream("c:\\doslot.docx");
XWPFDocument document=new XWPFDocument(input);
//*********************inserting the 2nd line**************************
XWPFHeader head = document.getHeaderList().get(0);
List<XWPFParagraph> para= head.getParagraphs();
XWPFRun pararun=para.get(0).createRun();
pararun.setText("DOSSIER DE LOT GLUSCAN® N°FG-4040400A");
//*********************inserting the header thrid table cell*************************
XWPFHeader headd = document.getHeaderList().get(1);
List<XWPFTable> tables = headd.getTables();
List<XWPFTableRow> rows = tables.get(0).getRows();
XWPFTableCell cell = rows.get(0).getTableCell(rows.get(0).getTableCells().get(3).getCTTc());
XWPFParagraph p =cell.addParagraph();
XWPFRun pararuno=p.createRun();
pararuno.setText("some text");
FileOutputStream out = new FileOutputStream("c:\\fin.docx");
document.write(out);
out.close();
}catch(Exception ex){
ex.printStackTrace();
}