วันพุธที่ 23 กรกฎาคม พ.ศ. 2557

POI org.apache.poi.hssf.usermodel HSSFWorkbook getNumberOfSheets()

POI org.apache.poi.hssf.usermodel HSSFWorkbook getNumberOfSheets()

Description Of HSSFWorkbook: getNumberOfSheets()

The java.lang.HSSFWorkbook.getNumberOfSheets() get the number of spreadsheets in the workbook (this will be three after serialization)

HSSFWorkbook.getNumberOfSheets() method returns number of sheet

Code Example Java HSSFWorkbook


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiExam {
 public static void main(String[] args) {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet1 = workbook.createSheet("sheetname 1");
  HSSFSheet sheet2 = workbook.createSheet("sheetname 2");
  
  System.out.println("number of Sheet : " + workbook.getNumberOfSheets());
  
  FileOutputStream fos = null;
  try {
   fos = new FileOutputStream(new File("PoiExam.xls"));
   workbook.write(fos);
   System.out.println("SUCCESS" + workbook.getNumberOfSheets());
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   if (fos != null) {
    try {
     fos.flush();
     fos.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }
}


yengo หรือ buzzcity

ไม่มีความคิดเห็น :

แสดงความคิดเห็น