POI的使用
[JAVA_Apache]POI套件的使用_產出EXCEL文件_創建EXCEL裡工作表的方法(Sheet)

產生新的工作表

 
public static void training3() throws IOException {
FileOutputStream fileOut = null;
try {
// 這裡只純產生新的工作表
// 產出Excel 97(XLS)文件格式
Workbook wb = new HSSFWorkbook(); // or new XSSFWorkbook();
Sheet sheet1 = wb.createSheet("new sheet");
Sheet sheet2 = wb.createSheet("second sheet");
   //另外如果是取得原來就有的excel裡的工作表
//方法一 :取得工作表名稱為:工作表1
//wb.getSheet("工作表1");
//方法二 :
//此方法 是要看在excel中的工作表順序
//hssfWorkbook.getSheetAt(0);
fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
finally {
if (null != fileOut) {
fileOut.close();
}
}
}














其它文章

arrow
arrow

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()