用java读取大文件EXCEL方法

时间:2023-12-08 阅读:58 评论:0 作者:yc888

我用JAVA读取了一个70000行10列的大文件excel。 


我使用 Apache POI 来读取和获取数据,但需要花费很多时间,例如 1 小时。


 我改用fast-excel来读取文件,但只能读取2000行。


有人可以建议我如何调整 Apache poi 吗? 或者也许还有其他解决方案?


答:可以试试下面的代码


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();
        }
    }
}



本文链接: https://a.10zhan.com/post/4294.html 转载请注明出处!