public class TestExcel {
private static String filePath = "";
private static String version = "2003";//默认为2003版本
private static Workbook wb = null;
private static Sheet sheet = null;
static User user = new User();
public static void setVersion(String filePath){
if(filePath.endsWith(".xlsx")){
version = "2007";
}
}
public static Workbook getWorkbook() throws IOException, InvalidFormatException{
BufferedInputStream in = new BufferedInputStream(new FileInputStream(filePath));
if("2003".equals(version)){
POIFSFileSystem fs = new POIFSFileSystem(in);
wb = (Workbook)new HSSFWorkbook(fs);
}else if("2007".equals(version)){
wb = (Workbook)new XSSFWorkbook(in);
}
return wb;
}
public static void print(){
try {
wb = getWorkbook();
int sheets = wb.getNumberOfSheets();//获取sheet的数量
// System.out.println(sheets);
poi 3.10 读取excel(2003/2007)
最新推荐文章于 2022-03-12 18:39:56 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)