在现有excel文件中添加工作表

时间:2015-07-21 09:54:08

标签: java excel apache-poi

我尝试过以各种方式添加Excel电子表格。但问题始终如一。

我尝试了这里提出的代码,

问题:

Exception in thread "main" java.lang.ClassCastException: org.apache.poi.hssf.record.BOFRecord cannot be cast to org.apache.poi.hssf.record.TabIdRecord
    at org.apache.poi.hssf.model.InternalWorkbook.fixTabIdRecord(InternalWorkbook.java:792)
    at org.apache.poi.hssf.model.InternalWorkbook.checkSheets(InternalWorkbook.java:742)
    at org.apache.poi.hssf.model.InternalWorkbook.setSheetName(InternalWorkbook.java:579)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.createSheet(HSSFWorkbook.java:748)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.createSheet(HSSFWorkbook.java:101)
    at ReadTry.main(ReadTry.java:28)

1 个答案:

答案 0 :(得分:0)

相同的代码适用于我

public class Modify {
   public static void main(String[] args) throws Exception {
    File f=new File("d:/temp/wb.xls");
    Workbook wb = WorkbookFactory.create(f);
    wb.createSheet("sheet2");
    FileOutputStream out = new FileOutputStream("d:/temp/wb1.xls");
    wb.write(out);
    out.close();
  }
} 

我使用了poi-3.9-20121203.jarpoi-ooxml-3.9-20121203.jar