java导入excel时,文件超过100k就会报错,几十k就没有问题,两个excel里的数据是一样的。
HSSFSheetsheet=newHSSFWorkbook(fis).getSheet(sheetNameMapping.get(key));这句代码出错其中key就是...
HSSFSheet sheet = new HSSFWorkbook(fis).getSheet(sheetNameMapping.get(key));
这句代码出错 其中key就是0 从excel读第一个sheet的。
Caused by: java.lang.ArrayIndexOutOfBoundsException: -32751
at org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry.getFunctionByIndexInternal(FunctionMetadataRegistry.java:61)
at org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry.getFunctionByIndex(FunctionMetadataRegistry.java:57)
at org.apache.poi.hssf.record.formula.FuncVarPtg.<init>(FuncVarPtg.java:39)
at org.apache.poi.hssf.record.formula.Ptg.createClassifiedPtg(Ptg.java:105)
at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:85)
at org.apache.poi.hssf.record.formula.Ptg.readTokens(Ptg.java:54)
at org.apache.poi.hssf.record.FormulaRecord.<init>(FormulaRecord.java:202)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
... 9 more 展开
这句代码出错 其中key就是0 从excel读第一个sheet的。
Caused by: java.lang.ArrayIndexOutOfBoundsException: -32751
at org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry.getFunctionByIndexInternal(FunctionMetadataRegistry.java:61)
at org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry.getFunctionByIndex(FunctionMetadataRegistry.java:57)
at org.apache.poi.hssf.record.formula.FuncVarPtg.<init>(FuncVarPtg.java:39)
at org.apache.poi.hssf.record.formula.Ptg.createClassifiedPtg(Ptg.java:105)
at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:85)
at org.apache.poi.hssf.record.formula.Ptg.readTokens(Ptg.java:54)
at org.apache.poi.hssf.record.FormulaRecord.<init>(FormulaRecord.java:202)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
... 9 more 展开
3个回答
展开全部
将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();
}
}
}
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();
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Caused by: java.lang.ArrayIndexOutOfBoundsException: -32751
更多追问追答
追问
Exception in thread "Timer-0" org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance
atcom.mochasoft.jsmcc.meeting.task.importmember.MeetingMemberImportModelValidator.validate(MeetingMemberImportModelValidator.java:29)
at com.mochasoft.jsmcc.meeting.task.importmember.MeetingMemberImportTask.run(MeetingMemberImportTask.java:43)
追答
不建议的话,把代码贴下吧 !实在是无法分析。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |