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 to use code to import and export excel data in java in Excel-converter

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

Share

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

It is believed that many inexperienced people don't know what to do about how to import and export excel data in java with code in Excel-converter. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Excel-converter is a project that I developed during the Spring Festival last year to import and export excel data in java.

At that time, I had been an java engineer in a company for several years, and I was involved in several projects with many excel import and export functions. So after I have finished my work, I would like to make a simple tool that can satisfy the data import and export excel function of most projects.

At the time of New Year's Day's holiday last year, I began to prepare this project, and after the holiday, there was no good way to achieve the function. After that, due to the stress of work, the project was occasionally able to submit a little code late at night. The project has been temporarily stranded.

Most of the functions of this project were developed during the Spring Festival holiday. At that time, when I returned to my hometown, I still wrote code in front of the computer every day, thinking about how to make it more convenient to use.

Before the end of the Spring Festival holiday, a preliminary version has come out (excel-converter). It is not difficult to use, but it is not concise at all. So thanks to the automatic configuration of springboot and the direction that the convention is greater than configuration, I developed excel-converter-starter, a project that relies on excel-converter and is also a springboot starter project, and the use of this project is very simple:

The degree of simplicity is as follows:

After adding the excel-converter-starter dependency and injecting ExExporter, export the excel using the following sentence of code:

ExExporter.export (dataList, file)

This is done using the default configuration.

For the data imported into Excel, as long as you specify the entity attributes corresponding to the excel data column, using excel-converter-starter, you can also import a sentence of code as the List of java:

List peo = exImporter.convert (". / Enterprise personnel Summary Table .xlsx", Person.class)

A prerequisite for code import: specify the attributes of the java entity corresponding to the data column in the first row of the excel data. This line is called nameRow in the source code, and the location of this line is also free to configure.

Of course, when the above code is imported and exported, some related properties can also be freely configured; for the parameters of the excel file, you can also use File instances, String paths, and input and output streams.

All this time, the code has been in gitee and has been open source.

Considering that in actual use, there is not only the requirement to export list, but also the requirement to populate the template with data according to a given template. Therefore, after the end of the holiday, I also took the time to do this function.

Later, the work project sure enough to achieve such an export, developers with the project team think this task is too troublesome, but I volunteered to take it, add their own open source project jar package, simple configuration calls to achieve the function, the next two days to go to work to watch random play, and then brush to play. (the boss didn't find out either.)

In July this year, I applied for the domain name jvm123.com (inspired by java1234 knowledge Resource sharing Network), so I released these two improved projects to maven Central Warehouse as version 1.0 in the name of com.jvm123, so that anyone can use them.

Search for jvm123 in the central warehouse and you will see excel converter and excel converter starter, as follows:

Mvn central warehouse-jvm123.com

The source code of the project can access the code cloud space: https://gitee.com/yawensilence/excel-converter

After reading the above, have you mastered how to import and export excel data in java with code in Excel-converter? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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