
?一、方式2——jxl方式,文件格式为xls格式
1、jar包导入
先复制jxl.jar文件到文件夹,然后右键Build Path-Add to Build Path
2、获取Excel文件
File file=new File("C:\\Users\\My\\Desktop\\student.xls");
Workbook wb=Workbook.getWorkbook(file);
3、获取指定的sheet页,可通过名称,也可以通过索引
wb.getSheet("Sheet1");
4、获取到指定单元格的值,参数是(列,行)
Cell cell=sheet.getCell(1,1);
System.out.pringln(cell.getContents());
4.1 循环获取指定的行和列的单元格的值
for(int i=0;i<sheet.getRows();i++){
for(int j=0;j<sheet.getColums();j++){
Cell cell=sheet.getCell(1,1);
Systerm.ot.pringln(cell.getContents()+"\t");
}}
wb.close();
二、方式3——POI使用



?
?
?
?
?步骤1:导入依赖
?
?步骤2:编码

?普通for循环获取数据也可以,如下:

?
?三、向Excel中写入数据



?四、Excel数据写入数据库
?导入依赖:POI相关包,数据库相关包,


?
?
|