PackageCom.coracle.yk.xmanager.util.poi;ImportOrg.apache.poi.hssf.usermodel.HSSFCellStyle;ImportOrg.apache.poi.hssf.usermodel.HSSFRow;ImportOrg.apache.poi.hssf.usermodel.HSSFSheet;ImportOrg.apache.poi.hssf.usermodel.HSSFWorkbook;ImportOrg.apache.poi.poifs.filesystem.POIFSFileSystem;ImportOrg.apache.poi.ss.usermodel.Cell;ImportOrg.apache.poi.ss.usermodel.CellStyle;ImportOrg.apache.poi.ss.usermodel.Row;ImportJava.io.*;/*** Created by Huangbaidong on 2016/3/17.*/ Public classPoitest { Public Static voidMain (String args[])throwsIOException {String path= "D:\\statistic.xls"; //Poifsfilesystem fs = new Poifsfilesystem (New FileInputStream ("D:/test.xls"));Hssfworkbook WB =NewHssfworkbook (); Hssfsheet Sheet1= Wb.createsheet ("Shopping Guide 1")); Hssfsheet Sheet2= Wb.createsheet ("Shopping Guide 2")); Hssfsheet Sheet3= Wb.createsheet ("Shopping Guide 3")); Sheet1.setdefaultcolumnwidth (25);//Set the default column widthSheet2.setdefaultcolumnwidth (25); Sheet3.setdefaultcolumnwidth (25); Sheet1.setdefaultrowheight (( Short) 300);//Set default row heightSheet2.setdefaultrowheight (( Short) 300); Sheet3.setdefaultrowheight (( Short) 300); Row row; Cell cell; Hssfcellstyle style=Wb.createcellstyle (); for(inti=0; i< 10; i++) {row= Sheet1.createrow (i+1); Cell= Row.createcell (0); Cell.setcellvalue ("NAME0" +i); Cell= Row.createcell (1); Cell.setcellvalue ("Age1" +i); Cell= Row.createcell (2); Cell.setcellvalue ("Sex2" +i); Row= Sheet2.createrow (i+1); Cell= Row.createcell (0); Cell.setcellvalue ("Name1" +i); Cell= Row.createcell (1); Cell.setcellvalue ("Age2" +i); Cell= Row.createcell (2); Cell.setcellvalue ("Sex3" +i); Row= Sheet3.createrow (i+1); Cell= Row.createcell (0); Cell.setcellvalue ("Name" +i); Cell= Row.createcell (1); Cell.setcellvalue ("Age" +i); Cell= Row.createcell (2); Cell.setcellvalue ("Sex" +i); } //false means no append, overriding every timeFileOutputStream fileout =NewFileOutputStream (Path,false); Wb.write (fileout); }}
Maven Joins POI dependency
<Dependency> <groupId>Org.apache.poi</groupId> <Artifactid>Poi</Artifactid> <version>3.14</version> </Dependency>
Apache POI generates Excel