|
|
@@ -0,0 +1,83 @@
|
|
|
+package com.uas.platform.b2c.core.support.view;
|
|
|
+
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.springframework.web.servlet.view.document.AbstractXlsxView;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 利用jxlsx模板生成excel
|
|
|
+ *
|
|
|
+ * @author yuj
|
|
|
+ *
|
|
|
+ */
|
|
|
+public class JxlsxExcelView extends AbstractXlsxView {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文件名
|
|
|
+ */
|
|
|
+ private String fileName;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入.xls格式文件
|
|
|
+ */
|
|
|
+ private static final String EXTENSION = ".xls";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * .xls 表格
|
|
|
+ */
|
|
|
+ public static final String EXCEL_XLS = "xls";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * .xlsx 表格
|
|
|
+ */
|
|
|
+ public static final String EXCEL_XLSX = "xlsx";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void buildExcelDocument(Map<String, Object> map, Workbook workbook, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
|
|
|
+/* if (model == null)
|
|
|
+ map = new HashMap<String, Object>();
|
|
|
+ map.put("export", new Export());
|
|
|
+ XLSTransformer transformer = new XLSTransformer();
|
|
|
+ transformer.transformWorkbook(workbook, map);
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8") + EXTENSION);*/
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Workbook createWorkbook(Map<String, Object> model, HttpServletRequest request) {
|
|
|
+ Object filePath = model.get("filePath");
|
|
|
+ return super.createWorkbook(model, request);
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+// public JxlsxExcelView(String tplPath, String fileName) {
|
|
|
+// super();
|
|
|
+// setUrl(tplPath);
|
|
|
+// this.fileName = fileName;
|
|
|
+// }
|
|
|
+
|
|
|
+ // @Override
|
|
|
+// protected HSSFWorkbook getTemplateSource(String url, HttpServletRequest request) throws Exception {
|
|
|
+// LocalizedResourceHelper helper = new LocalizedResourceHelper(ContextUtils.getApplicationContext());
|
|
|
+// Locale userLocale = RequestContextUtils.getLocale(request);
|
|
|
+// Resource inputFile = helper.findLocalizedResource(url, EXTENSION, userLocale);
|
|
|
+// if (this.logger.isDebugEnabled()) {
|
|
|
+// this.logger.debug("Loading Excel workbook from " + inputFile);
|
|
|
+// }
|
|
|
+// POIFSFileSystem fs = new POIFSFileSystem(inputFile.getInputStream());
|
|
|
+// return new HSSFWorkbook(fs);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// protected void buildExcelDocument(Map<String, Object> map, HSSFWorkbook workbook, HttpServletRequest request,
|
|
|
+// HttpServletResponse response) throws Exception {
|
|
|
+// if (map == null)
|
|
|
+// map = new HashMap<String, Object>();
|
|
|
+// map.put("export", new Export());
|
|
|
+// XLSTransformer transformer = new XLSTransformer();
|
|
|
+// transformer.transformWorkbook(workbook, map);
|
|
|
+// response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8") + EXTENSION);
|
|
|
+// }
|
|
|
+}
|