String path=“文件路径”
String path1=“文件保存路径”
FileInputStream in = new FileInputStream(path);
FileOutputStream out = new FileOutputStream(path1);
XWPFDocument doc = new XWPFDocument(in); //文档中是一个1行n列的表格。
获取表格
XWPFTable xwpfTable = doc.getTables().get(0);
xwpfTable.createRow();//这是新增的一行
//原始表格里面只有一行,又重新添加了一行,再新加入行中添加内容,并设置格式
XWPFRun run = table.getRow(1).getCell(1).getParagraphs().get(0).createRun();
设置格式
run.setFontSize(20); //设置字体大小 14
run.setFontFamily(“宋体”); //设置字体为宋体
run.setBold(true); //设置加粗
run.setText(“你的内容”)
//保存内容
doc.write(out);
out.flush();
out.close();