使用java POI编写一个巨大的数据二维数组以Excel文件

我有一个约16000 X 16000二维数组,我想出口这些logging到Excel文件。 目前我可以在短时间内输出多达1000个X1000的2Darrays。 但是,当我增加大小的数组例如3000 X 3000我的程序运行了很长时间没有返回任何数据。 我要求帮助导出整个二维数组到Excel文件,并使用POI。

我的示例代码来导出数据,其中一个如果参数是我的二维数组。

公共类exportData {

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

}

这里是使用CSVWritter打印2D数组的完整示例

 import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import au.com.bytecode.opencsv.CSVWriter; /** * @author Girish * */ public class CSVWritterExample { public static void main(String[] args) throws FileNotFoundException, IOException { int[][] data = new int[100][100]; for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { data[i][j] = j * i; } } exportDataToExcel("D:/sample.csv", data); } public static void exportDataToExcel(String fileName, int[][] data) throws FileNotFoundException, IOException { File file = new File(fileName); if (!file.isFile()) file.createNewFile(); CSVWriter csvWriter = new CSVWriter(new FileWriter(file)); int rowCount = data.length; for (int i = 0; i < rowCount; i++) { int columnCount = data[i].length; String[] values = new String[columnCount]; for (int j = 0; j < columnCount; j++) { values[j] = data[i][j] + ""; } csvWriter.writeNext(values); } csvWriter.flush(); csvWriter.close(); } } 

正如我看到你的数据是int [] []。 所以我相信它的计划静态数据(没有任何Excelexpression式)

那么,为什么不把你的数据写入一个CSV文件呢? 它是快速的+有限制的行数在POI限制在65,000+logging新表。

你可以使用CSVWritter