Download the excel generated by poi

#xls format
// download wb
		String fileNamestr = "filename.xls";
		OutputStream output = null;
		try {
			response.setHeader("Content-disposition","attachment; filename=" + new String(fileNamestr.getBytes("gb2312"), "ISO8859-1" ));
			response.setCharacterEncoding("UTF-8");
			output = response.getOutputStream(); // read file path
			response.setContentType("application/vnd.ms-excel");
			
			wb.write(output);
			output.flush();
		} catch (Exception e) {
			e.printStackTrace ();
		} finally {
			if (null != output) {
				try {
					output.close();
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		}





Attached:
1. Setting the cell background color does not work
CellStyle errStyle = sheet.getWorkbook().createCellStyle();
errStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//Set the foreground fill style
errStyle.setFillForegroundColor(HSSFColor.RED.index);
errStyle.setFillBackgroundColor(HSSFColor.RED.index);

2. The value filled in the cell is set to the text style
CellStyle textCellStyle = wb.createCellStyle(); 
        DataFormat format = wb.createDataFormat(); 
        textCellStyle.setDataFormat(format.getFormat("@ ")); 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326707238&siteId=291194637