+-

我尝试为此进行过多搜索,但未获得期望的结果.我正在使用Apache POI使用X WPF将特定的ata从Excel工作表复制到MS Word 2010文件中的表.我已经完成了.
我要做的最后一件事是为每个单元格添加一个小的左右边距,以使文本不会粘在单元格边框上.我在互联网上搜索了所有内容,但无法搜索.也许我缺少了一些东西.
最佳答案
您可以在表格级别设置单元格边距:
table.setCellMargins(0, 500, 0, 500);
完整的示例如下所示:
public static void main(String[] args) throws IOException {
XWPFDocument doc = new XWPFDocument();
FileOutputStream out = new FileOutputStream(new File(FILENAME));
XWPFParagraph para = doc.createParagraph();
XWPFRun run = para.createRun();
//table
XWPFTable table = doc.createTable();
table.setCellMargins(0, 500, 0, 500); //set margins here
//rows
XWPFTableRow row1 = table.getRow(0);
row1.getCell(0).setText("Hello1");
row1.addNewTableCell().setText("Hello2");
row1.addNewTableCell().setText("Hello3");
XWPFTableRow row2 = table.createRow();
row2.getCell(0).setText("Hello4");
row2.getCell(1).setText("Hello5");
row2.getCell(2).setText("Hello6");
doc.write(out);
out.close();
doc.close();
}
点击查看更多相关文章
转载注明原文:如何在Java中的Apache POI中更改XWPFTableCell边距? - 乐贴网