Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

大批数据导出报错问题 #89

Open
wumangeng opened this issue Jul 24, 2023 · 1 comment
Open

大批数据导出报错问题 #89

wumangeng opened this issue Jul 24, 2023 · 1 comment

Comments

@wumangeng
Copy link

我使用的版本是1.4.6,当导出数据达到500行时报错:Attempting to write a row[1567] in the range [0,1567] that is already written to disk.
导出代码为:
List dataList = bareService.queryList(new BareSearchDTO());

        Workbook workbook = null;
        List<BareVO> bareVOList = new ArrayList<>(100);
        for (int i = 0; i < dataList.size(); i++) {
            System.out.print(i+",");
            bareVOList.add(dataList.get(i));
            if (bareVOList.size() == 100){
                workbook = ExcelExportUtil.exportBigExcel(new ExportParams(), BareVO.class, new IExcelExportServer() {
                    @Override
                    public List<Object> selectListForExcelExport(Object o, int i) {
                        if (((int) o) < i) {return null;}
                        System.err.println("obj -- "+ o +"   page -- "+ i);
                        return new ArrayList<Object>(bareVOList);
                    }
                },  1);
                bareVOList.clear();
            }
        }
        FileOutputStream fos = new FileOutputStream("D:/download/test_excel.xls");
        workbook.write(fos);
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

当i为500时报错

@wumangeng
Copy link
Author

结合文档的例子测试,可以得出,导出的实体只要含有@ExcelCollection就会造成无法导出,例如下面的代码,将注释部分打开就无法导出:
workbook = ExcelExportUtil.exportBigExcel(new ExportParams(), TestEntity.class, new IExcelExportServer() {
/**
* obj 就是下面的10,限制条件
* page 是页数,他是在分页进行文件转换,page每次+1
*/
@OverRide
public List selectListForExcelExport(Object obj, int page) {
if (((int) obj) == page) {
return null;
}

                List<Object> list = new ArrayList<Object>();
                for (int i = 0; i < 10000; i++) {
                    TestEntity client = new TestEntity();
                    client.setName("小明" + page);
                    client.setAge((page-1)*10000+i);

// List signList = new ArrayList<>();
// BareSign bareSign = new BareSign();
// bareSign.setOrders(i).setLongitude("aaa").setLatitude("bbb");
// signList.add(bareSign);
// BareSign bareSign2 = new BareSign();
// bareSign2.setOrders(i).setLongitude("ccc").setLatitude("ddd");
// signList.add(bareSign2);
// client.setBareSignList(signList);
list.add(client);
}
return list;
}
}, 2);

TestEntity对象属性为:
@DaTa
public class TestEntity{
@Excel(name = "名字",needMerge = true)
private String name;
@Excel(name = "年龄",needMerge = true)
private Integer age;

// @ExcelCollection(name = "裸土边界点")
// private List bareSignList;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant