Overview
Everyday Office, the most office software we use is Microsoft Office, so one of the things we develop that inevitably comes across is the ability to interact with Office, so some smart people develop the appropriate feature pack, With our programmers we can easily read and write Microsoft Office format archives, which is the POI.
Excel operations that encapsulate a POI
For the POI specific Excel operation, here no longer repeat, this section of the main task is to do a package of these most basic functions, so that they use most of the operation of Excel.
the final effect after encapsulation
Export the data of an object to Excel through a template implementation, import data from Excel into the appropriate object
excelresources
to make the object's data export to Excel, we first need to determine what the data object's properties are in Excel. And the first column of the attribute in Excel? To solve this problem, we need to customize an annotation and then make the corresponding self-description on the class of the data object. Excelresources is the annotation class .
Excelheader
after the class of the data object is added self-describing, we can get its corresponding annotation value according to the object's class type object, for the value of these annotations, we should use an object to save, and then, in sorting the data, output to Excel On Excelheader is an annotated object that holds each property on the data object.
exceltemplate
The export operation of the data is based on the template, so we should need to have a class that represents the Excel template from the program, and Exceltemplate is the class. We analyze from the angle of the face object what function this class should have.
You first have to read the template into Excel and export Excel. We're going to save the data to excel in memory, we need to know where the data is starting from in Excel, so we need to specify some special identifiers, the sub-table used to code the title of Excel, the date, the starting position of the data, the default style, other non-default styles, and, The class should have the ability to replace these special identities, set cell styles, and create rows and cells.
Excelutil
Exceltemplate is a template-based operation, and the Excelutil is not based on the template, and the two classes are functionally identical.
Summary
The encapsulation of this feature can be met for most of the requirements. Code download
POI Operations Excel