【问题标题】:Java, Apache POI, XSSFWorkbook extremly slowJava、Apache POI、XSSFWorkbook 极慢
【发布时间】:2021-02-01 20:51:02
【问题描述】:

我使用 Apache POI 读取 excel 文件 (xlsx) 这在 Eclipse 中运行良好。 30.000 行和 20 列没问题。大约 5 秒后加载。

如果我生成一个可运行的 JAR 文件,它不会处理 excel 文件

    try {
        soeArraylist.clear();
        //JOptionPane.showMessageDialog(null, "SoE Pre Test 1", "Done" , JOptionPane.INFORMATION_MESSAGE);
        //Workbook workbook2 = new XSSFWorkbook();
        //JOptionPane.showMessageDialog(null, "SoE Pre Test 2", "Done" , JOptionPane.INFORMATION_MESSAGE); 
        
        JOptionPane.showMessageDialog(null, "SoE Import started 1", "Done" , JOptionPane.INFORMATION_MESSAGE); 
        
        FileInputStream excelFile = new FileInputStream(new File(FILE__NAME));
        JOptionPane.showMessageDialog(null, "SoE Import started 2 " + FILE__NAME, "Done" , JOptionPane.INFORMATION_MESSAGE); 
        
        
        Workbook workbook = new XSSFWorkbook(excelFile);
        JOptionPane.showMessageDialog(null, "SoE Import started 3", "Done" , JOptionPane.INFORMATION_MESSAGE); 
        
        Sheet datatypeSheet = workbook.getSheet("SoE");
        JOptionPane.showMessageDialog(null, "SoE Import started 4", "Done" , JOptionPane.INFORMATION_MESSAGE); 
        
        Iterator<Row> iterator = datatypeSheet.iterator();
        JOptionPane.showMessageDialog(null, "SoE Import started 5", "Done" , JOptionPane.INFORMATION_MESSAGE); 
        
        DataFormatter formatter = new DataFormatter(Locale.US);
        //JOptionPane.showMessageDialog(null, "SoE Import started 6", "Done" , JOptionPane.INFORMATION_MESSAGE); 
        
        JOptionPane.showMessageDialog(null, "File opened", "Done" , JOptionPane.INFORMATION_MESSAGE); 
        while (iterator.hasNext()) {

            Row currentRow = iterator.next();

 ........ code removed .......

    } catch (FileNotFoundException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, "SoE Import FileNotFoundException", "FileNotFoundException" , JOptionPane.INFORMATION_MESSAGE);
    } catch (IOException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, "SoE Import IOException", "IOException" , JOptionPane.INFORMATION_MESSAGE);
    }

所以在 SoE Import "started 2" 之后它就停止了 好的,它不会停止,但看起来它的处理时间很长。 1小时后仍然没有结果。

我试图在 Eclipse 之外创建一个空的工作簿和最后 20 秒。在 Eclipse 中不到 1 秒

    JOptionPane.showMessageDialog(null, "SoE Pre Test 1", "Done" , JOptionPane.INFORMATION_MESSAGE);
    Workbook workbook2 = new XSSFWorkbook();
    JOptionPane.showMessageDialog(null, "SoE Pre Test 2", "Done" , JOptionPane.INFORMATION_MESSAGE);

Java 在 Eclipse 和 W10 机器上是 1.8。 我知道这里有一些类似的问题,但没有一个在 Eclipse 和作为独立 JAR 之间有不同的时间。

有什么想法吗?

【问题讨论】:

    标签: java excel apache-poi


    【解决方案1】:

    当我在 POI 5.0.0 中遇到这个问题时,对我有用的是回滚到 4.1.2,它的性能提高了大约 20%,但随后还选择了“将所需的库提取到 JAR”而不是“需要的包”库到 JAR”,这是默认的 Eclipse 设置,与回滚到 4.1.2 相比,改进了大约 90%。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-26
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 2017-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多