Well, I learned how to operate jxl.
Step 1:
String filepath = "d :\\ test.xls ";
Writableworkbook WWB;
Outputstream OS = new fileoutputstream (new file (filepath ));
WWB = Workbook. createworkbook (OS );
// Use the file output stream to generate an Excel file for xls
Step 2: Create a sheet table
Writablesheet sheet = WWB. createsheet ("product list", 0 );
Step 3: Use the label that comes with jxl to add content to a specified location
Label Label = new label (INT column, int row, string content, jxl. format. cellformat format );
Four parameters:
Column
Row
Content
Format (optional) cellformat is an interface with multiple formatting subclasses.
Step 4: Use jxl. Write. Number to add numbers to a specified position
1. Define a formatting template first
Jxl. Write. numberformat NF = new jxl. Write. numberformat ("#.##");
2. writablecellformat is a subclass of cellformat and accepts a template parameter.
Jxl. Write. writablecellformat WCF = new jxl. Write. writablecellformat (NF );
3. Add a number to the specified position and specify the format template
Jxl. Write. Number NB = new jxl. Write. Number (2, 1, 2.45, WCF );
Step 5: add the corresponding worksheet after the location is specified:
Sheet. addcell (writablecell)
Step 6: Write Data and close the output stream
WWB. Write ();
WWB. clost ();
Supplement: Write of Boolean value and date format:
Write method of Boolean value:
Jxl. Write. boolean flag = new jxl. Write. boolean (6, 1, true );
Sheet. addcell (FLAG );
Write method in date format:
/**
* Defines the public format of the display date.
* Example: yyyy-mm-dd hh: mm
*/
Simpledateformat SDF = new simpledateformat ("yyyy-mm-dd ");
String newdate = SDF. Format (New java. util. Date ());
// Fill in the generated date
Label = new label (4,1, newdate );
Sheet. addcell (Label );