Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Java operate on Excel?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to operate Excel by Java". In daily operation, I believe many people have doubts about how to operate Excel by Java. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to operate Excel by Java". Next, please follow the editor to study!

1 Overview

Presumably, in the usual project development process, we often involve the export function of Excel files, and generally choose Apache poi components to complete, but usually need to write a lot of code, which undoubtedly increases the complexity, and there is a serious problem is very memory consumption, easy to lead to OOM, fortunately Ali open source easyexcel, it is based on Apache poi development of a component, easyexcel rewrote poi to 07 version of Excel parsing To be able to use POI sax for an original 3M excel still needs about 100m of memory to be reduced to the KB level, and no memory overflow will occur in a large excel, but in the course of actual use, it is not very convenient for easyexcel to operate each cell, so I rewrite a component easyexcel-util. This project is based on Ali easyexcel. On this basis, it is further encapsulated to make it easier to write data. It is easier to handle the font and style of each cell through the extracted ExcelDataHandler interface, and how to use easyexcel-util is described below.

2 easyexcel-util component uses 2.1 Maven package to introduce com.github.aifeinik easyexcel-util 1.02.2 Excel data writing 2.2.1 small amount of data is written to a single sheet at one time, using the default style public class ExcelTest {CampaignModel M1 = new CampaignModel ("2019-01-01", "10000000", "campaign1", "12.21,100,0.11") CampaignModel m2 = new CampaignModel ("2019-01-02", "12000010", "campaign2", "13", "99", "0.91"); CampaignModel m3 = new CampaignModel ("2019-01-03", "12001010", "campaign3", "10", "210"," 1.13") CampaignModel M4 = new CampaignModel ("2019-01-04", "15005010", "campaign4", "21.9"," 150,0.15 "); ArrayList data1 = Lists.newArrayList (M1, m2); ArrayList data2 = Lists.newArrayList (m3, M4) Test public void writeExcelWithOneSheet () throws Exception {ExcelUtil.writeExcelWithOneSheet (new File ("G:/tmp/campaign.xlsx"), "campaign", data1);}}

The write effect is as follows:

2.2.2 A small amount of data is written to a single sheet at once, using the custom style @ Test public void writeExcelWithOneSheet2 () throws Exception {ExcelUtil.writeExcelWithOneSheet (new File ("G:/tmp/campaign.xlsx"), "campaign", data1, new CampaignDataHandler ());}

The write effect is as follows:

2.2.3 A small amount of data is written to multiple sheet at a time. The default style @ Test public void writeExcelWithMultiSheet () throws Exception {Map

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report