@stu51 你好,想跟你请教个问题:
public class PoiRender extends Render{ private static Logger log = LoggerFactory.getLogger(ExcelUtils.class); private final static String CONTENT_TYPE = "application/msexcel;charset=" + getEncoding(); private List<Record> data; private String[] headers; private String[] columns; private String fileName; private String version; private int headerRow; private int cellWidth; public PoiRender(List<Record> data) { this.data = data; } public static PoiRender me(List<Record> data) { return new PoiRender(data); } @Override public void render() { response.reset(); response.setHeader("Content-disposition", "attachment; filename=" + fileName); response.setContentType(CONTENT_TYPE); OutputStream os = null; try { os = response.getOutputStream(); PoiExporter poi = PoiExporter.data(data); poi.version(version).sheetNames("sheet").headerRow(headerRow) .headers(headers).columns(columns) .cellWidth(cellWidth); Workbook wb = poi.export(); wb.write(os); } catch (Exception e) { throw new RenderException(e); } finally { try { if (os != null) { os.flush(); os.close(); } } catch (IOException e) { log.error(e.getMessage(), e); } } } public PoiRender headers(String[] headers){ this.headers = headers; return this; } public PoiRender columns(String[] columns){ this.columns = columns; return this; } public PoiRender fileName(String fileName) { this.fileName = fileName; return this; } public PoiRender version(String version) { this.version = version; return this; } public PoiRender headerRow(int headerRow) { this.headerRow = headerRow; return this; } public PoiRender cellWidth(int cellWidth) { this.cellWidth = cellWidth; return this; } }
PoiRender.me(list).headers(headerName).columns(headerKey).fileName(fileName + ".xls");
在控制器中这样弄:
RenderpoiRender=PoiRender.me(list).headers(headerName).columns(headerKey).fileName(fileName+".xls");render(poiRender);版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。