我嘗試讀取包含80K細胞的Android XLS文件,但它會出現以下錯誤信息:致命異常:主要 java.lang.OutOfMemoryError如何在android中加載大型xls文件?
我應該怎麼才能成功地讀取xls文件做?
由於提前, Anestis
public class ReadExcelFile
{
ArrayList<String> list = new ArrayList<String>();
public ReadExcelFile()
{
Workbook workbook1 = null;
WorkbookSettings s = null;
InputStream excelContent = null;
try {
excelContent = this.getClass().getResourceAsStream("/com/product/sopho/lexiko.xls");
s = new WorkbookSettings();
s.setUseTemporaryFileDuringWrite(true);
workbook1 = Workbook.getWorkbook(excelContent,s);
Sheet sheet = workbook1.getSheet(0);
ExcelMap(sheet);
ExcelKeyList(sheet);
} catch(Exception e) {
} finally {
if(workbook1 != null) {
workbook1.close();
}
if(excelContent != null) {
try {
excelContent.close();
} catch (IOException ex) {}
}
}
}
private void ExcelKeyList(Sheet sheet)
{
for (int i=0; i<80001; i++)
{
list.add(sheet.getCell(0,i).getContents());
}
}
public ArrayList<String> getExcelKeyList()
{
return list;
}
}
btw。如果OutOfMemory在ExcelKeyList中,那麼你可以使用「pager」來解決它:改變函數,這樣你可以要求1000個單元的塊,而不是一次存儲整個表 – rupps