Second, the POI write Excel file (in Excel2003 version for example, version 2007 is based on the file extension xlsx will hssfworkbook to Xssfworkbook, and its sheet, Row, cell and corresponding replacement)
1.//Create a work book
Hssfworkbook workbook = new Hssfworkbook ();
2.//Create Sheet page
Hssfsheet sheet = workbook.createsheet ("Sheet1");
3,//Create a row of data
Hssfrow firstrow = sheet.createrow (0);
4.//Create a cell on the first line
Hssfcell Firstrowcell = Firstrow.createcell (0);
5,//For cell assignment
Firstrowcell.setcellvalue ("abc");
6.//Create a File object
String Foldpath is the folder location to which you want to save the Excel file, not the full path to the file, and the Web site directly uses the virtual path to
File fold= new file (FilePath);
7,//Determine whether the folder exists, does not exist on the creation
if (!fold.exists ()) {fold.mkdirs ();}
8,///generally do not need to determine whether the file exists and create, because do not do other processing the new file will be created or overwrite the original file, the following is just a simple record for later use
File File = new file (FilePath, "Excel.xls");
File.createnewfile ();//Make sure the file is created with the folder present
9.//create file output stream
OutputStream outputstream = new FileOutputStream (filepath+ "/excel.xls");
10.//Write Workbook object to file stream
Workbook.write (OutputStream);
11.//Release Resources
Workbook.close ();
Outputstream.close ();
12, again, the above code is best to use try Catch
Write a description of the POI read/write Excel