The goal of the Apache POI project is to use the Java API to create and maintain various Office files (MS Word,ms PowerPoint and Ms Excel). This series of articles is primarily for Excel file operations. For Excel operations, Apache POI offers two models: HSSF and XSSF. The difference, please refer to Figure 1 below. As of May 28, 2015, the current latest version is 3.12. For specific information, we can visit its official website: http://poi.apache.org/
1. Here is the basic code for creating a workbook with Apache POI
Import Org.apache.poi.hssf.usermodel.hssfworkbook;import Java.io.fileoutputstream;import java.io.IOException; public class newworkbooktest{public static void Main (string[] args) throws IOException { Hssfworkbook wb = new Hssfworkbook (); FileOutputStream fileout = new FileOutputStream ("Helloworld.xls"); Wb.write (fileout); Fileout.close (); }}
2. Here's the code for creating an Excel cell form with Apache POI
Import Org.apache.poi.hssf.usermodel.hssfworkbook;import Org.apache.poi.hssf.usermodel.hssfsheet;import Org.apache.poi.ss.util.workbookutil;import Java.io.ioexception;import Java.io.fileoutputstream;public Class newsheet {public static void Main (string[] args) throws IOException { Hssfworkbook wb = new Hssfworkbook (); Hssfsheet Sheet1 = Wb.createsheet ("Sheet1"); Hssfsheet Sheet2 = Wb.createsheet (); Create with default name final String name = "Sheet2"; Wb.setsheetname (1, Workbookutil.createsafesheetname (name)); Setting sheet name later fileoutputstream fileout = new FileOutputStream ("Workbooktest.xls"); Wb.write (fileout); Fileout.close (); }}
(1) How to use Apache POI to manipulate Excel files-----Getting Started