Git Product home page Git Product logo

Comments (5)

Chat2DB-Pro avatar Chat2DB-Pro commented on July 16, 2024

目前支持的是在文件未关闭的情况下是可以持续读写,不用担心内存溢出问题,因为默认5000条数据是会flush到磁盘的。你所说的保存后再读写以前我没遇到过这种场景,确实没这么写过。

from easyexcel.

Chat2DB-Pro avatar Chat2DB-Pro commented on July 16, 2024

能够把你的场景,我看下合理性是否一定需要文件写已经关闭了再写呢?

from easyexcel.

yunshang734 avatar yunshang734 commented on July 16, 2024

public class LocalTest {

public static void main(String[] args) {
    String exportFilePath = "E:\\LocalTest.xlsx";
    Integer baseIndex = 0;
    for (int index = 0; index < 3; index++) {
        doExport(exportFilePath, baseIndex);
        baseIndex = baseIndex + 10000;
    }
}

private static void doExport(String exportFilePath, Integer baseIndex) {
    List<Order> orderList = new ArrayList<>();
    for (int index = 0; index < 10000; index++) {
        Order order = new Order();
        order.setFOrderId("FOrderId" + index + baseIndex);
        order.setFMerchantId("FMerchantId" + index + baseIndex);
        order.setFUserName("FUserName" + index + baseIndex);
        order.setFState(new Random().nextInt(3));
        order.setFAmount(new Random().nextInt(1000000));
        order.setFRefundAmount(new Random().nextInt(1000000));
        order.setFGoodsType("FGoodsType" + index + baseIndex);
        order.setFGoodsName("FGoodsName" + index + baseIndex);
        order.setFGoodsDetail("FGoodsDetail" + index + baseIndex);
        order.setFTime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
        orderList.add(order);
    }
    EasyExcelUtil.export(exportFilePath, orderList, Order.class, ExcelTypeEnum.XLSX);
}

}

public class EasyExcelUtil {

public static <T extends BaseMeta> void export(String exportFilePath, List<T> metaList, Class clazz, ExcelTypeEnum excelTypeEnum) {
    try {
        OutputStream outputStream = new FileOutputStream(exportFilePath);
        ExcelWriter excelWriter = new ExcelWriter(outputStream, excelTypeEnum);
        Sheet sheet1 = new Sheet(1, 0, clazz);
        excelWriter.write(metaList, sheet1);
        excelWriter.finish();
    } catch (FileNotFoundException exception) {
        System.out.println("EasyExcelUtil.export(), FileNotFoundException: " + exception);
    }
}

}

以上是我的代码,一个简单的测试DEMO,请看下。

from easyexcel.

Chat2DB-Pro avatar Chat2DB-Pro commented on July 16, 2024

OK,和我理解的是一样的,暂时不要在Excel没有写完的时候就去调finish().一个Excel写完再Finish()。内存问题不用担心。不过使用者确实可能会像你这样使用。后续版本优化这个问题

from easyexcel.

kud1 avatar kud1 commented on July 16, 2024

重新读取文件续写这个功能有加上吗?

from easyexcel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.