Read File Excel

125 Views Asked by At

I read a big file excel with 70,000 rows and 10 columns with JAVA. I use Apache POI to read and get the data but it takes much time like 1 hour. I changed to using fast-excel to read the file but just can read 2,000 row.

Can someone suggest to me how to tunning the Apache poi? Or maybe have other solutions?

2

There are 2 best solutions below

1
On BEST ANSWER

org.ttzero:eec:0.5.12 supports reading millions of rows of Excel github links, Unfortunately, only Chinese documents are available

try (ExcelReader reader = ExcelReader.read(Paths.get("./abc.xlsx"))) {
    // Print
    reader.sheet(0).rows().forEach(System.out::println);

    // Convert to Java Bean
    List<Item> list =  reader.sheet(0)
        .header(1)  // <- Specify the title line number
        .rows()
        .map(row -> row.to(Item.class)) // <- Convert to Java Bean
        .collect(Collectors.toList());
}
0
On

As @shmosel mentioned I too feel that your issue is in the file reader. Check if the below code works faster than what you have now.

Try the below code :

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.IOException;

public class ExcelReader {
    public static void main(String[] args) {
        try (FileInputStream file = new FileInputStream("path/to/your/excel/file.xlsx")) {
            
            Workbook workbook = new XSSFWorkbook(file);

            
            Sheet sheet = workbook.getSheetAt(0);

            
            for (Row row : sheet) {
                // Iterate over cells
                for (Cell cell : row) {
                    
                    System.out.print(cell.toString() + "\t");
                }
                
                System.out.println();
            }

            
            workbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}