khssf609
⑴ java导入excel时,文件超过100k就会报错,几十k就没有问题,两个excel里的数据是一样的。
将excel导入到本地,并转换为数组。上传过1M以上的都没报过错。
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
filePath));
HSSFSheet sheet = workbook.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
if (rows > 0) {
int cells = sheet.getRow(0).getPhysicalNumberOfCells();
for (int r =0; r < rows; r++) {
HSSFRow row = sheet.getRow(r);
String[] cellsvalue = new String[cells+1];
for (short c = 0; c < cells; c++) {
String value = "";
HSSFCell cell = row.getCell(c);
if (cell != null) {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_FORMULA:
//
break;
case HSSFCell.CELL_TYPE_NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
value = new java.text.SimpleDateFormat("yyyy-MM-dd").format(cell.getDateCellValue());
Date date = cell.getDateCellValue();
value = (date.getYear() + 1900) + "-" + (date.getMonth() + 1) + "-" + date.getDate();
} else {
value = String.valueOf(cell
.getNumericCellValue());
}
break;
case HSSFCell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_BLANK:
value="";
default:
break;
}
if (cell == null) {
value="";
}
}
cellsvalue[c] = value;
}
s[r] = cellsvalue;
java.io.File myfile = new java.io.File(filePath);
if (myfile.exists()) {
myfile.delete();
}
}
}