[英]How to remove Sheets form Excel sheet using JExcel
I am trying to remove sheets from an existing excel file using jxl api. 我正在尝试使用jxl api从现有的excel文件中删除工作表。
I cannot use 我不能使用
WritableWorkbook wwb = new Workbook.createWorkbook("abc.xls");
as I do not want to create a new workbook, rather I want to use an existing one. 因为我不想创建一个新的工作簿,而是想使用一个现有的工作簿。
I cannot use 我不能使用
Workbook wb = new Workbook.getWorkbook("abc.xls");
as this would get the file in read only mode. 因为这样会使文件处于只读模式。 There is no " getWorkbook " method for the class WritableWorkbook . WritableWorkbook类没有“ getWorkbook ”方法。 Please tell me how to go about it. 请告诉我如何去做。
I searched through examples online but in each case a new workbook is being created rather than using an existing one. 我在线搜索了示例,但在每种情况下,都是在创建新的工作簿,而不是使用现有的工作簿。
If you want to edit an existing excel file,you can do like this: 如果要编辑现有的excel文件,可以这样做:
//Get the existing excel file
Workbook file=Workbook.getWorkbook(new File("test.xls"));
//Open a copy of the excel file,and specify the parameters to write the data back
//to the original file.
WritableWorkbook writeBook=Workbook.createWorkbook(new File("test.xls"),file);
writeBook.removeSheet(0);
WritableWorkbook wwb = new Workbook.createWorkbook("abc.xls");
This line is wrong. 这行是错误的。 You can't use "new" since the class Workbook is a factory that returns a new Workbook. 您不能使用“ new”,因为Workbook类是一个返回新Workbook的工厂。 Try this: 尝试这个:
WritableWorkbook wwb = Workbook.createWorkbook("abc.xls");
Call removeSheet on the workbook instance? 在工作簿实例上调用removeSheet ? It's right there in the documentation... 就在文档中...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.