我使用Apache-POI java库来读取excel文件,效果很好。我读了每个excel文件大约100个单元格,然后关闭excel文件。
奇怪的是当excel文件有大量数据时,它会成功读取数据,然后进入另一个功能系统会崩溃。
我很感激能解决这个问题。
我正在使用此代码读取excel文件:
public void ExcelReader(String path,int range1, int range2)
{
try
{
// Read from original Excel file.
FileInputStream file = new FileInputStream(path);
Workbook workbook = WorkbookFactory.create(file);
// Get the first sheet.
Sheet sheet = workbook.getSheetAt(0);
int allocated = range2 - range1 +1;
BarcodeList = new int [allocated];
int count = 0;
for(int i=range1-1; i<allocated; i++)
{
Row row = sheet.getRow(i);
Cell cell = row.getCell(0);
double x = Double.parseDouble(cell.toString());
int y = (int) x;
BarcodeList[count] = y;
count++;
}
file.close();
}
catch(NullPointerException e)
{
System.out.println(e);
}
catch(FileNotFoundException e)
{
System.out.println(e);
}
catch(IOException e)
{
System.out.println(e);
}
catch(InvalidFormatException e)
{
System.out.println(e);
}
}