Detailed explanation of the method of exporting excel using POI on Java Web

This article describes the method of exporting excel using POI on Java Web. Share with you for your reference, as follows:

Adopt spring MVC Architecture:

The controller layer code is as follows

The service layer code is as follows:

The JS code of the foreground is as follows:

Set excel style and precautions:

Note 1: merge cells new cellrangeaddress (int, int, int), first row (0-based), last row (0-based), first column (0-based), last column (0-based)

Note 2: merge cell string [] excel header = {"region (city)", "number of network devices"};

Although the merged cell is one, its cell content should still be retained. Here, replace it with an empty string, otherwise the subsequent header will not be displayed

Note 3: fill cells

Correct writing:

Incorrect writing:

In order to save an hssfcell object, I used the wrong writing method. As a result, the hssfcell object was created twice. Finally, only the style was retained, and the content could not be displayed

Readers interested in more Java related content can view the topics on this site: Java data structure and algorithm tutorial, summary of java file and directory operation skills, summary of Java DOM node operation skills, and summary of Java cache operation skills

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>