我有一个约16000 X 16000的二维数组,我想将这些记录导出到Excel文件。目前我可以在短时间内输出多达1000个X1000的2D阵列。但是,当我增加大小的数组例如3000 X 3000我的程序运行很长时间而不返回任何数据。 我在寻求帮助将整个2D数组导出到excel文件并使用POI。写一个巨大的数据2D数组,以Excel文件使用Java 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");
}
}
你尝试调试找出哪些行的执行被挂起的完整的例子吗?可能是wb.write(fileOut);? – Maas
我没有试图做到这一点,但我正在寻找更好的方式输出我的整个数组的excel文件的任何建议。 –
如果可能,你应该避免POI和这样的库,并直接以CSV格式保存文件。 Excel可以打开这些,转换它们等。 – EJP