1、springboot 解析Excel文件中表格数据
在Spring Boot中解析Excel文件中的表格数据,你可以使用Apache POI库来实现。以下是一个简单的示例代码
2、引入maven依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>4.1.2</version>
</dependency>
3、代码
public class ReadExcelFileTest {
private static void parseexcel() {
List<String> data = new ArrayList<>();
try {
FileInputStream fis = new FileInputStream("../../xxx.xls");
Workbook workbook = WorkbookFactory.create(fis);
Sheet sheet = workbook.getSheetAt(0);
for (Row row : sheet) {
for (Cell cell : row) {
data.add(cell.toString());
}
}
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
parseexcel();
}
}