标签:back puts excel pid 文件解析 pen wrap 管理 font
private File file;
public void setFile(File file) {
this.file = file;
}
x
private File file;
public void setFile(File file) {
this.file = file;
}
<!-- Excel解析工具类 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.11</version>
</dependency>
x
<!-- Excel解析工具类 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.11</version>
</dependency>
public void resolveExcel() {
//1.加载excal文件对象
Workbook workbook=null;
try {
workbook = WorkbookFactory.create(new FileInputStream(file));
} catch (Exception e) {
e.printStackTrace();
}
//2.读取第一个sheet
Sheet sheet = workbook.getSheetAt(0);
//3.读取sheet中的每一行
for (Row row : sheet) {
//跳过第一行表头数据(如果有表头就跳过,没有则不用)
if (row.getRowNum()==0) {
continue;
}
//跳过空行
if (row.getCell(0)==null || StringUtils.isBlank(row.getCell(0).getStringCellValue())) {
continue;
}
//分别获取每一列的数据
String areaCode = row.getCell(0).getStringCellValue();
String province = row.getCell(1).getStringCellValue();
String city = row.getCell(2).getStringCellValue();
String area = row.getCell(3).getStringCellValue();
String postcode = row.getCell(4).getStringCellValue();
//接下来要对得到的数据怎么操作,随业务而定了!可以先打印测试一下
}
}
public void resolveExcel() {
//1.加载excal文件对象
Workbook workbook=null;
try {
workbook = WorkbookFactory.create(new FileInputStream(file));
} catch (Exception e) {
e.printStackTrace();
}
//2.读取第一个sheet
Sheet sheet = workbook.getSheetAt(0);
//3.读取sheet中的每一行
for (Row row : sheet) {
//跳过第一行表头数据(如果有表头就跳过,没有则不用)
if (row.getRowNum()==0) {
continue;
}
//跳过空行
if (row.getCell(0)==null || StringUtils.isBlank(row.getCell(0).getStringCellValue())) {
continue;
}
//分别获取每一列的数据
String areaCode = row.getCell(0).getStringCellValue();
String province = row.getCell(1).getStringCellValue();
String city = row.getCell(2).getStringCellValue();
String area = row.getCell(3).getStringCellValue();
String postcode = row.getCell(4).getStringCellValue();
//接下来要对得到的数据怎么操作,随业务而定了!可以先打印测试一下
}
}
标签:back puts excel pid 文件解析 pen wrap 管理 font
原文地址:https://www.cnblogs.com/zhaoxuan734/p/8745826.html