spring 读取文件Excel

hfsqlsce  于 2024-01-05  发布在  Spring
关注(0)|答案(2)|浏览(161)

我用JAVA读了一个70,000行10列的大文件excel。我用Apache POI读取和获取数据,但需要1小时左右的时间。我改用fast-excel读取文件,但只能读取2,000行。
有人能建议我如何调整Apache POI吗?或者有其他解决方案?

u59ebvdq

u59ebvdq1#

正如@shmosel提到的,我也觉得你的问题出在文件阅读器上。检查下面的代码是否比你现在的代码运行得更快。
试试下面的代码:

  1. import org.apache.poi.ss.usermodel.*;
  2. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. public class ExcelReader {
  6. public static void main(String[] args) {
  7. try (FileInputStream file = new FileInputStream("path/to/your/excel/file.xlsx")) {
  8. Workbook workbook = new XSSFWorkbook(file);
  9. Sheet sheet = workbook.getSheetAt(0);
  10. for (Row row : sheet) {
  11. // Iterate over cells
  12. for (Cell cell : row) {
  13. System.out.print(cell.toString() + "\t");
  14. }
  15. System.out.println();
  16. }
  17. workbook.close();
  18. } catch (IOException e) {
  19. e.printStackTrace();
  20. }
  21. }
  22. }

字符串

展开查看全部
kcugc4gi

kcugc4gi2#

org.ttzero:eec:0.5.12支持阅读数百万行Excel github links,遗憾的是,只有中文文档可用

  1. try (ExcelReader reader = ExcelReader.read(Paths.get("./abc.xlsx"))) {
  2. // Print
  3. reader.sheet(0).rows().forEach(System.out::println);
  4. // Convert to Java Bean
  5. List<Item> list = reader.sheet(0)
  6. .header(1) // <- Specify the title line number
  7. .rows()
  8. .map(row -> row.to(Item.class)) // <- Convert to Java Bean
  9. .collect(Collectors.toList());
  10. }

字符串

相关问题