POI org.apache.poi.hssf.usermodel HSSFWorkbook getSheetIndex(java.lang.String name)
Description Of HSSFWorkbook: getSheetIndex(java.lang.String name)
The java.lang.HSSFWorkbook.getSheetIndex(java.lang.String name) Returns the index of the sheet by his name
HSSFWorkbook.getSheetIndex(java.lang.String name) method returns number of sheet by name, method return -1 is not found
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");
int sheetindex1 = workbook.getSheetIndex("sheetname 1");
int sheetindex2 = workbook.getSheetIndex("sheetname 3");
System.out.println("sheet1 is index : " + sheetindex1);
System.out.println("sheet1 is index : " + sheetindex2);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File("PoiExam.xls"));
workbook.write(fos);
System.out.println("SUCCESS");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
ไม่มีความคิดเห็น :
แสดงความคิดเห็น