In form development, how to choose the processing tool that suits you?

introduction

GcExcel and EasyExcel are both excellent high-performance Excel processing libraries. GcExcel was developed by Grape City Company and can be used on Java and .Net platforms; while EasyExcel is a Java-based open source Excel processing library developed by Alibaba. In this article, we will compare GcExcel and EasyExcel to help readers make a wise choice in actual scenarios.

The difference between EasyExcel and GcExcel

Each product has its original design intention behind it. The main goal of EasyExcel is to solve some problems that POI encounters when reading and writing Excel files, such as excessive memory usage, frequent OOM (out of memory) errors, and insufficient performance to easily Limitations in handling large files. Therefore, EasyExcel aims to provide a more efficient and stable Excel reading and writing solution to meet the needs of processing large files.

Unlike EasyExcel, GcExcel's API design has unique original intentions. EasyExcel focuses on reading and writing Excel files quickly and easily, while GcExcel focuses more on improving reading and writing performance, formula calculation performance, and support for advanced Excel functions, such as charts, pivot tables, data validation, conditional formatting, etc.

On the basis of going beyond Excel functions, GcExcel actively invests in improving performance and provides developers with a rich variety of advanced Excel functions. Whether it is data analysis, report production or complex formula calculations, GcExcel has demonstrated its unique value with excellent performance and functions.

Application scenarios of EasyExcel and GcExcel

Both component libraries are extremely performant due to differences in the problems they solve, but they apply their performance benefits to different scenarios.

For EasyExcel, Excel is more like a data carrying method. When users need to deal with high concurrency and high memory requirements, EasyExcel shows more suitable performance.

However, after years of development by Microsoft, Excel has derived many different application scenarios, such as formula calculation, data filling, printing and reporting, etc. In these scenarios, the component library is usually required to cover enough Excel functions. Therefore, in these cases, GcExcel is more suitable.

For example, industries such as funds, insurance, finance and taxation usually require Excel formula calculations. By using GcExcel, a server-side automated formula calculation solution can be realized.

In addition, in fields such as metrological testing and laboratory management, there is a high demand for export functions. Functions such as automated PDF export and scheduled submission can be realized through GcExcel.

At the same time, Grape City also provides a pure front-end Excel component library product SpreadJS. If the scenario requires front-end and back-end collaboration for Excel processing, GcExcel is obviously more appropriate.

In short, according to different demand scenarios, choosing the appropriate component library can give full play to its performance advantages and provide better Excel processing solutions.

API design styles of EasyExcel and GcExcel

EasyExcel's API adopts streaming reading and writing and event-driven methods. This design concept allows the balance between performance and memory to be achieved when operating Excel. At the same time, its annotation-based design concept decouples code logic from Excel files, so that developers only need to think better about model design without having to worry about tedious Excel operations. To sum up, EasyExcel's API provides a high-performance and efficient Excel operation solution, allowing you to focus more on the implementation of business logic.

// 摘自EasyExcel官方文档

 // 有个很重要的点 DemoDataListener 不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去
 @Slf4j
 public class DemoDataListener implements ReadListener<DemoData> {

   /**
   * 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收
   */
   private static final int BATCH_COUNT = 100;
   /**
   * 缓存的数据
   */
   private List<DemoData> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
   /**
   * 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。
   */
   private DemoDAO demoDAO;

   public DemoDataListener() {
     // 这里是demo,所以随便new一个。实际使用如果到了spring,请使用下面的有参构造函数
     demoDAO = new DemoDAO();
   }

   /**
   * 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来
   *
   * @param demoDAO
   */
   public DemoDataListener(DemoDAO demoDAO) {
     this.demoDAO = demoDAO;
   }

   /**
   \* 这个每一条数据解析都会来调用
   *
   * @param data  one row value. Is is same as {@link AnalysisContext#readRowHolder()}
   * @param context
   */
   @Override
   public void invoke(DemoData data, AnalysisContext context) {
     log.info("解析到一条数据:{}", JSON.toJSONString(data));
     cachedDataList.add(data);
     // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
     if (cachedDataList.size() >= BATCH_COUNT) {
       saveData();
       // 存储完成清理 list
       cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
     }
   }

   /**
   * 所有数据解析完成了 都会被调用
   *
   * @param context
   */
   @Override
   public void doAfterAllAnalysed(AnalysisContext context) {
     // 这里也要保存数据,确保最后遗留的数据也存储到数据库
     saveData();
     log.info("所有数据解析完成!");
   }

   /**
   * 加上存储数据库
   */
   private void saveData() {
     log.info("{}条数据,开始存储数据库!", cachedDataList.size());
     demoDAO.save(cachedDataList);
     log.info("存储数据库成功!");
   }
 }

GcExcel's API is modeled on Excel, using concepts such as workbook, worksheet, and range, so that the entire component library can perfectly support various functions of Excel. If you are very familiar with Excel, you will feel very friendly and natural when using GcExcel.

These two design methods are like two products that solve different scenarios, and they are suitable for developers of different styles.

For developers who pursue the ultimate in technology, EasyExcel's flexibility is very suitable. For those pragmatic developers who pay more attention to quickly solving business needs, GcExcel provides a variety of API choices and is highly compatible with Excel, which can effectively empower this scenario.

 Workbook wb = new Workbook();
 IWorksheet sheet1 = wb.getWorksheets().get(0);
 Object[][] values = (Object[][]) sheet1.getRange("A1:Z26").getValue();

at last

Through the above comparison, EasyExcel and GcExcel are suitable for different situations.

When choosing, you can think according to different dimensions and choose an Excel processing library that is more suitable for your own scenario.

Fined 200 yuan and more than 1 million yuan confiscated You Yuxi: The importance of high-quality Chinese documents Musk's hard-core migration server Solon for JDK 21, virtual threads are incredible! ! ! TCP congestion control saves the Internet Flutter for OpenHarmony is here The Linux kernel LTS period will be restored from 6 years to 2 years Go 1.22 will fix the for loop variable error Svelte built a "new wheel" - runes Google celebrates its 25th anniversary
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/powertoolsteam/blog/10114541