我被告知在此代码中使用hashmap以允许上传XLSX文件并能够在网站上阅读。我在XLSX上输入的数据也必须在网站上捕获。至于现在,有一个零异常错误 这就是我的代码现在的样子。
OPCPackage pkg = null;
XSSFWorkbook workbook = null;
XSSFSheet sheet = null;
try {
pkg = OPCPackage.open("C:\\Users\\....Load_AcctCntr_Template.xlsx");
System.out.println(_LOC + "1.0 " + " pkg:" + pkg);
workbook = new XSSFWorkbook(pkg);
System.out.println(_LOC + "1.0 " + " workbook:" + workbook);
sheet = workbook.getSheetAt(Sheetindex);
System.out.println(_LOC + "1.0 " + " sheet:" + sheet);
pkg.close();
} catch (Exception e) {
System.out.println(_LOC + "1.0 " + " Test:");
return _m;
}
System.out.println(_LOC + "1.0 " + " sheet.getRow(0):" + sheet.getRow(0));
int _totalc = sheet.getRow(0).getLastCellNum();
int _totalr = sheet.getLastRowNum();
// Header r=0
String[] st = new String[_totalc];
for (int c = 0; c < _totalc; c++) {
st[c] = sheet.getRow(0).getCell(0).getStringCellValue();
}
_m.put("HEADER", st);
System.out.println(_LOC + "1.0 " + " _m:" + _m);
// Data r=1 thereafter
List list = new ArrayList();
for (int r = 1; r < _totalr; r++) {
Object[] o = new Object[_totalc];
String strRow = null;
for (int c = 0; c < _totalc; c++) {
o[c] = sheet.getRow(r).getCell(c);
String cn = o[c].getClass().getName();
String strCell = null;
if (!isEmptyNull(strCell)) {
strRow = "record_available";
}
}
if ((o != null) && (o.length != 0)) {
list.add(o);
}
}
_m.put("DATA", list);
System.out.println(_LOC + "1.0 " + " _m:" + _m);
return _m;
}
return _m;
}
我的控制台上显示了什么:
SystemOut O [RedirectLogin: requiredRights]1.0/BelsizeWeb/faces/module/entity/en1102.xhtml
SystemOut O [RedirectLogin: requiredRights]1.0en1102.xhtml
SystemOut O [En1102: doEn1102_command_readfileAction]1.0
SystemOut O [PageCodeBase: getConstructJXLList]1.0 pkg:org.apache.poi.openxml4j.opc.ZipPackage@a6742ad
SystemOut O [PageCodeBase: getConstructJXLList]1.0 workbook:Name: /xl/workbook.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml
SystemOut O [PageCodeBase: getConstructJXLList]1.0 sheet:Name: /xl/worksheets/sheet1.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml
SystemOut O [PageCodeBase: getConstructJXLList]1.0 sheet.getRow(0):<xml-fragment r="1" spans="1:7" x14ac:dyDescent="0.25" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:main="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
Caused by: java.lang.NullPointerException
at pagecode.PageCodeBase.getConstructJXLList_xlsx(PageCodeBase.java:6527)
at pagecode.module.entity.En1102.doEn1102_command_readfileAction(En1102.java:166)