我正在开发一个小项目,我正在通过 Java 创建 Word 文件,并在此 Word 文件中输入一些详细信息。我能够创建Word文件,也能够在其中输入数据。我还将一个表格写入Word文件并输入一些详细信息。
现在我想要的是,我想增加特定列的宽度。
有什么办法可以做到这一点吗?我正在使用 Apache POI 驱动程序来创建 Word 文件并向其中写入数据。
我正在使用下面的代码:
XWPFDocument document= new XWPFDocument();
try{
FileOutputStream out = new FileOutputStream(
new File("d:\\createparagraph.docx"));
XWPFParagraph paragraph = document.createParagraph();
XWPFTable table = document.createTable();
XWPFTableRow tableRowOne = table.getRow(0);
tableRowOne.getCell(0).setText("CLientID");
tableRowOne.addNewTableCell().setText(txtCID.getText());
//create second row
XWPFTableRow tableRow2 = table.createRow();
tableRow2.getCell(0).setText("AccountID");
tableRow2.getCell(1).setText(txtAID.getText());
document.write(out);
out.close();
}
Run Code Online (Sandbox Code Playgroud)
该代码工作正常并生成正常表格,但我想增加特定列(第 2 列)的宽度。
请帮忙。