First Lecture
About Poi
Apache POI is an open source library of the Apache Software Foundation, where POI provides APIs to Java programs to read and write to Microsoft Office format archives.
1. Create a new workbook and name the workbook
Workbook wb=new// define a newer workbook fileoutputstream fileout= new FileOutputStream ("c:\\-out workbook with Poi"); Wb.write (fileout); Fileout.close () ;
2. Create a new Sheet page and name the Sheet page
Workbook wb=new// define a workbook wb.createsheet ("first sheet page"); // Create a first sheet page Wb.createsheet ("second sheet page"); // Create a second sheet page fileoutputstream fileout=new fileoutputstream ("c:\\ with poi out of sheet page. xls"); Wb.write ( Fileout); Fileout.close ();
The effect is as follows:
3. Create a cell and assign a value to the cell
Workbook WB=NewHssfworkbook ();//to define a new workbookSheet Sheet=wb.createsheet ("first sheet page");//Create a first sheet pageRow Row=sheet.createrow (0);//Create a rowcell Cell=row.createcell (0);//Create a cell 1th columnCell.setcellvalue (1);//set a value for a cellRow.createcell (1). Setcellvalue (1.2);//Create a cell the 2nd column value is 1.2Row.createcell (2). Setcellvalue ("This is a string type");//Create a cell with the 3rd column value as a stringRow.createcell (3). Setcellvalue (false);//Create a cell the 4th column value is a Boolean typeFileOutputStream fileout=NewFileOutputStream ("c:\\ Cell.xls with Poi"); Wb.write (fileout); Fileout.close ();
The effect is as follows:
The source code is as follows: HTTP://YUNPAN.CN/CDRTNABGZRGDM access password 4188
POI Tutorial First: Create a new workbook, Sheet page, create a cell