Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.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

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
是什么导致excel在通过java更新文件后崩溃?_Java_Excel_Apache Poi - Fatal编程技术网

是什么导致excel在通过java更新文件后崩溃?

是什么导致excel在通过java更新文件后崩溃?,java,excel,apache-poi,Java,Excel,Apache Poi,我有一些java代码,可以打开excel工作表,向一组列添加自动筛选,然后保存和关闭。问题是,当用户打开文件并尝试从最小到最大或从最大到最小排序时,excel将冻结,然后崩溃。但若你们先过滤,那个么你们就可以解决这个问题,它不会冻结和崩溃 private static void AddFilter() { //Adds filter to the rows in Column 2 try { FileInputStream fileIn = new Fi

我有一些java代码,可以打开excel工作表,向一组列添加自动筛选,然后保存和关闭。问题是,当用户打开文件并尝试从最小到最大或从最大到最小排序时,excel将冻结,然后崩溃。但若你们先过滤,那个么你们就可以解决这个问题,它不会冻结和崩溃

private static void AddFilter()
{
    //Adds filter to the rows in Column 2
    try 
    {
        FileInputStream fileIn = new FileInputStream("C:\\Users\\gria\\Desktop\\Fleet Manager Summary.xls");

        HSSFWorkbook report = new HSSFWorkbook(fileIn);

        Sheet sheet  = report.getSheetAt(0);
        sheet.setAutoFilter(CellRangeAddress.valueOf("A5:P5"));


        FileOutputStream fileOut = new FileOutputStream("C:\\Users\\gria\\Desktop\\Fleet Manager SummaryT.xls");
        report.write(fileOut);
        fileOut.close();
    } 
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
谢谢,

更新: 经过一些实验后,我更新了信息和代码,因为原来的问题是为了更好地解释问题。

尝试更改

XSSFFormulaEvaluator.evaluateAllFormulaCells(report);

XSSFFormulaEvaluator.evaluateAllFormulaCells()适用于XSSF工作簿,但不适用于HSSF工作簿

而且, 您可以将注释代码编辑为:

for(int i = 5; i < sheet.getLastRowNum(); i++) 
{
    Cell cell = sheet.getRow(i).getCell(6);

    //I don't know if you have data in all of the cells,
    //So I suggest you to evaluate null
    if(cell != null && !cell.getStringCellValue().isEmpty())
    {
        cell.setCellValue(Double.valueOf(cell.getStringCellValue()).doubleValue());
    }
}
for(int i=5;i
如果不起作用,请告诉我您使用的POI版本。我使用的是3.15版。经过大量的实验,我发现我的问题并不是100%准确。我现在正在更新它。我用的是3.13,在我升级到3.15之后,我的代码用3.13没问题,坏了。所以我又回到了3.13。而且,当我将poi库版本3.13与poi ooxml库版本3.14一起使用时,我遇到了一些问题。当我在3.13版本中同时使用poi和poi ooxml库时,我没有任何问题。但是为什么要在HSSFWorkbook上调用XSSFFormulaEvaluator.evaluateAllFormulaCells()方法?我有一些方程正在更新,直到我发现excel类型正在从XLSX更改为XLS,我忘记删除它。我将把它从我的帖子中删除,以避免进一步的混淆。我将尝试使用3.13版本,看看是否有效。我会让你知道它是否有效。我已经下载了3.13版本,并引用了它,而不是3.15,但我仍然收到相同的问题。我还完全更新了原来的问题,以消除一些混乱后,一些更多的实验。顺便说一句,谢谢你的帮助
for(int i = 5; i < sheet.getLastRowNum(); i++) 
{
    Cell cell = sheet.getRow(i).getCell(6);

    //I don't know if you have data in all of the cells,
    //So I suggest you to evaluate null
    if(cell != null && !cell.getStringCellValue().isEmpty())
    {
        cell.setCellValue(Double.valueOf(cell.getStringCellValue()).doubleValue());
    }
}