简体   繁体   中英

Apache POI Copy row with formula n times

i have a sheet with 6 columns and like 50k rows. I would like to copy one row n times. For now I am doing like this:

for (int i=0; i<=excel_max_row; i++) {
        row = sheet3.createRow((short) i);
        cell = row.createCell(0);
        cell.setCellFormula("IFERROR(LOOKUP(Template!A"+(i+2)+",'Dropdown-Values'!A:A,'Dropdown-Values'!B:B),\"\")");

        cell = row.createCell(1);
        cell.setCellFormula("IF(Template!B"+(i+2)+"=0,\"\",Template!B"+(i+2)+")");

        cell = row.createCell(2);
        cell.setCellFormula("IFERROR(LOOKUP(Template!C"+(i+2)+",'Dropdown-Values'!C:C,'Dropdown-Values'!D:D),\"\")");

        cell = row.createCell(3);
        cell.setCellFormula("IFERROR(LOOKUP(Template!D"+(i+2)+",'Dropdown-Values'!E:E,'Dropdown-Values'!F:F),\"\")");

        cell = row.createCell(4);
        cell.setCellFormula("IFERROR(LOOKUP(Template!E"+(i+2)+",'Dropdown-Values'!E:E,'Dropdown-Values'!F:F),\"\")");

        cell = row.createCell(5);
        cell.setCellFormula("IF(Template!F"+(i+2)+"=0,\"\",Template!F"+(i+2)+")");
}
XSSFFormulaEvaluator.evaluateAllFormulaCells(wb);

It works but is very slow because excel_max_row can be up to 50k. Is there any way to quick copy a row n times with also all forumals?

Thanks a lot

当用户打开文件时,我评估所有公式:

wb.setForceFormulaRecalculation(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM