时间:2010-07-26 07:39:01

标签: java apache-poi

2 个答案:

答案 0 :(得分:5)

答案 1 :(得分:1)

为了处理常规样式和数据,我们可以迭代每个单元格 但是如果我们有公式启用的单元格,不可编辑的单元格,合并单元格,那么这是更好的解决方案:
我尝试过像复印纸一样的东西,但它没有用 此外,我需要复制一张表格,其中有一些不可编辑的单元格和公式启用的单元格。

此解决方案对我有用:
1)复制整个工作簿
2)删除不必要的表格 3)将新表格添加到上面的书中

//input source excel file which contains sheets to be copied
file = new FileInputStream("C:\\SamepleTemplate.xlsx");
workbookinput = new XSSFWorkbook(file);

//output new excel file to which we need to copy the above sheets
//this would copy entire workbook from source
XSSFWorkbook workbookoutput=workbookinput;

//delete one or two unnecessary sheets, you can delete them by specifying the sheetnames
workbook.removeSheetAt(workbook.getSheetIndex(workbook.getSheet(" your sheet name ")));

//if you want to delete more sheets you can use a for to delete the sheets
for (int index=0;index<=5;index++)
{
   workbook.removeSheetAt(index);
}

//To write your changes to new workbook
FileOutputStream out = new FileOutputStream("C:\\FinalOutput.xlsx");
workbookoutput.write(out);
out.close();