The instructor asked me to check some java excel operations. I had to check them online for a long time, but I didn't know much about them. I would like to summarize some valuable information.
It is found that there are many third-party jar packages used to operate Excel in java. There are two sets of influential APIs available: POI and jExcelAPI.
I. jExcelAPI
JExcelAPI is a Korean programmer's work. Although it is not as noble as POI, it is simple and convenient in the use process of the Author. It provides excellent support for Chinese and powerful functions. Its download address is:Http://www.andykhan.com/jexcelapi/
Its features are described as follows:
● Support all versions of Excel-
● Generate standard Excel 2000 format
● Supports font, number, and date operations
● Ability to modify cell attributes
● Images and charts supported
It should be said that the above functions have roughly met our needs. The most important thing is that this API is pure Java and does not depend on Windows. Even if it runs in Linux, it can process Excel files correctly. In addition, this API has limited support for graphics and charts and only recognizes PNG formats.
It should be said that the above functions have roughly met our needs. The most important thing is that this API is pure Java and does not depend on Windows. Even if it runs in Linux, it can process Excel files correctly. In addition, this API has limited support for graphics and charts and only recognizes PNG formats.
Build Environment
Unpack the downloaded file, get jxl. jar, and put it into classpath. The installation is complete.
Basic operations
1. Create a file
An Excel file named "testing data .xls" will be generated. The first worksheet is named "first page". The general effect is as follows:
Code (CreateXLS. java ):
// Generate an Excel class
Import java. io .*;
Import jxl .*;
Import jxl. write .*;
Public class CreateXLS
{
Public static void main (String args [])
{
Try
{
// Open the file
WritableWorkbook book =
Workbook. createWorkbook (new file(development test .xls "));
// Generate a worksheet named "first page". The parameter 0 indicates that this is the first page.
WritableSheet sheet = book. createSheet ("first page", 0 );
// In the constructor of the Label object, the cell position is the first row (0, 0) in the first column)
// And the cell content is test
Label label = new Label (0, 0, "test ");
// Add the defined cells to the worksheet
Sheet. addCell (label );
/* Generate a cell for saving numbers
The full package path of Number must be used; otherwise, the syntax is ambiguous.
The cell position is the second column, the first row, and the value is 789.123 */
Jxl. write. Number number = new jxl. write. Number (1,0, 789.123 );
Sheet. addCell (number );
// Write data and close the file
Book. write ();
Book. close ();
} Catch (Exception e)
{
System. out. println (e );
}</