1

大きな Excel ファイルを変更する Java アプリケーションを実行しています。そして、私は更新が行われるのに時間がかかることを経験しています..

各セルについて、休閑地としての変更に基づいて更新を実行しています

  public boolean updateCellData(ColumnName, RowNum, Data){
    FileInputStream fis = new FileInputStream(path);
        Workbook    workbook = WorkbookFactory.create(fis);

        row =  getRow(rowNum-1);
            if (row == null){
                row = sheet.createRow(rowNum-1);
            }
            cell = row.getCell(colNum);
            if (cell == null){
                cell = row.createCell(colNum);
            }
            cell.setCellValue(data);
            fileOut = new FileOutputStream(path);
            workbook.write(fileOut);
            fileOut.close();
    }

コードに対して実行できる最適化はありますか?

4

1 に答える 1

3

すべての更新操作が終了したら、Excel を 1 回開き、Excel を閉じます。

例 :

      FileInputStream fis =null;
     Workbook workbook=null;
    public void openWorkbook(){
         fis = new FileInputStream(path);
         workbook = WorkbookFactory.create(fis);
    }

    public boolean updateCellData(ColumnName, RowNum, Data){

            row =  getRow(rowNum-1);
                if (row == null){
                    row = sheet.createRow(rowNum-1);
                }
                cell = row.getCell(colNum);
                if (cell == null){
                    cell = row.createCell(colNum);
                }
                cell.setCellValue(data);
      }

    public void closeWorkbook(){
        fileOut = new FileOutputStream(path);
        workbook.write(fileOut);
        fileOut.close();
    }
于 2013-01-30T05:54:44.200 に答える