Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 删除工作表后打开excel时出现POI错误_Java_Excel_Apache Poi - Fatal编程技术网

Java 删除工作表后打开excel时出现POI错误

Java 删除工作表后打开excel时出现POI错误,java,excel,apache-poi,Java,Excel,Apache Poi,我需要从工作簿中删除第一张工作表(工作表数>1) 这是我的代码: inputStreamExcel = new FileInputStream(path); wrkbook = new XSSFWorkbook(inputStreamExcel ); wrkbook .removeSheetAt(0); outputStreamExcel = new FileOutputStream(path); wrkbook.write(outputStreamExcel );

我需要从工作簿中删除第一张工作表(工作表数>1)

这是我的代码:

inputStreamExcel = new FileInputStream(path);
wrkbook = new XSSFWorkbook(inputStreamExcel );

wrkbook .removeSheetAt(0);
outputStreamExcel = new FileOutputStream(path);             
wrkbook.write(outputStreamExcel );      
outputStreamExcel .flush();
outputStreamExcel .close();
我没有任何例外。 但是,当我尝试打开excel文件时,出现了一个错误:

excel发现无法读取的内容


如果excel未正确保存,则会发生此错误,
您可能希望检查保存时,
当前选定/活动单元格
是否未指向空行,或者
活动工作表
是否不为空

请在删除第一张工作表后再次尝试设置活动工作表:

...
wrkbook.removeSheetAt(0);
wrkbook.setActiveSheet(0);
...

这应该可以解决问题。

您所说的活动单元格是什么意思?活动单元格是指当前选定的单元格。此外,在删除当前工作表之前/之后(无论如何),需要更改活动工作表。我认为它解决了问题,在接受此答案之前,我将运行更多测试场景。谢谢