怎么用poi 在word表格指定位置中插入行

怎么用poi 在word表格指定位置中插入行,第1张

关键代码如下:
FileInputStream fileInputStream = new FileInputStream( soureFile);
POIFSFileSystem pfs = new POIFSFileSystem( fileInputStream );
HWPFDocument hwpf = new HWPFDocument(pfs);// make a HWPFDocument object
OutputStream output = new FileOutputStream( targetFile );
hwpfwrite(output);// write to the target file
outputclose();
(2)再word中插入表格。HWPF的情况:
Table tcDataTable = rangeinsertTableBefore( (short)column , row);//column and row列数和行数
tcDataTablegetRow(i)getCell(j)getParagraph(0)getCharacterRun(0)insertBefore("插入i行j列的内容" );
XWPF的情况:
String outputFile = "D:\\testdoc";
XWPFDocument document = new XWPFDocument();
XWPFTable tableOne = documentcreateTable();
XWPFTableRow tableOneRowOne = tableOnegetRow(0);
tableOneRowOnegetCell(0)setText("11");
XWPFTableCell cell12 = tableOneRowOnecreateCell();
cell12setText("12");
// tableOneRowOneaddNewTableCell()setText("第1行第2列");
// tableOneRowOneaddNewTableCell()setText("第1行第3列");
// tableOneRowOneaddNewTableCell()setText("第1行第4列");
XWPFTableRow tableOneRowTwo = tableOnecreateRow();
tableOneRowTwogetCell(0)setText("21");
tableOneRowTwogetCell(1)setText("22");
// tableOneRowTwogetCell(2)setText("第2行第3列");
XWPFTableRow tableOneRow3 = tableOnecreateRow();
tableOneRow3addNewTableCell()setText("31");
tableOneRow3addNewTableCell()setText("32");
FileOutputStream fOut;
try {
fOut = new FileOutputStream(outputFile);
documentwrite(fOut);
fOutflush();
// *** 作结束,关闭文件
fOutclose();
} catch (Exception e) {
eprintStackTrace();
}

以上就是关于怎么用poi 在word表格指定位置中插入行全部的内容,包括:怎么用poi 在word表格指定位置中插入行、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9561189.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存