java讀取EXCEL檔案(XLSM)


引用下列的JAR檔




IMPORT下列3項

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.WorkbookFactory;


// 讀取EXCEL資料
String path = "c:\\work\\";
String fileName = "123.xlsm";

InputStream stream = new FileInputStream(path + fileName);

File f = new File(path + fileName);

//把EXCEL檔OPEN起來
org.apache.poi.ss.usermodel.Workbook workbook = WorkbookFactory.create(f);
System.out.println(workbook);

int numberOfSheets = workbook.getNumberOfSheets();
System.out.println(numberOfSheets);
org.apache.poi.ss.usermodel.Sheet sheet = null;
sheet = workbook.getSheet("sheet1");//sheet1sheet1");//sheet1名稱

// 讀取sheet的CELL資料
Row row = sheet.getRow(1);// 數字是從0開始,所以對到實際的數字要減1
Cell cell = row.getCell(4);// 數字是從0開始,所以對到實際的數字要減1
if (cell != null) {
workManID = cell.toString();
}

//完畢時workBook要CLOSE
workbook.close();

留言

這個網誌中的熱門文章

java BigDecimal 加減乘除,四捨五入,四則運算及比較

MS sqlServer資料庫移轉至MySQL-->利用MySQL WorkBench

java 數字轉字串 字串轉數字