我有一个大约 16000 X 16000 的二维数组,我想将这些记录导出到 Excel 文件。目前我可以在短时间内导出最多 1000 X1000 的二维数组。但是当我增加数组的大小(例如 3000 X 3000)时,我的程序运行很长时间而不返回任何数据。 我正在寻求帮助将整个 2D 数组导出到 Excel 文件并使用 POI。
我用于导出数据的示例代码,其中如果参数是我的二维数组,则为 1。
公共(public)类导出数据{
public static void exportDataToExcel(String fileName, String tabName, int[][] data) throws FileNotFoundException, IOException
{
//Create new workbook and tab
Workbook wb = new XSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream(fileName);
Sheet sheet = wb.createSheet(tabName);
//Create 2D Cell Array
Row[] row = new Row[data.length];
Cell[][] cell = new Cell[row.length][];
//Define and Assign Cell Data from Given
for(int i = 0; i < row.length; i ++)
{
row[i] = sheet.createRow(i);
cell[i] = new Cell[data[i].length];
for(int j = 0; j < cell[i].length; j ++)
{
cell[i][j] = row[i].createCell(j);
cell[i][j].setCellValue(data[i][j]);
}
}
//Export Data
wb.write(fileOut);
fileOut.close();
System.out.println("File exported successfully");
}
}
最佳答案
据我所知,您的数据是 int[][]。所以我相信它的计划静态数据(没有任何excel公式)
那么,为什么不将数据写入 CSV 文件呢?它很快+行数有限制,因为 POI 中的新工作表限制为 65,000 多条记录。
您可以使用CSVWritter
关于java - 使用java POI将巨大的数据二维数组写入excel文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24862127/