12 changed files with 451 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-8914 |
||||
|
||||
JSD-8914 分页分sheet导出 sheet支持公式命名 |
||||
JSD-8914 分页分sheet导出 sheet支持公式命名\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.fr.plugin.xxxx.yyjm.fold</id> |
||||
<main-package>com.fr.plugin.xxxx.yyjm.fold</main-package> |
||||
<name><![CDATA[sheet重命名]]></name> |
||||
<active>yes</active> |
||||
<version>1.0</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[sheet重命名]]></description> |
||||
<change-notes><![CDATA[ |
||||
[2021-11-15]【1.0】初始化插件。<br/> |
||||
]]></change-notes> |
||||
<extra-report> |
||||
<ExcelExportAppProvider class="com.fr.plugin.xxxx.yyjm.fold.RenameSheetExcelExportProvider"/> |
||||
</extra-report> |
||||
<extra-decision> |
||||
<HttpHandlerProvider class="com.fr.plugin.xxxx.yyjm.fold.FoldRequestHandlerBridge"/> |
||||
<URLAliasProvider class="com.fr.plugin.xxxx.yyjm.fold.FoldRequestURLAliasBridge" /> |
||||
</extra-decision> |
||||
<function-recorder class="com.fr.plugin.xxxx.yyjm.fold.RenameSheetExcelExportProvider"/> |
||||
</plugin> |
@ -0,0 +1,10 @@
|
||||
package com.fr.plugin.xxxx.yyjm.fold; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/16 |
||||
* @Description |
||||
**/ |
||||
public class Constants { |
||||
public static final String PLUGIN_ID = "com.fr.plugin.xxxx.yyjm.fold"; |
||||
} |
@ -0,0 +1,79 @@
|
||||
package com.fr.plugin.xxxx.yyjm.fold; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.decision.webservice.Response; |
||||
import com.fr.io.TemplateWorkBookIO; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.main.TemplateWorkBook; |
||||
import com.fr.plugin.xxxx.yyjm.fold.utils.PrintUtils; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.stable.PageActor; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.org.apache.commons.io.FilenameUtils; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.Enumeration; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author f.open |
||||
* @Date 2021/11/16 |
||||
* @Description |
||||
**/ |
||||
public class ExportHandler extends BaseHttpHandler { |
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/export"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
String cptName = req.getParameter("cptName"); |
||||
String sheetName = req.getParameter("sheet_name"); |
||||
String nameFormat = req.getParameter("name_format"); |
||||
FineLoggerFactory.getLogger().info("cptName is {}", cptName); |
||||
FineLoggerFactory.getLogger().info("sheetName is {}", sheetName); |
||||
FineLoggerFactory.getLogger().info("nameFormat is {}", nameFormat); |
||||
if(StringUtils.isBlank(cptName)){ |
||||
setError(res,"cptName is not null"); |
||||
} |
||||
//ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
PrintUtils.setExcel2007Content(res, FilenameUtils.getBaseName(cptName)); |
||||
Map<String, Object> params = getParams(req); |
||||
TemplateWorkBook wb = TemplateWorkBookIO.readTemplateWorkBook(cptName); |
||||
MyPageToSheetExcelExporter exporter = new MyPageToSheetExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(wb),params); |
||||
exporter.export(res.getOutputStream(), wb.execute(params, new PageActor())); |
||||
} |
||||
|
||||
private Map<String, Object> getParams(HttpServletRequest request) { |
||||
Map<String, Object> params = new HashMap<>(); |
||||
Enumeration<String> names = request.getParameterNames(); |
||||
while (names.hasMoreElements()) { |
||||
String name = names.nextElement(); |
||||
if ("cptName".equals(name) || "sheet_name".equals(name) || "name_format".equals(name)) { |
||||
continue; |
||||
} |
||||
params.put(name, request.getParameter(name)); |
||||
} |
||||
return params; |
||||
} |
||||
|
||||
private void setError(HttpServletResponse res, String mess) throws Exception { |
||||
WebUtils.printAsJSON(res, JSONObject.mapFrom(Response.error(mess,mess))); |
||||
} |
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.fr.plugin.xxxx.yyjm.fold; |
||||
|
||||
import com.fr.decision.fun.HttpHandler; |
||||
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/16 |
||||
* @Description |
||||
**/ |
||||
@Authorize(callSignKey = Constants.PLUGIN_ID) |
||||
@EnableMetrics |
||||
public class FoldRequestHandlerBridge extends AbstractHttpHandlerProvider { |
||||
|
||||
@Override |
||||
@Focus(id = Constants.PLUGIN_ID, text = "sheet重命名", source = Original.PLUGIN) |
||||
public HttpHandler[] registerHandlers() { |
||||
if (PluginContexts.currentContext().isAvailable()) { |
||||
return new HttpHandler[]{ |
||||
new ExportHandler(), |
||||
}; |
||||
} |
||||
return new HttpHandler[]{ |
||||
|
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.fr.plugin.xxxx.yyjm.fold; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractURLAliasProvider; |
||||
import com.fr.decision.webservice.url.alias.URLAlias; |
||||
import com.fr.decision.webservice.url.alias.URLAliasFactory; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/16 |
||||
* @Description |
||||
**/ |
||||
public class FoldRequestURLAliasBridge extends AbstractURLAliasProvider { |
||||
@Override |
||||
public URLAlias[] registerAlias() { |
||||
return new URLAlias[]{ |
||||
URLAliasFactory.createPluginAlias("/export", "/export", true), |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.fr.plugin.xxxx.yyjm.fold; |
||||
|
||||
import com.fr.io.attr.ReportExportAttr; |
||||
import com.fr.io.exporter.PageToSheetExcelExporter; |
||||
import com.fr.io.exporter.poi.wrapper.POIWorkbookAction; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.page.PaperSettingProvider; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.report.report.ResultECReport; |
||||
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFWorkbook; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/16 |
||||
* @Description |
||||
**/ |
||||
public class MyPageToSheetExcelExporter extends PageToSheetExcelExporter { |
||||
private Map parm; |
||||
public MyPageToSheetExcelExporter(List<PaperSettingProvider> list, Map parm) { |
||||
super(list); |
||||
this.parm = parm; |
||||
} |
||||
|
||||
@Override |
||||
protected MyStreamExcel2007Exporter getExporterFor2007(List<PaperSettingProvider> list) throws ClassNotFoundException { |
||||
return new MyStreamExcel2007Exporter(list,this.parm); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void innerExportReports(ResultECReport resultECReport, ResultWorkBook resultWorkBook, POIWorkbookAction poiWorkbookAction, List list, List<String> list1, List<Report> list2, int i) { |
||||
super.innerExportReports(resultECReport, resultWorkBook, poiWorkbookAction, list, list1, list2, i); |
||||
} |
||||
|
||||
@Override |
||||
protected void innerExportReport(Report report, ReportExportAttr reportExportAttr, String s, HSSFWorkbook hssfWorkbook, List list, List<String> list1, int i) throws Exception { |
||||
super.innerExportReport(report, reportExportAttr, NameUtil.getName(s,report,i, parm), hssfWorkbook, list, list1, i); |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.plugin.holger.yyjm.fold; |
||||
|
||||
import com.fr.io.attr.ReportExportAttr; |
||||
import com.fr.io.exporter.PageToSheetExcel2007Exporter; |
||||
import com.fr.io.exporter.poi.wrapper.POIWorkbookAction; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.report.report.ResultECReport; |
||||
import com.fr.third.v2.org.apache.poi.xssf.streaming.SXSSFWorkbook; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author hujian |
||||
* @Date 2021/11/16 |
||||
* @Description |
||||
**/ |
||||
public class MyStreamExcel2007Exporter extends PageToSheetExcel2007Exporter { |
||||
private Map parm; |
||||
public MyStreamExcel2007Exporter(List list, Map parm) { |
||||
super(list); |
||||
this.parm = parm; |
||||
} |
||||
|
||||
@Override |
||||
protected void innerExportReports(ResultECReport resultECReport, ResultWorkBook resultWorkBook, POIWorkbookAction poiWorkbookAction, List list, List list1, List list2, int i) { |
||||
super.innerExportReports(resultECReport, resultWorkBook, poiWorkbookAction, list, list1, list2, i); |
||||
} |
||||
|
||||
@Override |
||||
protected void innerExportReport(Report report, ReportExportAttr reportExportAttr, String s, SXSSFWorkbook sxssfWorkbook, List list, List list1, int i) throws Exception { |
||||
super.innerExportReport(report, reportExportAttr, NameUtil.getName(s,report,i,parm), sxssfWorkbook, list, list1, i); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.fr.plugin.xxxx.yyjm.fold; |
||||
|
||||
import com.fr.general.FArray; |
||||
import com.fr.io.core.PageToSheetExcelExporterReport; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/16 |
||||
* @Description |
||||
**/ |
||||
public class NameUtil { |
||||
public static String getName(FArray names , String format, int currentPage){ |
||||
String res = "Page"+currentPage; |
||||
if(names == null || names.length() == 0){ |
||||
return res; |
||||
} |
||||
if(StringUtils.isBlank(format)){ |
||||
return names.elementAt(currentPage - 1).toString(); |
||||
} |
||||
res = format; |
||||
res = res.replaceAll("TotalPageNumber",String.valueOf(names.length())); |
||||
res = res.replaceAll("PageIndex",String.valueOf(currentPage - 1)); |
||||
res = res.replaceAll("SheetName",names.elementAt(currentPage - 1).toString()); |
||||
return res; |
||||
} |
||||
public static String getName(String defaultName, Report report, int i, Map map) { |
||||
if(report instanceof PageToSheetExcelExporterReport){ |
||||
}else{ |
||||
return defaultName; |
||||
} |
||||
String sheetNames = (String) map.get("SHEET_NAME".toUpperCase()); |
||||
String nameFormat = (String) map.get("NAME_FORMAT".toUpperCase()); |
||||
if(StringUtils.isBlank(sheetNames) || StringUtils.isBlank(nameFormat)){ |
||||
return defaultName; |
||||
} |
||||
return getName(new FArray(sheetNames.split(",")),nameFormat,Integer.valueOf(defaultName.replace("Page",""))); |
||||
} |
||||
} |
@ -0,0 +1,52 @@
|
||||
package com.fr.plugin.xxxx.yyjm.fold; |
||||
|
||||
import com.fr.general.DeclareRecordType; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.io.collection.ExportCollection; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.ExcelExportType; |
||||
import com.fr.io.exporter.PageToSheetExcelExporter; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.fun.impl.AbstractExcelExportAppProvider; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.fr.web.core.ReportSessionIDInfor; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/16 |
||||
* @Description |
||||
**/ |
||||
@FunctionRecorder |
||||
@Authorize(callSignKey = Constants.PLUGIN_ID) |
||||
@EnableMetrics |
||||
public class RenameSheetExcelExportProvider extends AbstractExcelExportAppProvider { |
||||
|
||||
@Override |
||||
public String exportType() { |
||||
return "sheet"; |
||||
} |
||||
|
||||
@Override |
||||
@Focus(id = Constants.PLUGIN_ID, text = "sheet重命名", source = Original.PLUGIN) |
||||
public AppExporter<Boolean> createAppExporter(ExportCollection exportCollection, ExcelExportType excelExportType, ReportSessionIDInfor reportSessionIDInfor) { |
||||
Map param = reportSessionIDInfor.getParameterMap(); |
||||
AppExporter exporter; |
||||
if (PluginContexts.currentContext().isAvailable()) { |
||||
exporter = new MyPageToSheetExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(reportSessionIDInfor.getContextBook()), param); |
||||
} else { |
||||
exporter = new PageToSheetExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(reportSessionIDInfor.getContextBook())); |
||||
} |
||||
exportCollection.setExporter(exporter); |
||||
exportCollection.setRecordType(DeclareRecordType.EXPORT_TYPE_EXCEL_PAGESHEET); |
||||
return exporter; |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,113 @@
|
||||
package com.fr.plugin.xxxx.yyjm.fold.utils; |
||||
|
||||
import com.fr.decision.webservice.bean.user.UserBean; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.login.TokenResource; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.web.core.SessionPoolManager; |
||||
import com.fr.web.core.WidgetSessionIDInfor; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Date 2021/11/16 |
||||
* @Description |
||||
**/ |
||||
public class PrintUtils { |
||||
private static final String DSM = ""; |
||||
|
||||
public static void setPDFContent(HttpServletResponse var0, String var1, boolean var2) { |
||||
var0.setContentType("application/pdf"); |
||||
var0.setHeader("extension", "pdf"); |
||||
if (var2) { |
||||
var0.setHeader("Content-disposition", "anyword; filename=" + var1 + ".pdf"+DSM); |
||||
} else { |
||||
var0.setHeader("Content-disposition", "attachment; filename=" + var1 + ".pdf"+DSM); |
||||
} |
||||
|
||||
} |
||||
public static void setImageContext(HttpServletResponse var0, String var1, String var2) { |
||||
var0.setContentType("image/" + var2); |
||||
var0.setHeader("extension", var2); |
||||
var0.setHeader("Content-disposition", "attachment; filename=" + var1 + "." + var2+DSM); |
||||
} |
||||
|
||||
public static void setExcelContent(HttpServletResponse var0, String var1) { |
||||
var0.setContentType("application/x-excel"); |
||||
var0.setHeader("extension", "xls"); |
||||
var0.setHeader("Content-disposition", "attachment; filename=" + var1 + ".xls"+DSM); |
||||
} |
||||
|
||||
public static void setExcel2007Content(HttpServletResponse var0, String var1) { |
||||
var0.setContentType("application/x-excel"); |
||||
var0.setHeader("extension", "xlsx"); |
||||
var0.setHeader("Content-disposition", "attachment; filename=" + var1 + ".xlsx"+DSM); |
||||
} |
||||
|
||||
public static void setWordConetent(HttpServletResponse var0, String var1) { |
||||
var0.setContentType("application/msword"); |
||||
var0.setHeader("extension", "doc"); |
||||
var0.setHeader("Content-disposition", "attachment; filename=" + var1 + ".doc"+DSM); |
||||
} |
||||
|
||||
public static UserBean getUserById(HttpServletRequest req){ |
||||
String id = getCurrentUserFromRequest(req); |
||||
try { |
||||
if(StringUtils.isBlank(id)){ |
||||
return null; |
||||
} |
||||
return UserService.getInstance().getUser(id); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(),e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 判断FR是否登录了 |
||||
* |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
private static Boolean isLoginedFR(HttpServletRequest req) { |
||||
try { |
||||
String token = TokenResource.COOKIE.getToken(req); |
||||
LoginService.getInstance().loginStatusValid(token, null); |
||||
return true; |
||||
} catch (Exception e) { |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 获取当前用户名 |
||||
* |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
private static String getCurrentUserFromRequest(HttpServletRequest req) { |
||||
if (!isLoginedFR(req)) { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
try { |
||||
return UserService.getInstance().getCurrentUserIdFromCookie(req); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(),e); |
||||
} |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
public static String getReportId(HttpServletRequest req) { |
||||
String sessionID = WebUtils.getHTTPRequestParameter(req, "sessionID"); |
||||
WidgetSessionIDInfor sinfo = SessionPoolManager.getSessionIDInfor(sessionID, WidgetSessionIDInfor.class); |
||||
if(StringUtils.isNotBlank(sessionID)){ |
||||
return (String) sinfo.getParameterMap4Execute().get("reportId".toUpperCase()); |
||||
} |
||||
return StringUtils.EMPTY; |
||||
} |
||||
} |
Loading…
Reference in new issue