update
This commit is contained in:
43
autopoi/autopoi-web/pom.xml
Normal file
43
autopoi/autopoi-web/pom.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.jeecgframework.boot3</groupId>
|
||||
<artifactId>autopoi-parent</artifactId>
|
||||
<version>3.7.0</version>
|
||||
</parent>
|
||||
<artifactId>autopoi-web</artifactId>
|
||||
<dependencies>
|
||||
<!-- autopoi -->
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework.boot3</groupId>
|
||||
<artifactId>autopoi</artifactId>
|
||||
<version>${autopoi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--spring -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- servlet -->
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<version>6.0.0</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-to-slf4j</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<optional>true</optional>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright 2013-2015 JEECG (jeecgos@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jeecgframework.poi.excel.def;
|
||||
|
||||
/**
|
||||
* 基础POI常量
|
||||
*
|
||||
* @author JEECG
|
||||
* @date 2014年6月30日 下午9:23:37
|
||||
*/
|
||||
interface BasePOIConstants {
|
||||
|
||||
/**
|
||||
* 注解对象
|
||||
*/
|
||||
public final static String CLASS = "entity";
|
||||
/**
|
||||
* 表格参数
|
||||
*/
|
||||
public final static String PARAMS = "params";
|
||||
/**
|
||||
* 下载文件名称
|
||||
*/
|
||||
public final static String FILE_NAME = "fileName";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2013-2015 JEECG (jeecgos@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jeecgframework.poi.excel.def;
|
||||
|
||||
/**
|
||||
* 正常导出Excel
|
||||
*
|
||||
* @Author JEECG on 14-3-8. 静态常量
|
||||
*/
|
||||
public interface MapExcelConstants extends BasePOIConstants {
|
||||
/**
|
||||
* 单Sheet导出
|
||||
*/
|
||||
public final static String JEECG_MAP_EXCEL_VIEW = "jeecgMapExcelView";
|
||||
/**
|
||||
* Entity List
|
||||
*/
|
||||
public final static String ENTITY_LIST = "data";
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public final static String MAP_LIST = "mapList";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright 2013-2015 JEECG (jeecgos@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jeecgframework.poi.excel.def;
|
||||
|
||||
/**
|
||||
* 正常导出Excel
|
||||
*
|
||||
* @Author JEECG on 14-3-8. 静态常量
|
||||
*/
|
||||
public interface NormalExcelConstants extends BasePOIConstants {
|
||||
/**
|
||||
* 单Sheet导出
|
||||
*/
|
||||
public final static String JEECG_ENTITY_EXCEL_VIEW = "jeecgEntityExcelView";
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public final static String DATA_LIST = "data";
|
||||
|
||||
/**
|
||||
* 多Sheet 对象
|
||||
*/
|
||||
public final static String MAP_LIST = "mapList";
|
||||
|
||||
/**
|
||||
* 导出字段自定义
|
||||
*/
|
||||
public final static String EXPORT_FIELDS = "exportFields";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright 2013-2015 JEECG (jeecgos@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jeecgframework.poi.excel.def;
|
||||
|
||||
/**
|
||||
* 模板Excel导出常量
|
||||
*
|
||||
* @author JEECG
|
||||
* @date 2014年6月30日 下午9:26:52
|
||||
*/
|
||||
public interface TemplateExcelConstants extends BasePOIConstants {
|
||||
/**
|
||||
* 模板导出
|
||||
*/
|
||||
public final static String JEECG_TEMPLATE_EXCEL_VIEW = "jeecgTemplateExcelView";
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public final static String LIST_DATA = "list";
|
||||
/**
|
||||
* 模板参数
|
||||
*/
|
||||
public final static String MAP_DATA = "map";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright 2013-2015 JEECG (jeecgos@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jeecgframework.poi.excel.def;
|
||||
|
||||
/**
|
||||
* Word 导出模板常量
|
||||
*
|
||||
* @author JEECG
|
||||
* @date 2014年7月24日 下午11:26:46
|
||||
*/
|
||||
public interface TemplateWordConstants extends BasePOIConstants {
|
||||
/**
|
||||
* 模板导出
|
||||
*/
|
||||
public final static String JEECG_TEMPLATE_WORD_VIEW = "jeecgTemplateWordView";
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public final static String URL = "url";
|
||||
/**
|
||||
* 模板参数
|
||||
*/
|
||||
public final static String MAP_DATA = "map";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright 2013-2015 JEECG (jeecgos@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jeecgframework.poi.excel.view;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.export.ExcelExportServer;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* Entity 实体数据对象导出
|
||||
* @Author JEECG
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Controller(NormalExcelConstants.JEECG_ENTITY_EXCEL_VIEW)
|
||||
public class JeecgEntityExcelView extends MiniAbstractExcelView {
|
||||
|
||||
public JeecgEntityExcelView() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
String codedFileName = "临时文件";
|
||||
Workbook workbook = null;
|
||||
//---update-end-----autor:scott------date:20191016-------for:导出字段支持自定义--------
|
||||
String[] exportFields = null;
|
||||
|
||||
Object exportFieldStr = model.get(NormalExcelConstants.EXPORT_FIELDS);
|
||||
if(exportFieldStr!=null && exportFieldStr!=""){
|
||||
exportFields = exportFieldStr.toString().split(",");
|
||||
}
|
||||
//---update-end-----autor:scott------date:20191016-------for:导出字段支持自定义--------
|
||||
if (model.containsKey(NormalExcelConstants.MAP_LIST)) {
|
||||
List<Map<String, Object>> list = (List<Map<String, Object>>) model.get(NormalExcelConstants.MAP_LIST);
|
||||
if (list.size() == 0) {
|
||||
throw new RuntimeException("MAP_LIST IS NULL");
|
||||
}
|
||||
workbook = ExcelExportUtil.exportExcel((ExportParams) list.get(0).get(NormalExcelConstants.PARAMS), (Class<?>) list.get(0).get(NormalExcelConstants.CLASS), (Collection<?>) list.get(0).get(NormalExcelConstants.DATA_LIST),exportFields);
|
||||
for (int i = 1; i < list.size(); i++) {
|
||||
new ExcelExportServer().createSheet(workbook, (ExportParams) list.get(i).get(NormalExcelConstants.PARAMS), (Class<?>) list.get(i).get(NormalExcelConstants.CLASS), (Collection<?>) list.get(i).get(NormalExcelConstants.DATA_LIST),exportFields);
|
||||
}
|
||||
} else {
|
||||
workbook = ExcelExportUtil.exportExcel((ExportParams) model.get(NormalExcelConstants.PARAMS), (Class<?>) model.get(NormalExcelConstants.CLASS), (Collection<?>) model.get(NormalExcelConstants.DATA_LIST),exportFields);
|
||||
}
|
||||
if (model.containsKey(NormalExcelConstants.FILE_NAME)) {
|
||||
codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME);
|
||||
}
|
||||
if (workbook instanceof HSSFWorkbook) {
|
||||
codedFileName += HSSF;
|
||||
} else {
|
||||
codedFileName += XSSF;
|
||||
}
|
||||
if (isIE(request)) {
|
||||
codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
|
||||
} else {
|
||||
codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
|
||||
}
|
||||
response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
workbook.write(out);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Copyright 2013-2015 JEECG (jeecgos@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jeecgframework.poi.excel.view;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.def.MapExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* Map 数据对象接口导出
|
||||
*
|
||||
* @author JEECG
|
||||
* @date 2014年11月25日 下午3:26:32
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Controller(MapExcelConstants.JEECG_MAP_EXCEL_VIEW)
|
||||
public class JeecgMapExcelView extends MiniAbstractExcelView {
|
||||
|
||||
public JeecgMapExcelView() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
String codedFileName = "临时文件";
|
||||
Workbook workbook = ExcelExportUtil.exportExcel((ExportParams) model.get(MapExcelConstants.PARAMS), (List<ExcelExportEntity>) model.get(MapExcelConstants.ENTITY_LIST), (Collection<? extends Map<?, ?>>) model.get(MapExcelConstants.MAP_LIST));
|
||||
if (model.containsKey(MapExcelConstants.FILE_NAME)) {
|
||||
codedFileName = (String) model.get(MapExcelConstants.FILE_NAME);
|
||||
}
|
||||
if (workbook instanceof HSSFWorkbook) {
|
||||
codedFileName += HSSF;
|
||||
} else {
|
||||
codedFileName += XSSF;
|
||||
}
|
||||
if (isIE(request)) {
|
||||
codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
|
||||
} else {
|
||||
codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
|
||||
}
|
||||
response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
workbook.write(out);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright 2013-2015 JEECG (jeecgos@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jeecgframework.poi.excel.view;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.def.TemplateExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* Excel 模板导出
|
||||
*
|
||||
* @author JEECG
|
||||
* @date 2014年6月30日 下午9:15:49
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Controller(TemplateExcelConstants.JEECG_TEMPLATE_EXCEL_VIEW)
|
||||
public class JeecgTemplateExcelView extends MiniAbstractExcelView {
|
||||
|
||||
public JeecgTemplateExcelView() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
String codedFileName = "临时文件";
|
||||
Workbook workbook = ExcelExportUtil.exportExcel((TemplateExportParams) model.get(TemplateExcelConstants.PARAMS), (Class<?>) model.get(TemplateExcelConstants.CLASS), (List<?>) model.get(TemplateExcelConstants.LIST_DATA), (Map<String, Object>) model.get(TemplateExcelConstants.MAP_DATA));
|
||||
if (model.containsKey(NormalExcelConstants.FILE_NAME)) {
|
||||
codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME);
|
||||
}
|
||||
if (workbook instanceof HSSFWorkbook) {
|
||||
codedFileName += HSSF;
|
||||
} else {
|
||||
codedFileName += XSSF;
|
||||
}
|
||||
if (isIE(request)) {
|
||||
codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
|
||||
} else {
|
||||
codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
|
||||
}
|
||||
response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
workbook.write(out);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright 2013-2015 JEECG (jeecgos@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jeecgframework.poi.excel.view;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.jeecgframework.poi.excel.def.TemplateWordConstants;
|
||||
import org.jeecgframework.poi.word.WordExportUtil;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
|
||||
/**
|
||||
* Word模板导出
|
||||
*
|
||||
* @author JEECG
|
||||
* @date 2014年6月30日 下午9:15:49
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Controller(TemplateWordConstants.JEECG_TEMPLATE_WORD_VIEW)
|
||||
public class JeecgTemplateWordView extends AbstractView {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/msword";
|
||||
|
||||
public JeecgTemplateWordView() {
|
||||
setContentType(CONTENT_TYPE);
|
||||
}
|
||||
|
||||
public boolean isIE(HttpServletRequest request) {
|
||||
return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 || request.getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0) ? true : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
String codedFileName = "临时文件.docx";
|
||||
if (model.containsKey(TemplateWordConstants.FILE_NAME)) {
|
||||
codedFileName = (String) model.get(TemplateWordConstants.FILE_NAME) + ".docx";
|
||||
}
|
||||
if (isIE(request)) {
|
||||
codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
|
||||
} else {
|
||||
codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
|
||||
}
|
||||
response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
|
||||
XWPFDocument document = WordExportUtil.exportWord07((String) model.get(TemplateWordConstants.URL), (Map<String, Object>) model.get(TemplateWordConstants.MAP_DATA));
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
document.write(out);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright 2013-2015 JEECG (jeecgos@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jeecgframework.poi.excel.view;
|
||||
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
|
||||
/**
|
||||
* 基础抽象Excel View
|
||||
*
|
||||
* @author JEECG
|
||||
* @date 2015年2月28日 下午1:41:05
|
||||
*/
|
||||
public abstract class MiniAbstractExcelView extends AbstractView {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/vnd.ms-excel";
|
||||
|
||||
protected static final String HSSF = ".xls";
|
||||
protected static final String XSSF = ".xlsx";
|
||||
|
||||
public MiniAbstractExcelView() {
|
||||
setContentType(CONTENT_TYPE);
|
||||
}
|
||||
|
||||
protected boolean isIE(HttpServletRequest request) {
|
||||
return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 || request.getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0) ? true : false;
|
||||
}
|
||||
|
||||
}
|
||||
80
autopoi/autopoi-web/src/test/java/DaoChuBigDataTest.java
Normal file
80
autopoi/autopoi-web/src/test/java/DaoChuBigDataTest.java
Normal file
@@ -0,0 +1,80 @@
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.handler.inter.IExcelExportServer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 大数据导出示例
|
||||
* @author: liusq
|
||||
* @date: 2022年1月4日
|
||||
*/
|
||||
public class DaoChuBigDataTest {
|
||||
/**
|
||||
* 导出测试方法
|
||||
* 参考:http://doc.wupaas.com/docs/easypoi/easypoi-1c10lbsojh62f
|
||||
* 参考:https://blog.csdn.net/weixin_45214729/article/details/118552415
|
||||
* @author liusq
|
||||
* @date: 2022年1月4日
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void bigDataExport() throws Exception {
|
||||
Workbook workbook = null;
|
||||
List<TestEntity> aList = new ArrayList<TestEntity>();
|
||||
ExportParams exportParams = new ExportParams();
|
||||
Date start = new Date();
|
||||
//模拟100w数据
|
||||
for(int j=0;j<1000000;j++){
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setName("李四"+j);
|
||||
testEntity.setAge(j);
|
||||
aList.add(testEntity);
|
||||
}
|
||||
//分别是 totalPage是总页数,pageSize 页码长度
|
||||
int totalPage = (aList.size() / 100000) + 1;
|
||||
int pageSize = 100000;
|
||||
/**
|
||||
* params:(表格标题属性)筛选条件,sheet值
|
||||
* TestEntity:表格的实体类
|
||||
*/
|
||||
workbook = ExcelExportUtil.exportBigExcel(exportParams,TestEntity.class, new IExcelExportServer() {
|
||||
/**
|
||||
* obj 就是下面的totalPage,限制条件
|
||||
* page 是页数,他是在分页进行文件转换,page每次+1
|
||||
*/
|
||||
@Override
|
||||
public List<Object> selectListForExcelExport(Object obj, int page) {
|
||||
//很重要!!这里面整个方法体,其实就是将所有的数据aList分批返回处理
|
||||
//分批的方式很多,我直接用了subList。然后 每批不能太大。我试了30000一批,
|
||||
//特别注意,最好每次10000条,否则,可能有内存溢出风险
|
||||
if (page > totalPage) {
|
||||
return null;
|
||||
}
|
||||
// fromIndex开始索引,toIndex结束索引
|
||||
int fromIndex = (page - 1) * pageSize;
|
||||
int toIndex = page != totalPage ? fromIndex + pageSize :aList.size();
|
||||
//不是空时:一直循环运行selectListForExcelExport。每次返回1万条数据。
|
||||
List<Object> list = new ArrayList<>();
|
||||
list.addAll(aList.subList(fromIndex, toIndex));
|
||||
return list;
|
||||
}
|
||||
}, totalPage);
|
||||
File savefile = new File("D:/excel/");
|
||||
if (!savefile.exists()) {
|
||||
savefile.mkdirs();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream("D:/excel/ExcelExportBigData.bigDataExport.xlsx");
|
||||
workbook.write(fos);
|
||||
fos.close();
|
||||
System.out.println("耗时(秒):"+((new Date().getTime() - start.getTime())/ 1000));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bigDataExport();
|
||||
}
|
||||
}
|
||||
69
autopoi/autopoi-web/src/test/java/DaoChuSheetTest.java
Normal file
69
autopoi/autopoi-web/src/test/java/DaoChuSheetTest.java
Normal file
@@ -0,0 +1,69 @@
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 参考文档:http://doc.jeecg.com/2044223
|
||||
* @author: scott
|
||||
* @date: 2020年09月16日 11:46
|
||||
*/
|
||||
public class DaoChuSheetTest {
|
||||
private static final String basePath = "G:\\needtodeplay\\autopoi-framework-sy-4.0\\autopoi-web\\src\\test\\resources\\templates\\";
|
||||
|
||||
public static ExportParams getExportParams(String name) {
|
||||
return new ExportParams(name,name,ExcelType.XSSF);
|
||||
}
|
||||
public static Workbook test() {
|
||||
/**
|
||||
* 多个Map
|
||||
* title:对应表格Title
|
||||
* entity:对应表格对应实体
|
||||
* data:Collection 数据
|
||||
*/
|
||||
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
|
||||
for(int i=0;i<3;i++){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("title", getExportParams("测试"+i));//表格Title
|
||||
map.put("entity",TestEntity.class);//表格对应实体
|
||||
List<TestEntity> ls=new ArrayList<TestEntity> ();
|
||||
for(int j=0;j<10;j++){
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setName("张三"+i+j);
|
||||
testEntity.setAge(18+i+j);
|
||||
ls.add(testEntity);
|
||||
}
|
||||
List<Map> ls2=new ArrayList<Map> ();
|
||||
for(int j=0;j<10;j++){
|
||||
Map map1 = new HashMap();
|
||||
map1.put("name","李四"+i+j);
|
||||
map1.put("age",18+i+j);
|
||||
ls2.add(map1);
|
||||
}
|
||||
map.put("data", ls);//ls or ls2
|
||||
listMap.add(map);
|
||||
}
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(listMap, ExcelType.XSSF);
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
Workbook workbook = test();
|
||||
File savefile = new File(basePath);
|
||||
if (!savefile.exists()) {
|
||||
savefile.mkdirs();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(basePath + "testSheet.xlsx");
|
||||
workbook.write(fos);
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
55
autopoi/autopoi-web/src/test/java/DaoChuTest.java
Normal file
55
autopoi/autopoi-web/src/test/java/DaoChuTest.java
Normal file
@@ -0,0 +1,55 @@
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: scott
|
||||
* @date: 2020年09月16日 11:46
|
||||
*/
|
||||
public class DaoChuTest {
|
||||
private static final String basePath = "G:\\needtodeplay\\autopoi-framework-sy-4.0\\autopoi-web\\src\\test\\resources\\templates\\";
|
||||
|
||||
public static TemplateExportParams getTemplateParams(String name) {
|
||||
return new TemplateExportParams(basePath + name + ".xlsx");
|
||||
}
|
||||
|
||||
public static Workbook test(String name) {
|
||||
TemplateExportParams params = getTemplateParams(name);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Map<String, Object> lm = new HashMap<String, Object>();
|
||||
lm.put("name", "姓名1" + i);
|
||||
lm.put("isTts", i);
|
||||
lm.put("sname", "s姓名");
|
||||
lm.put("ttsContent", "ttsContent内容");
|
||||
lm.put("rate", 1000 + i);
|
||||
listMap.add(lm);
|
||||
}
|
||||
map.put("autoList", listMap);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
String temName = "test";
|
||||
String temNameNextM = "testNextMarge";
|
||||
Workbook workbook = test(temNameNextM);
|
||||
File savefile = new File(basePath);
|
||||
if (!savefile.exists()) {
|
||||
savefile.mkdirs();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(basePath + "testNew.xlsx");
|
||||
workbook.write(fos);
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
57
autopoi/autopoi-web/src/test/java/DaoChuWordTest.java
Normal file
57
autopoi/autopoi-web/src/test/java/DaoChuWordTest.java
Normal file
@@ -0,0 +1,57 @@
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.jeecgframework.poi.word.WordExportUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: scott
|
||||
* @date: 2020年09月16日 11:46
|
||||
*/
|
||||
public class DaoChuWordTest {
|
||||
private static final String basePath = "G:\\needtodeplay\\autopoi-framework-sy-4.0\\autopoi-web\\src\\test\\resources\\templates\\";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String curTime = format.format(new Date());
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
|
||||
// Map<String, Object> map1 = new HashMap<String, Object>();
|
||||
// map1.put("type", "个人所得税");
|
||||
// map1.put("presum", "1580");
|
||||
// map1.put("thissum", "1750");
|
||||
// map1.put("curmonth", "1-11月");
|
||||
// map1.put("now", curTime);
|
||||
// mapList.add(map1);
|
||||
// Map<String, Object> map2 = new HashMap<String, Object>();
|
||||
// map2.put("type", "增值税");
|
||||
// map2.put("presum", "1080");
|
||||
// map2.put("thissum", "1650");
|
||||
// map2.put("curmonth", "1-11月");
|
||||
// map2.put("now", curTime);
|
||||
// mapList.add(map2);
|
||||
map.put("taxlist", mapList);
|
||||
map.put("totalpreyear", "2660");
|
||||
map.put("totalthisyear", "3400");
|
||||
|
||||
map.put("type", "增值税");
|
||||
map.put("presum", "1080");
|
||||
map.put("thissum", "1650");
|
||||
map.put("curmonth", "1-11月");
|
||||
map.put("now", curTime);
|
||||
|
||||
//单列
|
||||
XWPFDocument document = WordExportUtil.exportWord07(basePath + "纳税信息.docx", map);
|
||||
File savefile = new File("D:\\poi");
|
||||
if (!savefile.exists()) {
|
||||
savefile.mkdirs();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(basePath + "纳税信息new.docx");
|
||||
document.write(fos);
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
29
autopoi/autopoi-web/src/test/java/TestEntity.java
Normal file
29
autopoi/autopoi-web/src/test/java/TestEntity.java
Normal file
@@ -0,0 +1,29 @@
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: lsq
|
||||
* @date: 2021年02月02日 16:31
|
||||
*/
|
||||
public class TestEntity {
|
||||
@Excel(name = "姓名", width = 15)
|
||||
private String name;
|
||||
@Excel(name = "年龄", width = 15)
|
||||
private Integer age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
BIN
autopoi/autopoi-web/src/test/resources/templates/test.xlsx
Normal file
BIN
autopoi/autopoi-web/src/test/resources/templates/test.xlsx
Normal file
Binary file not shown.
Binary file not shown.
BIN
autopoi/autopoi-web/src/test/resources/templates/纳税信息.docx
Normal file
BIN
autopoi/autopoi-web/src/test/resources/templates/纳税信息.docx
Normal file
Binary file not shown.
Reference in New Issue
Block a user