1. import java.io.FileNotFoundException;  
  2. import java.io.FileOutputStream;  
  3. import java.io.IOException;  
  4.  
  5. import org.apache.poi.hssf.usermodel.HSSFCell;  
  6. import org.apache.poi.hssf.usermodel.HSSFRow;  
  7. import org.apache.poi.hssf.usermodel.HSSFSheet;  
  8. import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
  9.  
  10.  
  11.  
  12. public class WriteExcel {  
  13.      public static void main(String[] args) {   
  14.         FileOutputStream fos;  
  15.         try {  
  16.             fos = new FileOutputStream("d:\\test.xls");//文件要写的路径,如存在则覆盖,不存在则创建  
  17.             HSSFWorkbook wb = new HSSFWorkbook();   
  18.             HSSFSheet s = wb.createSheet();   
  19.             wb.setSheetName(0"first sheet");   
  20.             for(int i=0;i<8;i++){  
  21.                 HSSFRow row = s.createRow(i);  
  22.                 for(int j=0;j<8;j++){  
  23.                     HSSFCell cell = row.createCell(j);  
  24.                       
  25.                     cell.setCellValue(i+","+j);   
  26.                 }  
  27.                   
  28.             }  
  29.  
  30.             wb.write(fos);   
  31.             fos.close();   
  32.         } catch (FileNotFoundException e) {  
  33.             e.printStackTrace();  
  34.         } catch (IOException e) {  
  35.             e.printStackTrace();  
  36.         }   
  37.           
  38.       
  39.      }  
  40.  
  41. }