中易网

poi 操作word 2007 (如何删除word中的某一个表格)

答案:1  悬赏:10  
解决时间 2021-01-10 18:37
poi 操作word 2007 (如何删除word中的某一个表格)
最佳答案
关键代码如下:
FileInputStream fileInputStream = new FileInputStream( soureFile);
POIFSFileSystem pfs = new POIFSFileSystem( fileInputStream );
HWPFDocument hwpf = new HWPFDocument(pfs);// make a HWPFDocument object

OutputStream output = new FileOutputStream( targetFile );
hwpf.write(output);// write to the target file
output.close();

(2)再word中插入表格。HWPF的情况:
Table tcDataTable = range.insertTableBefore( (short)column , row);//column and row列数和行数
tcDataTable.getRow(i).getCell(j).getParagraph(0).getCharacterRun(0).insertBefore("插入i行j列的内容" );

XWPF的情况:
String outputFile = "D:\\test.doc";

XWPFDocument document = new XWPFDocument();

XWPFTable tableOne = document.createTable();

XWPFTableRow tableOneRowOne = tableOne.getRow(0);
tableOneRowOne.getCell(0).setText("11");
XWPFTableCell cell12 = tableOneRowOne.createCell();
cell12.setText("12");
// tableOneRowOne.addNewTableCell().setText("第1行第2列");
// tableOneRowOne.addNewTableCell().setText("第1行第3列");
// tableOneRowOne.addNewTableCell().setText("第1行第4列");

XWPFTableRow tableOneRowTwo = tableOne.createRow();
tableOneRowTwo.getCell(0).setText("21");
tableOneRowTwo.getCell(1).setText("22");
// tableOneRowTwo.getCell(2).setText("第2行第3列");

XWPFTableRow tableOneRow3 = tableOne.createRow();
tableOneRow3.addNewTableCell().setText("31");
tableOneRow3.addNewTableCell().setText("32");

FileOutputStream fOut;

try {
fOut = new FileOutputStream(outputFile);

document.write(fOut);
fOut.flush();
// 操作结束,关闭文件
fOut.close();
} catch (Exception e) {
e.printStackTrace();
}
追问:我是要删除word模版中的表格,不是创建表格
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
香肤源美容会所怎么去啊,有事要去办理
1.8排量相当于多少功率
窝凤沟村地址在哪,我要去那里办事
3.475约等于多少精确到百分位
3x十2x二5.5怎么列解方程
Win7 64位 CAD2012无法安装 好像是.NET Frame
汽车研究所是干什么的?
主耶稣快要来临了吗
魅蓝5和魅蓝note3哪个好
江南皮革厂16年经历了什么?
郎溪县梅诸中学地址在什么地方,想过去办事
放下书的古文
河南河北的河指的是
谁都不欠谁 我也不欠任何人
4.24dnf神秘人今天在哪
推荐资讯
老黄历査询司命黄道危日可以搬家吗
查浙ha6153在杭州秋实高架有没有违章
何加林在当代书画界属于什么地位,有哪些代表
机动战士敢达OL里哪种机体最厉害?
十八重溪里为什么会有11人失踪?
变压器年耗电量怎么计算?
电大心理学什么是手段目的分析
那第四五段写僧侣敲木鱼为人报晓有何作用呢?
牛肉土豆西红柿能加咖厘吗?
本届g20英国参加了吗
英威腾4/5.5kw变频器怎样设置启动时间
89年1月2日出生现在是几岁,22还是23?
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?