[JAVA_Apache]POI套件的使用_產出EXCEL文件_產出EXCEL方法(Workbook)
public static void training1() throws IOException { FileOutputStream fileOut = null ; try { //這裡只是純產出excel檔案而以 //產出Excel 97(XLS)文件格式 Workbook hssfwb = new HSSFWorkbook(); fileOut = new FileOutputStream("workbook.xls"); hssfwb.write(fileOut); fileOut.close(); //Excel 2007的(XLSX)文件格式 Workbook xssfwb = new XSSFWorkbook(); fileOut = new FileOutputStream("workbook.xlsx"); xssfwb.write(fileOut); fileOut.close(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { if (null != fileOut) { fileOut.close(); } } }
public static void training2() throws IOException { // 讀取一個原有的excel檔案 FileInputStream fileInputStream = null; Workbook hssfWorkbook = null; try { fileInputStream = new FileInputStream(new File("D:/training1.xls")); if (null != fileInputStream) { try { hssfWorkbook = new HSSFWorkbook(fileInputStream); } catch (IOException e) { e.printStackTrace(); } } } catch (IOException ioe) { ioe.printStackTrace(); throw ioe; } finally { if (null != fileInputStream) { fileInputStream.close(); } } //將剛讀取的excel檔案,產出為另一個excel檔案。 FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(new File("D:/trainingto.xls")); hssfWorkbook.write(fileOutputStream); fileOutputStream.flush(); } catch (IOException ioe) { ioe.printStackTrace(); throw ioe; } finally { if (null != fileOutputStream) { fileOutputStream.close(); } } }
其它文章
- 首頁
- JAVA 目錄
- JAVA WEB 目錄
- JAVA 其他未分類 目錄
- Grails目錄
- jQuery 目錄
- Apache 目錄
- JavaScript 目錄
- Spring + Hibernate 目錄
- Hibernate 目錄
- Linux 目錄
- 程式開發工具目錄
- MySQL 目錄
- PHP目錄
- C/C++ 目錄
- Google App Engine 目錄
- HTML5/CSS3
- 程式開發基本資訊
- Android
- Oracle 目錄
- Struts 目錄
沒有留言:
張貼留言