我们的要求是用户将上传xlsx文件,如果有任何错误(数据类型不匹配),我们必须验证文件的每个单元格值的数据类型,然后我们必须使用附加列写入xls作为带有错误详细信息的备注并返回给用户。
因此,我首先阅读xlsx文件并使用Apache POI(Java API)检索第一行的单元格数据类型,然后根据数据类型(从第一行)验证每行和每个单元格对于具有高达20K到30K记录的文件,机制工作正常,但是当我处理具有100K记录的大型xlsx文件时,它无法处理。我有堆空间问题。
我使用Apache POI(Java API)进行迭代,Excel版本为32位。
当搜索任何解决方案时,我正在获得有关如何读取或写入巨大的xls文件的解决方案。但是因为我必须获取单元数据类型,然后更新相同的xlsx,如果有任何错误,我无法得到任何解决方案。
如果有人解决此类问题,请告诉我。
请找到我正在使用的以下代码:
Set set = remarksInfo.entrySet(); //HashMap object
Integer rownumber;
String value;
Iterator iterator = set.iterator();
//Read Excel document first
FileInputStream input_document = new FileInputStream(new File("C:\\simple.xlsx"));
XSSFWorkbook my_xlsx_workbook = new XSSFWorkbook(input_document);
XSSFSheet my_worksheet = my_xlsx_workbook.getSheetAt(0);
while (iterator.hasNext()) {
Map.Entry mentry = (Map.Entry) iterator.next();
rownumber = (Integer) mentry.getKey();
value = (String) mentry.getValue();
Row row = mySheet.getRow(rownumber);
Cell newCell = row.createCell(mySheet.getRow(rownumber).getLastCellNum() - 2);
newCell.setCellValue(value);
newCell.setCellStyle(style);
}
input_document.close();
FileOutputStream output_file =new FileOutputStream(new File("C:\\simple.xlsx"));
my_xlsx_workbook.write(output_file);
//close the stream
output_file.close();
错误:
java.lang.OutOfMemoryError: GC overhead limit exceeded] with root cause
java.lang.OutOfMemoryError: GC overhead limit exceeded
at org.apache.poi.ss.util.CellReference.separateRefParts(CellReference.java:361)
at org.apache.poi.ss.util.CellReference.<init>(CellReference.java:92)
at org.apache.poi.xssf.usermodel.XSSFCell.<init>(XSSFCell.java:106)
at org.apache.poi.xssf.usermodel.XSSFRow.<init>(XSSFRow.java:69)
at org.apache.poi.xssf.usermodel.XSSFSheet.initRows(XSSFSheet.java:234)
at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:197)
at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:184)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:350)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:166)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:259)
at pxs.dgd.gna.fileUpload.FileUploadXls.getXcelSheetinfoMap(FileUploadXls.java:101)
at pxs.dgd.gna.services.GNAServiceImple.getXcelSheetinfoMap(GNAServiceImple.java:225)
at pxs.dgd.gna.controller.FileUploadController.getSheetDetails(FileUploadController.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)