package com.yhg.choose;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
/**
* 读取固定路径下的excel文件
* 存在的问题是:只能读取字符串,不能读取数字类型的,还需要进一步修改
* @author uj
*
*/
public class ReadExcel {
public static void main(String[] args) throws Exception {
File file = new File("C:\\Users\\uj\\Desktop\\模板.xlsx");
InputStream is = new FileInputStream(file);
Workbook wb = WorkbookFactory.create(is);
Sheet sheet = wb.getSheetAt(0);
int lastRowNum = sheet.getLastRowNum();
System.out.println("last number is "+ lastRowNum);
for(int i = 0 ; i <= lastRowNum ; i++){
Row row = null;
row = sheet.getRow(i);
if( row != null ){
System.out.println("reading line is " + i);
int lastCellNum = row.getLastCellNum();
System.out.println("lastCellNum is " + lastCellNum );
Cell cell = null;
for( int j = 0 ; j <= lastCellNum ; j++ ){
cell = row.getCell(j);
if( cell != null ){
String cellValue = cell.getStringCellValue();
System.out.println("cell value is " + cellValue);
}
}
}
}
}
}