Create an Excel file with Apache POI HSSF
At the beginning
The Web is full of data and is a perfect media to search and display data.Many users want to analyze the data in a way that suits their thinking process when they find data.Some web applications are trying to meet this need by increasing the data display options.It may be appropriate.For example, an e -commerce site that can compare prices and functions.In many other cases, browser is not a tool suitable for data analysis.In particular, power users will not be satisfied.Financial data is the best example.Business intelligence site users want to see the data in various ways, but if you try to create different display methods for each user, you will be less convenient and increase maintenance work.Individual investors often collect frustration in the flexibility of the stock price analysis site.
In some very expensive platforms, you can create a web page that allows users to operate data until they are satisfied.Such a platform costs a lot of licensing, hardware and training, and the development costs more.Depending on the application, you can get a high investment revenue from this cost.In addition, it is very easy to provide data in a format that users can operate freely.
The spreadsheet is perfect for this purpose, and the expensive platform as described above automatically generates spreadsheets.
Alternatively, you can make these spreadsheets yourself without spending money.
The previous article "Reading Excel Files with Apache Poi HSSF" explained how to use Excel Book to provide data to Java applications.This time, let's look at how to provide data to users in the same format.
Easy spreadsheet
In the case of a very simple spreadsheet, all work can be done automatically using the HTML reading function incorporated in the Office application.What is necessary to convert the HTML table into a spreadsheet is on the header line.
Col 1 | Col 2 | Col 3 |
---|---|---|
1 | 2 | 3 |
4 | 5 | 6 |
The reason why the Java code is not used here is that the author is a sloppy.Readers should imagine the process of repeating the dataset repeatedly and setting the value of the header and field.
Next, set the mime type of JSP.
In some web servers, the MIME type web is as follows..You need to define it in XML.
xlsapplication/vnd.ms-excel
When a user clicks the standard Href link to this JSP, a spreadsheet is created.