Home > Back-end >  Poi export Excel error
Poi export Excel error

Time:01-27

After launch, the first export excel to Fail to save: the an error occurs while saving the package: the part/docProps/core XML failed to be saved in the stream with the marshaller org.. Apache poi. Openxml4j. Opc. Internal. Marshallers. ZipPackagePropertiesMarshaller @ 6 da2de6; The second export could actually, don't know if god have know this bug
My source:
@ ResponseBody
@ RequestMapping ("/exportExcel ")
Public void exportExcel (it request, HttpServletResponse response, @ RequestParam Map Map) {
OutputStream OutputStream=null;
Try {
The map. The put (" startDate ", the map. The get (" date "));
List List=firepreventRealdataService. List (map);
//date the export date
String date=((String) map. Get (" date "). The replace (" - ", "");
The response. SetContentType (" application/binary; Charset=ISO8859_1 ");
OutputStream=response. GetOutputStream ();
The String fileName=new String ((date + Constant. FIREPREVENTREALEXCEL). GetBytes (), "ISO8859_1");
The response. SetHeader (" the Content - the disposition ", "legislation; Filename="+ filename +". XLSX ");//assembly name and format attachment
//1. Create a XSSFWorkbook XSSFWorkbook, corresponding to an Excel file
XSSFWorkbook wb=new XSSFWorkbook ();
//2. Add a sheet in the workbook, corresponding sheet in Excel file
XSSFSheet sheet=wb. CreateSheet (date);
//3. Set the header, that is, each column name
String [] titles={" equipment serial number ", "equipment serial number", "electric box state", "real-time temperature", "CO concentration/PPM", "smoke detection", "linkage fire extinguisher status", "record time"};

ExportUtil ExportUtil=new ExportUtil (wb, sheet);
XSSFCellStyle titleStyle=exportUtil. GetTitleStyle ();
XSSFCellStyle mainStyle.=exportUtil getMainStyle ();
CellRangeAddress cellRange=null;


XSSFRow titleRow=sheet. CreateRow (0);
TitleRow. SetHeightInPoints (18.75 f);
XSSFCell tCell.=titleRow createCell (0);
TCell. SetCellStyle (titleStyle);
TCell. SetCellValue (date + Constant. FIREPREVENTREALEXCEL);
CellRange=new CellRangeAddress (0, 0, 0, 7);
Sheet. AddMergedRegion (cellRange);

//build header
XSSFRow headRow=sheet. CreateRow (1);
XSSFCell cell=null;
for (int i=0; I & lt; Titles. Length; I++) {
Cell=headRow. CreateCell (I);
Cell. SetCellStyle (mainStyle);
Cell. SetCellValue (titles [I]);
}

if(list !=null & amp; & List. The size () & gt; 0 {
For (int I=0; I & lt; List. The size (); I++) {
FirepreventDataEntity entity=list. Get (I);
The Integer outfire=entity. GetOutfire ();
XSSFRow bodyRow=sheet. CreateRow (I + 2);

Cell=bodyRow. CreateCell (0);
Cell. SetCellStyle (mainStyle);
Cell. SetCellValue (entity. GetNumber ());

Cell=bodyRow. CreateCell (1);
Cell. SetCellStyle (mainStyle);
Cell. SetCellValue (entity. GetDeviceNo ());

Cell=bodyRow. CreateCell (2);
Cell. SetCellStyle (mainStyle);
Cell. SetCellValue (entity. The getStatus ());

Cell=bodyRow. CreateCell (3);
Cell. SetCellStyle (mainStyle);
Cell. SetCellValue (entity. GetTemperature ());

Cell=bodyRow. CreateCell (4);
Cell. SetCellStyle (mainStyle);
Cell. SetCellValue (entity. As ());

Cell=bodyRow. CreateCell (5);
Cell. SetCellStyle (mainStyle);
Cell. SetCellValue (entity. GetSmoke ()==0?" Smoke-free ":" smoke ");

Cell=bodyRow. CreateCell (6);
Cell. SetCellStyle (mainStyle);
Cell. SetCellValue (outfire==0?" Normal: outfire==1? "" Thermal line starts ": the outfire==2?" Electric start ":" electric start-up failure ");

Cell=bodyRow. CreateCell (7);
Cell. SetCellStyle (mainStyle);
Cell. SetCellValue (DateUtils yyyy_MM_dd (entity. GetRecordTime ()));

}
}
Sheet. SetColumnWidth (7, 20 * 256);
Wb. Write (outputStream);
OutputStream. Flush ();
} the catch (Exception e) {
e.printStackTrace();
Logger. The error (" firepreventRealdataController derived error error==& gt;=={}, parameters & gt; {} ", um participant etMessage (), map);
} the finally {
Try {
outputStream.close();
} the catch (IOException e) {
e.printStackTrace();
}
}
}

CodePudding user response:

Through the debug debugging, it is in the wb. Write (outputStream); This is an error, which a great god knows how to return a responsibility

CodePudding user response:

I just share a poi export Excel, you can see https://blog.csdn.net/Gemini_Kanon/article/details/90762894 hope to help get you

CodePudding user response:

can not see epsilon=(' &western ` *))) ~

CodePudding user response:

POI will create a temporary folder/TMP/poifiles, could it be your application without permission?

CodePudding user response:

To find the reason, is springboot tomcat connection timeout time is too short, cause the HTTP connection timeout, the server connection timeout - the long line

CodePudding user response:

Optimize the export interface of time, I also met, window on Google can export 7000, apple computer export out of the question, apple export hundreds also no problem, thanks to the building

CodePudding user response:

The import import cn. Hutool. Core. *
 @ GetMapping ("/export ") 
Derived @ ApiOperation (value="https://bbs.csdn.net/topics/", httpMethod="GET")
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related