commit
825dae1b24
31 changed files with 1435 additions and 0 deletions
@ -0,0 +1,6 @@
|
||||
# open-JSD-9684 |
||||
|
||||
JSD-9684 客户报表添加水印:姓名+手机尾号。需在excel导出将水印带上\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 |
Binary file not shown.
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<plugin> |
||||
<id>com.fr.plugin.ifhd.watermark</id> |
||||
<name><![CDATA[水印功能定制]]></name> |
||||
<active>yes</active> |
||||
<version>1.0</version> |
||||
<env-version>10.0~10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[Excel水印功能定制]]></description> |
||||
<change-notes><![CDATA[ |
||||
<p>Excel水印功能定制</p> |
||||
<p>集成Excel流式导出支持行式引擎插件功能</p> |
||||
]]></change-notes> |
||||
<main-package>com.fr.plugin.ifhd</main-package> |
||||
<prefer-packages> |
||||
<prefer-package>com.fanruan.api</prefer-package> |
||||
</prefer-packages> |
||||
<extra-core> |
||||
<LocaleFinder class="com.fr.plugin.ifhd.LocaleFinder"/> |
||||
</extra-core> |
||||
<extra-report> |
||||
<ExcelExportAppProvider class="com.fr.plugin.ifhd.provider.SimpleExcelExportApp"/> |
||||
<ExcelExportAppProvider class="com.fr.plugin.ifhd.provider.SheetExcelExportApp"/> |
||||
<ExcelExportAppProvider class="com.fr.plugin.ifhd.provider.PageExcelExportApp"/> |
||||
<ExtensionButtonProvider class="com.fr.plugin.ifhd.excel.StreamExcelExtensionButton"/> |
||||
<ExcelExportAppProvider class="com.fr.plugin.ifhd.excel.StreamExcelExportApp"/> |
||||
<ExcelExportAppProvider class="com.fr.plugin.ifhd.excel.LayerExcelExportApp"/> |
||||
|
||||
</extra-report> |
||||
<extra-designer> |
||||
<ToolbarItemProvider class="com.fr.plugin.ifhd.excel.ui.StreamExcelExportToolbarUI"/> |
||||
</extra-designer> |
||||
|
||||
<function-recorder class="com.fr.plugin.ifhd.LocaleFinder"/> |
||||
</plugin> |
@ -0,0 +1,37 @@
|
||||
/* |
||||
* Copyright (C), 2018-2020 |
||||
* Project: starter |
||||
* FileName: LocaleFinder |
||||
* Author: Louis |
||||
* Date: 2020/8/31 22:19 |
||||
*/ |
||||
package com.fr.plugin.ifhd; |
||||
|
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <LocaleFinder> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
@EnableMetrics |
||||
public class LocaleFinder extends AbstractLocaleFinder { |
||||
|
||||
public static final String PLUGIN_ID = "com.fr.plugin.ifhd.watermark"; |
||||
|
||||
@Override |
||||
@Focus(id = PLUGIN_ID, text = "Plugin-ifhd", source = Original.PLUGIN) |
||||
public String find() { |
||||
return "com/fr/plugin/ifhd/locale/lang"; |
||||
} |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return CURRENT_LEVEL; |
||||
} |
||||
} |
@ -0,0 +1,68 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: LayerExcelExportApp |
||||
* Author: xxx |
||||
* Date: 2021/12/3 9:22 |
||||
*/ |
||||
package com.fr.plugin.ifhd.excel; |
||||
|
||||
import com.fr.general.DeclareRecordType; |
||||
import com.fr.io.collection.ExportCollection; |
||||
import com.fr.io.exporter.ExcelExportType; |
||||
import com.fr.plugin.ExtraClassManager; |
||||
import com.fr.plugin.ifhd.export.StreamExcel2007Exporter4LayerPlus; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.fun.impl.AbstractExcelExportAppProvider; |
||||
import com.fr.stable.ExportConstants; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.fr.stable.fun.FunctionProcessor; |
||||
import com.fr.web.core.ReportSessionIDInfor; |
||||
import com.fr.web.core.utils.ExportUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import static com.fr.plugin.ifhd.LocaleFinder.PLUGIN_ID; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <LayerExcelExportApp> |
||||
* |
||||
* @author xxx |
||||
* @since 1.0.0 |
||||
*/ |
||||
@Authorize(callSignKey = PLUGIN_ID) |
||||
public class LayerExcelExportApp extends AbstractExcelExportAppProvider { |
||||
public LayerExcelExportApp() { |
||||
} |
||||
|
||||
private static void recordFunction() { |
||||
FunctionProcessor var0 = ExtraClassManager.getInstance().getFunctionProcessor(); |
||||
if (var0 != null) { |
||||
var0.recordFunction(LayerStreamExportFunctionProcessor.getInstance()); |
||||
} |
||||
|
||||
} |
||||
|
||||
public int currentAPILevel() { |
||||
return super.currentAPILevel(); |
||||
} |
||||
|
||||
public String exportType() { |
||||
return ExportConstants.TYPE_LARGEDATA_PAGE; |
||||
} |
||||
|
||||
public ExportCollection createLargeDataExportCollection(HttpServletRequest var1, HttpServletResponse var2, ReportSessionIDInfor var3, String var4, ExcelExportType var5) { |
||||
ExportCollection var6 = ExportCollection.create(); |
||||
if (var2 != null) { |
||||
ExportUtils.setExcel2007Content(var2, var4); |
||||
} |
||||
|
||||
StreamExcel2007Exporter4LayerPlus var7 = new StreamExcel2007Exporter4LayerPlus(ReportUtils.getPaperSettingListFromWorkBook(var3.getContextBook()), var5.isPage()); |
||||
var6.setExporter(var7); |
||||
var6.setRecordType(DeclareRecordType.EXPORT_TYPE_EXCEL_ORIGINAL); |
||||
recordFunction(); |
||||
return var6; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: LayerStreamExportFunctionProcessor |
||||
* Author: xxx |
||||
* Date: 2021/12/3 9:23 |
||||
*/ |
||||
package com.fr.plugin.ifhd.excel; |
||||
|
||||
import com.fr.stable.fun.FunctionHelper; |
||||
import com.fr.stable.fun.impl.AbstractFunctionProcessor; |
||||
|
||||
import static com.fr.plugin.ifhd.LocaleFinder.PLUGIN_ID; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <LayerStreamExportFunctionProcessor> |
||||
* |
||||
* @author xxx |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class LayerStreamExportFunctionProcessor extends AbstractFunctionProcessor { |
||||
private static LayerStreamExportFunctionProcessor instance = new LayerStreamExportFunctionProcessor(); |
||||
|
||||
public LayerStreamExportFunctionProcessor() { |
||||
} |
||||
|
||||
public static LayerStreamExportFunctionProcessor getInstance() { |
||||
return instance; |
||||
} |
||||
|
||||
public int getId() { |
||||
return FunctionHelper.generateFunctionID(PLUGIN_ID); |
||||
} |
||||
|
||||
public String getLocaleKey() { |
||||
return "Plugin-ifhd_Excel_Stream_Export_Layer"; |
||||
} |
||||
} |
@ -0,0 +1,49 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: StreamExcelExportApp |
||||
* Author: xxx |
||||
* Date: 2021/12/3 9:24 |
||||
*/ |
||||
package com.fr.plugin.ifhd.excel; |
||||
|
||||
import com.fr.general.DeclareRecordType; |
||||
import com.fr.io.collection.ExportCollection; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.ExcelExportType; |
||||
import com.fr.plugin.ifhd.excel.exporter.StreamExcelExporter; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.fun.impl.AbstractExcelExportAppProvider; |
||||
import com.fr.stable.ExportConstants; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.fr.web.core.ReportSessionIDInfor; |
||||
|
||||
import static com.fr.plugin.ifhd.LocaleFinder.PLUGIN_ID; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <StreamExcelExportApp> |
||||
* |
||||
* @author xxx |
||||
* @since 1.0.0 |
||||
*/ |
||||
@Authorize(callSignKey = PLUGIN_ID) |
||||
public class StreamExcelExportApp extends AbstractExcelExportAppProvider { |
||||
public StreamExcelExportApp() { |
||||
} |
||||
|
||||
public int currentAPILevel() { |
||||
return super.currentAPILevel(); |
||||
} |
||||
|
||||
public String exportType() { |
||||
return ExportConstants.TYPE_STREAM; |
||||
} |
||||
|
||||
public AppExporter<Boolean> createAppExporter(ExportCollection var1, ExcelExportType var2, ReportSessionIDInfor var3) { |
||||
StreamExcelExporter var4 = new StreamExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(var3.getContextBook())); |
||||
var1.setExporter(var4); |
||||
var1.setRecordType(DeclareRecordType.EXPORT_TYPE_EXCEL_ORIGINAL); |
||||
return var4; |
||||
} |
||||
} |
@ -0,0 +1,68 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: StreamExcelExtensionButton |
||||
* Author: xxx |
||||
* Date: 2021/12/3 9:24 |
||||
*/ |
||||
package com.fr.plugin.ifhd.excel; |
||||
|
||||
import com.fr.base.IconManager; |
||||
import com.fr.form.ui.WebContentUtils; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.general.Inter; |
||||
import com.fr.js.JavaScriptImpl; |
||||
import com.fr.report.fun.impl.AbstractExtensionButton; |
||||
import com.fr.stable.web.Repository; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <StreamExcelExtensionButton> |
||||
* |
||||
* @author xxx |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class StreamExcelExtensionButton extends AbstractExtensionButton { |
||||
public StreamExcelExtensionButton() { |
||||
super(Inter.getLocText("Plugin-ifhd_Excel_Stream_Export"), IconManager.EXCEL.getName()); |
||||
} |
||||
|
||||
public StreamExcelExtensionButton(String var1) { |
||||
super(var1); |
||||
} |
||||
|
||||
public StreamExcelExtensionButton(String var1, String var2) { |
||||
super(var1, var2); |
||||
} |
||||
|
||||
public int currentAPILevel() { |
||||
return 2; |
||||
} |
||||
|
||||
public Class<? extends Widget> classForDirectoryButton() { |
||||
return this.getClass(); |
||||
} |
||||
|
||||
public String getParentDirectory() { |
||||
return null; |
||||
} |
||||
|
||||
public String getType() { |
||||
return "StreamExcelExport.class"; |
||||
} |
||||
|
||||
public String getRelatedCheckBoxTitle() { |
||||
return null; |
||||
} |
||||
|
||||
public boolean isSelected() { |
||||
return false; |
||||
} |
||||
|
||||
public void setSelected(boolean var1) { |
||||
} |
||||
|
||||
protected JavaScriptImpl clickAction(Repository var1) { |
||||
return new JavaScriptImpl(WebContentUtils.getExcelExportAction(var1, "stream")); |
||||
} |
||||
} |
@ -0,0 +1,117 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: StreamExcel2007Exporter4Layer |
||||
* Author: xxx |
||||
* Date: 2021/12/3 9:28 |
||||
*/ |
||||
package com.fr.plugin.ifhd.excel.exporter; |
||||
|
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.io.core.LargeDataExcelExporterReport; |
||||
import com.fr.io.exporter.excel.stream.StreamExcel2007Exporter; |
||||
import com.fr.io.exporter.poi.wrapper.POIWorkbookAction; |
||||
import com.fr.io.exporter.poi.wrapper.XssfCellWrapper; |
||||
import com.fr.io.exporter.poi.wrapper.XssfWorkbookWrapper; |
||||
import com.fr.main.workbook.PageRWorkBook; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.page.PageSetProvider; |
||||
import com.fr.page.PaperSettingProvider; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.report.report.ResultECReport; |
||||
import com.fr.report.stable.ReportSettings; |
||||
import com.fr.stable.ExportConstants; |
||||
import com.fr.stable.FT; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Cell; |
||||
import com.fr.third.v2.org.apache.poi.xssf.streaming.SXSSFWorkbook; |
||||
|
||||
import java.io.OutputStream; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <StreamExcel2007Exporter4Layer> |
||||
* |
||||
* @author xxx |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class StreamExcel2007Exporter4Layer<T> extends StreamExcel2007Exporter<T> { |
||||
private boolean isPage = false; |
||||
|
||||
public StreamExcel2007Exporter4Layer(List<PaperSettingProvider> var1, boolean var2) { |
||||
super(var1); |
||||
this.isPage = var2; |
||||
} |
||||
|
||||
public void export(OutputStream var1, ResultWorkBook var2, boolean var3) throws Exception { |
||||
this.defaultXSSFCellStyle = null; |
||||
this.hssfFontHash.clear(); |
||||
this.hssfCellStyleHash.clear(); |
||||
this.format = null; |
||||
SXSSFWorkbook var4 = new SXSSFWorkbook(10000); |
||||
ArrayList var5 = new ArrayList(); |
||||
ArrayList var6 = new ArrayList(); |
||||
XssfWorkbookWrapper var7 = new XssfWorkbookWrapper(var4); |
||||
this.setDefaultFont(var7); |
||||
|
||||
for (int var8 = 0; var8 < var2.getReportCount(); ++var8) { |
||||
ResultECReport var9 = (ResultECReport) var2.getResultReport(var8); |
||||
if (var9 != null) { |
||||
if (var9.getReportSettings() == null) { |
||||
var9.setReportSettings(new ReportSettings()); |
||||
} |
||||
|
||||
var9.getReportSettings().setPageOrder(1); |
||||
PaperSettingProvider var10 = this.paperSettingList == null ? null : (PaperSettingProvider) this.paperSettingList.get(var8); |
||||
PageSetProvider var11 = var9.generateReportPageSet(var10); |
||||
var11 = this.isPage ? var11.traverse4Export() : var11.traverse4SimpleExport(); |
||||
FT var12 = new FT(0, 0); |
||||
|
||||
while (var12.to != -1) { |
||||
var12.from = var12.to; |
||||
PageRWorkBook var13 = new PageRWorkBook(); |
||||
String var14 = var2.getReportName(var8); |
||||
var13.addReport(var14, new LargeDataExcelExporterReport(var9, var11, var12, false, ExportConstants.MAX_ROWS_2007)); |
||||
this.exportBook(var13, var7, var5, var6, new ArrayList(), var3); |
||||
FRLogger.getLogger().info(var14 + Inter.getLocText("Plugin-ifhd_Engine_Finish_Export")); |
||||
} |
||||
|
||||
if (!var3 && !var11.isPageCached()) { |
||||
var11.release(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
this.dealWithFormula(var5, var6); |
||||
var4.write(var1); |
||||
var1.flush(); |
||||
var4.dispose(); |
||||
} |
||||
|
||||
private void dealWithFormula(List<Cell> var1, List<String> var2) { |
||||
int var3 = 0; |
||||
|
||||
for (int var4 = var1.size(); var3 < var4; ++var3) { |
||||
Cell var5 = (Cell) var1.get(var3); |
||||
this.dealWithFormula(new XssfCellWrapper(var5), (String) var2.get(var3)); |
||||
} |
||||
|
||||
} |
||||
|
||||
protected void exportBook(ResultWorkBook var1, POIWorkbookAction var2, List var3, List<String> var4, List<Report> var5, boolean var6) throws Exception { |
||||
int var7; |
||||
Report var8; |
||||
for (var7 = 0; var7 < var1.getReportCount(); ++var7) { |
||||
var8 = var1.getReport(var7); |
||||
var5.add(var8); |
||||
} |
||||
|
||||
for (var7 = 0; var7 < var1.getReportCount(); ++var7) { |
||||
var8 = (Report) var5.get(var7); |
||||
this.innerExportReport(var8, var1.getReportExportAttr(), var1.getReportName(var7), (SXSSFWorkbook) var2.getWorkbook(), var3, var4, var7); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: StreamExcelExporter |
||||
* Author: xxx |
||||
* Date: 2021/12/3 9:27 |
||||
*/ |
||||
package com.fr.plugin.ifhd.excel.exporter; |
||||
|
||||
import com.fr.general.FRLogger; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.ExcelExporter; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.page.PaperSettingProvider; |
||||
import com.fr.plugin.ifhd.export.StreamExcel2007PlusExporter; |
||||
|
||||
import java.io.OutputStream; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <StreamExcelExporter> |
||||
* |
||||
* @author xxx |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class StreamExcelExporter extends ExcelExporter { |
||||
public StreamExcelExporter(List<PaperSettingProvider> var1) { |
||||
super(var1); |
||||
} |
||||
|
||||
protected void exportFor2003(OutputStream var1, ResultWorkBook var2, boolean var3) throws Exception { |
||||
FRLogger.getLogger().error("StreamExcelExporter for 2003 is not supported"); |
||||
} |
||||
|
||||
protected AppExporter getExporterFor2007(List<PaperSettingProvider> var1) throws ClassNotFoundException { |
||||
return new StreamExcel2007PlusExporter(var1); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: StreamExcelExportToolbarUI |
||||
* Author: xxx |
||||
* Date: 2021/12/3 9:26 |
||||
*/ |
||||
package com.fr.plugin.ifhd.excel.ui; |
||||
|
||||
import com.fanruan.api.design.DesignKit; |
||||
import com.fr.design.fun.impl.AbstractToolbarItem; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.plugin.ifhd.excel.StreamExcelExtensionButton; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <StreamExcelExportToolbarUI> |
||||
* |
||||
* @author xxx |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class StreamExcelExportToolbarUI extends AbstractToolbarItem { |
||||
public StreamExcelExportToolbarUI() { |
||||
} |
||||
|
||||
public int currentAPILevel() { |
||||
return 1; |
||||
} |
||||
|
||||
public Class<? extends Widget> classForWidget() { |
||||
return StreamExcelExtensionButton.class; |
||||
} |
||||
|
||||
public String iconPathForWidget() { |
||||
return "/com/fr/plugin/ifhd/excel/images/excel.png"; |
||||
} |
||||
|
||||
public String nameForWidget() { |
||||
return DesignKit.i18nText("Plugin-ifhd_Excel_Stream_Export"); |
||||
} |
||||
} |
@ -0,0 +1,54 @@
|
||||
/** |
||||
* Copyright (C), 2015-2020 |
||||
* FileName: ExcelPlusExporter |
||||
* Author: Louis |
||||
* Date: 2020/3/17 11:50 |
||||
* Description: ExcelPlusExporter |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ifhd.export; |
||||
|
||||
import com.fr.io.attr.ReportExportAttr; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.ExcelExporter; |
||||
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; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈ExcelPlusExporter〉 |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class ExcelPlusExporter extends ExcelExporter { |
||||
|
||||
public ExcelPlusExporter() { |
||||
} |
||||
|
||||
public ExcelPlusExporter(List list) { |
||||
super(list); |
||||
} |
||||
|
||||
@Override |
||||
protected AppExporter getExporterFor2007(List<PaperSettingProvider> list) { |
||||
return new StreamExcel2007PlusExporter(list); |
||||
} |
||||
|
||||
@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, s, hssfWorkbook, list, list1, i); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/** |
||||
* Copyright (C), 2015-2020 |
||||
* FileName: LargeDataPageExcelPlusExporter |
||||
* Author: Louis |
||||
* Date: 2020/3/23 17:01 |
||||
* Description: LargeDataPageExcelPlusExporter |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ifhd.export; |
||||
|
||||
import com.fr.io.attr.ReportExportAttr; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.LargeDataPageExcelExporter; |
||||
import com.fr.page.PaperSettingProvider; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFWorkbook; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈LargeDataPageExcelPlusExporter〉 |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class LargeDataPageExcelPlusExporter extends LargeDataPageExcelExporter { |
||||
|
||||
public LargeDataPageExcelPlusExporter(List list, boolean b) { |
||||
super(list, b); |
||||
} |
||||
|
||||
@Override |
||||
protected AppExporter getExporterFor2007(List<PaperSettingProvider> list) { |
||||
return new StreamExcel2007PlusExporter(list); |
||||
} |
||||
|
||||
@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, s, hssfWorkbook, list, list1, i); |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
/** |
||||
* Copyright (C), 2015-2020 |
||||
* FileName: PageExcel2007PlusExporter |
||||
* Author: Louis |
||||
* Date: 2020/3/22 20:39 |
||||
* Description: PageExcel2007PlusExporter |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ifhd.export; |
||||
|
||||
import com.fr.io.exporter.PageExcel2007Exporter; |
||||
import com.fr.io.exporter.poi.wrapper.POIWorkbookAction; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.page.PaperSettingProvider; |
||||
import com.fr.plugin.ifhd.utils.WaterMarkHandler; |
||||
import com.fr.report.report.Report; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈PageExcel2007PlusExporter〉 |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class PageExcel2007PlusExporter<T> extends PageExcel2007Exporter<T> { |
||||
|
||||
public PageExcel2007PlusExporter(List<PaperSettingProvider> list) { |
||||
super(list); |
||||
} |
||||
|
||||
@Override |
||||
protected void exportBook(ResultWorkBook resultWorkBook, POIWorkbookAction poiWorkbookAction, List list, List<String> list1, List<Report> list2, boolean b) throws Exception { |
||||
super.exportBook(resultWorkBook, poiWorkbookAction, list, list1, list2, b); |
||||
WaterMarkHandler.putWaterRemarkToExcel(resultWorkBook, poiWorkbookAction); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/** |
||||
* Copyright (C), 2015-2020 |
||||
* FileName: PageExcelPlusExporter |
||||
* Author: Louis |
||||
* Date: 2020/3/22 20:36 |
||||
* Description: PageExcelPlusExporter |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ifhd.export; |
||||
|
||||
import com.fr.io.attr.ReportExportAttr; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.PageExcelExporter; |
||||
import com.fr.page.PaperSettingProvider; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFWorkbook; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈PageExcelPlusExporter〉 |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class PageExcelPlusExporter extends PageExcelExporter { |
||||
|
||||
public PageExcelPlusExporter(List list) { |
||||
super(list); |
||||
} |
||||
|
||||
@Override |
||||
protected AppExporter getExporterFor2007(List<PaperSettingProvider> list) throws ClassNotFoundException { |
||||
return new PageExcel2007PlusExporter(list); |
||||
} |
||||
|
||||
@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, s, hssfWorkbook, list, list1, i); |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
/** |
||||
* Copyright (C), 2015-2020 |
||||
* FileName: PageToSheetExcel2007PlusExporter |
||||
* Author: Louis |
||||
* Date: 2020/3/22 15:12 |
||||
* Description: PageToSheetExcel2007PlusExporter |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ifhd.export; |
||||
|
||||
import com.fr.io.exporter.PageToSheetExcel2007Exporter; |
||||
import com.fr.io.exporter.poi.wrapper.POIWorkbookAction; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.plugin.ifhd.utils.WaterMarkHandler; |
||||
import com.fr.report.report.Report; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈PageToSheetExcel2007PlusExporter〉 |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class PageToSheetExcel2007PlusExporter<T> extends PageToSheetExcel2007Exporter<T> { |
||||
|
||||
public PageToSheetExcel2007PlusExporter(List list) { |
||||
super(list); |
||||
} |
||||
|
||||
@Override |
||||
protected void exportBook(ResultWorkBook resultWorkBook, POIWorkbookAction poiWorkbookAction, List list, List<String> list1, List<Report> list2, boolean b) throws Exception { |
||||
super.exportBook(resultWorkBook, poiWorkbookAction, list, list1, list2, b); |
||||
WaterMarkHandler.putWaterRemarkToExcel(resultWorkBook, poiWorkbookAction); |
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
/** |
||||
* Copyright (C), 2015-2020 |
||||
* FileName: PageToSheetExcelPlusExporter |
||||
* Author: Louis |
||||
* Date: 2020/3/22 15:07 |
||||
* Description: PageToSheetExcelPlusExporter |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ifhd.export; |
||||
|
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.PageToSheetExcelExporter; |
||||
import com.fr.page.PaperSettingProvider; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈PageToSheetExcelPlusExporter〉 |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class PageToSheetExcelPlusExporter extends PageToSheetExcelExporter { |
||||
|
||||
public PageToSheetExcelPlusExporter(List<PaperSettingProvider> list) { |
||||
super(list); |
||||
} |
||||
|
||||
@Override |
||||
protected AppExporter getExporterFor2007(List<PaperSettingProvider> list) { |
||||
return new PageToSheetExcel2007PlusExporter(list); |
||||
} |
||||
} |
@ -0,0 +1,45 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: StreamExcel2007Exporter4LayerPlus |
||||
* Author: Louis |
||||
* Date: 2021/12/3 11:55 |
||||
*/ |
||||
package com.fr.plugin.ifhd.export; |
||||
|
||||
import com.fr.io.exporter.poi.wrapper.POIWorkbookAction; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.page.PaperSettingProvider; |
||||
import com.fr.plugin.ifhd.excel.exporter.StreamExcel2007Exporter4Layer; |
||||
import com.fr.plugin.ifhd.utils.WaterMarkHandler; |
||||
import com.fr.report.report.Report; |
||||
|
||||
import java.io.OutputStream; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <StreamExcel2007Exporter4LayerPlus> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class StreamExcel2007Exporter4LayerPlus<T> extends StreamExcel2007Exporter4Layer<T> { |
||||
private ResultWorkBook resultWorkBook; |
||||
|
||||
public StreamExcel2007Exporter4LayerPlus(List<PaperSettingProvider> paperSettingProviders, boolean b) { |
||||
super(paperSettingProviders, b); |
||||
} |
||||
|
||||
@Override |
||||
public void export(OutputStream outputStream, ResultWorkBook resultWorkBook, boolean b) throws Exception { |
||||
this.resultWorkBook = resultWorkBook; |
||||
super.export(outputStream, resultWorkBook, b); |
||||
} |
||||
|
||||
@Override |
||||
protected void exportBook(ResultWorkBook resultWorkBook, POIWorkbookAction poiWorkbookAction, List list, List<String> list1, List<Report> reports, boolean b) throws Exception { |
||||
super.exportBook(resultWorkBook, poiWorkbookAction, list, list1, reports, b); |
||||
WaterMarkHandler.putWaterRemarkToExcel(this.resultWorkBook, poiWorkbookAction); |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
/** |
||||
* Copyright (C), 2015-2020 |
||||
* FileName: StreamExcel2007PlusExporter |
||||
* Author: Louis |
||||
* Date: 2020/3/17 16:18 |
||||
* Description: StreamExcel2007PlusExporter |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ifhd.export; |
||||
|
||||
import com.fr.io.exporter.excel.stream.StreamExcel2007Exporter; |
||||
import com.fr.io.exporter.poi.wrapper.POIWorkbookAction; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.page.PaperSettingProvider; |
||||
import com.fr.plugin.ifhd.utils.WaterMarkHandler; |
||||
import com.fr.report.report.Report; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈StreamExcel2007PlusExporter〉 |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class StreamExcel2007PlusExporter<T> extends StreamExcel2007Exporter<T> { |
||||
|
||||
public StreamExcel2007PlusExporter() { |
||||
} |
||||
|
||||
public StreamExcel2007PlusExporter(List<PaperSettingProvider> list) { |
||||
super(list); |
||||
} |
||||
|
||||
@Override |
||||
protected void exportBook(ResultWorkBook resultWorkBook, POIWorkbookAction poiWorkbookAction, List list, List<String> list1, List<Report> list2, boolean b) throws Exception { |
||||
super.exportBook(resultWorkBook, poiWorkbookAction, list, list1, list2, b); |
||||
WaterMarkHandler.putWaterRemarkToExcel(resultWorkBook, poiWorkbookAction); |
||||
} |
||||
} |
@ -0,0 +1,46 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter |
||||
* FileName: WordOperate |
||||
* Author: Louis |
||||
* Date: 2022/2/23 15:26 |
||||
*/ |
||||
package com.fr.plugin.ifhd.export; |
||||
|
||||
import com.fr.general.ReportDeclareRecordType; |
||||
import com.fr.io.collection.ExportCollection; |
||||
import com.fr.io.exporter.ExportChecker; |
||||
import com.fr.io.exporter.WordExportChecker; |
||||
import com.fr.stable.web.SessionProvider; |
||||
import com.fr.web.core.reserve.DefaultOperate; |
||||
import com.fr.web.core.utils.ExportUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <WordOperate> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class WordOperate extends DefaultOperate { |
||||
@Override |
||||
public void setContent(HttpServletRequest request, HttpServletResponse response, String fileName, boolean isEmbed) { |
||||
ExportUtils.setWordConetent(response, fileName); |
||||
} |
||||
|
||||
@Override |
||||
public ExportCollection newExportCollection(HttpServletRequest request, HttpServletResponse response, SessionProvider sessionIDInfor, String fileName) { |
||||
ExportCollection exportCollection = ExportCollection.create(); |
||||
exportCollection.setExporter(new WordPlusExporter()); |
||||
exportCollection.setRecordType(ReportDeclareRecordType.EXPORT_TYPE_WORD); |
||||
return exportCollection; |
||||
} |
||||
|
||||
@Override |
||||
public ExportChecker newExportChecker(HttpServletRequest request) { |
||||
return new WordExportChecker(); |
||||
} |
||||
} |
@ -0,0 +1,27 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter |
||||
* FileName: WordPlusExporter |
||||
* Author: Louis |
||||
* Date: 2022/2/23 15:38 |
||||
*/ |
||||
package com.fr.plugin.ifhd.export; |
||||
|
||||
import com.fr.io.exporter.WordExporter; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
|
||||
import java.io.OutputStream; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <WordPlusExporter> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class WordPlusExporter extends WordExporter { |
||||
@Override |
||||
public void export(OutputStream outputStream, ResultWorkBook resultWorkBook) throws Exception { |
||||
super.export(outputStream, resultWorkBook); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: PageExcelExportApp |
||||
* Author: Louis |
||||
* Date: 2021/12/6 9:07 |
||||
*/ |
||||
package com.fr.plugin.ifhd.provider; |
||||
|
||||
import com.fr.general.ReportDeclareRecordType; |
||||
import com.fr.io.collection.ExportCollection; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.ExcelExportType; |
||||
import com.fr.plugin.ifhd.export.PageExcelPlusExporter; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.fun.impl.AbstractExcelExportAppProvider; |
||||
import com.fr.stable.ExportConstants; |
||||
import com.fr.stable.web.SessionProvider; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <分页导出PageExcelExportApp> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class PageExcelExportApp extends AbstractExcelExportAppProvider { |
||||
|
||||
@Override |
||||
public String exportType() { |
||||
return ExportConstants.TYPE_PAGE; |
||||
} |
||||
|
||||
@Override |
||||
public AppExporter<Boolean> newAppExporter(ExportCollection collection, ExcelExportType exportType, SessionProvider sessionIDInfor) { |
||||
AppExporter<Boolean> exporter = new PageExcelPlusExporter(ReportUtils.getPaperSettingListFromWorkBook(sessionIDInfor.getOriginalObject())); |
||||
collection.setExporter(exporter); |
||||
collection.setRecordType(ReportDeclareRecordType.EXPORT_TYPE_EXCEL_PAGE); |
||||
return exporter; |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: SheetExcelExportApp |
||||
* Author: Louis |
||||
* Date: 2021/12/6 8:44 |
||||
*/ |
||||
package com.fr.plugin.ifhd.provider; |
||||
|
||||
import com.fr.general.ReportDeclareRecordType; |
||||
import com.fr.io.collection.ExportCollection; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.ExcelExportType; |
||||
import com.fr.plugin.ifhd.export.PageToSheetExcelPlusExporter; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.fun.impl.AbstractExcelExportAppProvider; |
||||
import com.fr.stable.ExportConstants; |
||||
import com.fr.stable.web.SessionProvider; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <分页分sheet导出SheetExcelExportApp> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class SheetExcelExportApp extends AbstractExcelExportAppProvider { |
||||
|
||||
@Override |
||||
public String exportType() { |
||||
return ExportConstants.TYPE_PAGETOSHETT; |
||||
} |
||||
|
||||
@Override |
||||
public AppExporter<Boolean> newAppExporter(ExportCollection collection, ExcelExportType exportType, SessionProvider sessionIDInfor) { |
||||
AppExporter<Boolean> exporter = new PageToSheetExcelPlusExporter(ReportUtils.getPaperSettingListFromWorkBook(sessionIDInfor.getOriginalObject())); |
||||
collection.setExporter(exporter); |
||||
collection.setRecordType(ReportDeclareRecordType.EXPORT_TYPE_EXCEL_PAGESHEET); |
||||
return exporter; |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: SimpleExcelExportApp |
||||
* Author: Louis |
||||
* Date: 2021/12/6 8:27 |
||||
*/ |
||||
package com.fr.plugin.ifhd.provider; |
||||
|
||||
import com.fr.general.ReportDeclareRecordType; |
||||
import com.fr.io.collection.ExportCollection; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.ExcelExportType; |
||||
import com.fr.plugin.ifhd.export.ExcelPlusExporter; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.fun.impl.AbstractExcelExportAppProvider; |
||||
import com.fr.stable.ExportConstants; |
||||
import com.fr.stable.web.SessionProvider; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <原样导出SimpleExcelExportApp> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class SimpleExcelExportApp extends AbstractExcelExportAppProvider { |
||||
|
||||
@Override |
||||
public String exportType() { |
||||
return ExportConstants.TYPE_SIMPLE; |
||||
} |
||||
|
||||
@Override |
||||
public AppExporter<Boolean> newAppExporter(ExportCollection collection, ExcelExportType exportType, SessionProvider sessionIDInfor) { |
||||
AppExporter<Boolean> exporter = new ExcelPlusExporter(ReportUtils.getPaperSettingListFromWorkBook(sessionIDInfor.getOriginalObject())); |
||||
collection.setExporter(exporter); |
||||
collection.setRecordType(ReportDeclareRecordType.EXPORT_TYPE_EXCEL_ORIGINAL); |
||||
return exporter; |
||||
} |
||||
} |
@ -0,0 +1,60 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter |
||||
* FileName: WordExportExtension |
||||
* Author: Louis |
||||
* Date: 2022/2/23 15:17 |
||||
*/ |
||||
package com.fr.plugin.ifhd.provider; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.io.collection.ExportCollection; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.plugin.ifhd.export.WordOperate; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.fr.web.core.ReportSessionIDInfor; |
||||
import com.fr.web.core.reserve.DefaultExportExtension; |
||||
import com.fr.web.core.reserve.Operate; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import static com.fr.plugin.ifhd.LocaleFinder.PLUGIN_ID; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <WordExportExtension> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
@EnableMetrics |
||||
@Authorize(callSignKey = PLUGIN_ID) |
||||
public class WordExportExtension extends DefaultExportExtension { |
||||
private static final String FORMAT_WORD = "word"; |
||||
|
||||
private static final Map<String, Operate> OPERATE_MAP; |
||||
|
||||
static { |
||||
OPERATE_MAP = new HashMap<String, Operate>(); |
||||
// 导出类型参考com.fr.web.core.reserve.ExportFactory
|
||||
OPERATE_MAP.put(FORMAT_WORD, new WordOperate()); |
||||
} |
||||
|
||||
@Override |
||||
@Focus(id = PLUGIN_ID, text = "Plugin-ifhd", source = Original.PLUGIN) |
||||
public ExportCollection createCollection(HttpServletRequest req, HttpServletResponse res, ReportSessionIDInfor reportSessionIDInfor, String format, String fileName, boolean isEmbed) throws Exception { |
||||
LogKit.info("ifhd-WordExportExtension-createCollection-format:{}", format); |
||||
Operate operate = OPERATE_MAP.get(format.toLowerCase()); |
||||
if (operate != null && PluginContexts.currentContext().isAvailable()) { |
||||
operate.setContent(req, res, reportSessionIDInfor, fileName, isEmbed); |
||||
return operate.newExportCollection(req, res, reportSessionIDInfor, fileName); |
||||
} |
||||
return super.createCollection(req, res, reportSessionIDInfor, format, fileName, isEmbed); |
||||
} |
||||
} |
@ -0,0 +1,178 @@
|
||||
/** |
||||
* Copyright (C), 2015-2021 |
||||
* FileName: WaterMarkHandler |
||||
* Author: Louis |
||||
* Date: 2020/3/16 21:55 |
||||
* Description: WaterMarkHandler |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ifhd.utils; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.base.iofile.attr.WatermarkAttr; |
||||
import com.fr.io.exporter.poi.wrapper.POIWorkbookAction; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Workbook; |
||||
import com.fr.third.v2.org.apache.poi.xssf.streaming.SXSSFWorkbook; |
||||
import com.fr.third.v2.org.apache.poi.xssf.usermodel.XSSFRelation; |
||||
import com.fr.third.v2.org.apache.poi.xssf.usermodel.XSSFSheet; |
||||
import com.fr.third.v2.org.apache.poi.xssf.usermodel.XSSFWorkbook; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
import java.awt.*; |
||||
import java.awt.font.FontRenderContext; |
||||
import java.awt.geom.Rectangle2D; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
import java.io.IOException; |
||||
|
||||
public class WaterMarkHandler { |
||||
private final String WATER_MARK; |
||||
|
||||
public WaterMarkHandler(String water_mark) { |
||||
WATER_MARK = water_mark; |
||||
} |
||||
|
||||
public static ByteArrayOutputStream createWaterMark(WatermarkAttr watermarkAttr) throws IOException { |
||||
Color color = new Color(watermarkAttr.getColor().getRed(), watermarkAttr.getColor().getGreen(), watermarkAttr.getColor().getBlue(), 100); |
||||
int width = 300; |
||||
int height = 150; |
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);// 获取bufferedImage对象
|
||||
String fontType = "仿宋"; |
||||
int fontStyle = Font.BOLD; |
||||
int fontSize = watermarkAttr.getFontSize(); |
||||
Font font = new Font(fontType, fontStyle, fontSize); |
||||
Graphics2D g2d = image.createGraphics(); // 获取Graphics2d对象
|
||||
image = g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); |
||||
g2d.dispose(); |
||||
g2d = image.createGraphics(); |
||||
g2d.setColor(color); //设置字体颜色和透明度,最后一个参数为透明度
|
||||
g2d.setStroke(new BasicStroke(1)); // 设置字体
|
||||
g2d.setFont(font); // 设置字体类型 加粗 大小
|
||||
g2d.rotate(-0.3, (double) image.getWidth() / 2, (double) image.getHeight() / 2);//设置倾斜度
|
||||
FontRenderContext context = g2d.getFontRenderContext(); |
||||
Rectangle2D bounds = font.getStringBounds(watermarkAttr.getText(), context); |
||||
double x = (width - bounds.getWidth()) / 2; |
||||
double y = (height - bounds.getHeight()) / 2; |
||||
double ascent = -bounds.getY(); |
||||
double baseY = y + ascent; |
||||
// 写入水印文字原定高度过小,所以累计写水印,增加高度
|
||||
String[] info = watermarkAttr.getText().split("\\;"); |
||||
if (info.length > 0) { |
||||
for (int i = 0; i < info.length; i++) { |
||||
String s = info[i]; |
||||
g2d.drawString(s, 1 + (i * 40), (int) baseY + (i * 25)); |
||||
} |
||||
} else { |
||||
g2d.drawString(watermarkAttr.getText(), 0, (int) baseY); |
||||
} |
||||
|
||||
// 设置透明度
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); |
||||
// 释放对象
|
||||
g2d.dispose(); |
||||
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
||||
ImageIO.write(image, "png", os); |
||||
return os; |
||||
} |
||||
|
||||
/** |
||||
* 为Excel打上水印工具函数 |
||||
* |
||||
* @param sheet excel sheet |
||||
* @param bytes 水印图片字节数组 |
||||
*/ |
||||
public static void putWaterRemarkToExcel(XSSFSheet sheet, byte[] bytes) { |
||||
//add relation from sheet to the picture data
|
||||
XSSFWorkbook workbook = sheet.getWorkbook(); |
||||
int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG); |
||||
String rID = sheet.addRelation(null, XSSFRelation.IMAGES, workbook.getAllPictures().get(pictureIdx)) |
||||
.getRelationship().getId(); |
||||
//set background picture to sheet
|
||||
sheet.getCTWorksheet().addNewPicture().setId(rID); |
||||
} |
||||
|
||||
public static void main(String[] args) throws IOException { |
||||
FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\\aa.xlsx")); |
||||
XSSFWorkbook workbook = new XSSFWorkbook(); |
||||
XSSFSheet sheet = workbook.createSheet("Sheet1"); |
||||
WatermarkAttr watermarkAttr = new WatermarkAttr(); |
||||
watermarkAttr.setText("内部信息,严禁外传;2021-09-14;曲君阳"); |
||||
watermarkAttr.setFontSize(16); |
||||
watermarkAttr.setColor(new Color(0, 0, 0, 100)); |
||||
try (ByteArrayOutputStream byteArrayOutputStream = WaterMarkHandler.createWaterMark(watermarkAttr)) { |
||||
int pictureIdx = workbook.addPicture(byteArrayOutputStream.toByteArray(), Workbook.PICTURE_TYPE_PNG); |
||||
//add relation from sheet to the picture data
|
||||
String rID = sheet.addRelation(null, XSSFRelation.IMAGES, workbook.getAllPictures().get(pictureIdx)) |
||||
.getRelationship().getId(); |
||||
//set background picture to sheet
|
||||
sheet.getCTWorksheet().addNewPicture().setId(rID); |
||||
workbook.write(fileOutputStream); |
||||
} |
||||
} |
||||
|
||||
public static void setWartMark(XSSFWorkbook workbook, XSSFSheet sheet, WatermarkAttr wartInfo) { |
||||
try (ByteArrayOutputStream byteArrayOutputStream = WaterMarkHandler.createWaterMark(wartInfo)) { |
||||
int pictureIdx = workbook.addPicture(byteArrayOutputStream.toByteArray(), Workbook.PICTURE_TYPE_PNG); |
||||
//add relation from sheet to the picture data
|
||||
String rID = sheet.addRelation(null, XSSFRelation.IMAGES, workbook.getAllPictures().get(pictureIdx)) |
||||
.getRelationship().getId(); |
||||
//set background picture to sheet
|
||||
sheet.getCTWorksheet().addNewPicture().setId(rID); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 设定水印图片Idx |
||||
* |
||||
* @param resultWorkBook |
||||
* @param poiWorkbookAction |
||||
* @return |
||||
*/ |
||||
private static int getPictureIdx(ResultWorkBook resultWorkBook, POIWorkbookAction poiWorkbookAction) { |
||||
WatermarkAttr watermarkAttr = ReportUtils.getWatermarkAttrFromTemplate(resultWorkBook); |
||||
if (watermarkAttr == null || watermarkAttr.isEmpty()) { |
||||
return 0; |
||||
} |
||||
try { |
||||
LogKit.info("ifhd-WaterMarkHandler-watermarkAttr:{}", watermarkAttr.getText()); |
||||
ByteArrayOutputStream byteArrayOutputStream = createWaterMark(watermarkAttr); |
||||
return poiWorkbookAction.addPicture(byteArrayOutputStream.toByteArray(), Workbook.PICTURE_TYPE_PNG); |
||||
} catch (IOException e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 关联sheet和水印图片 |
||||
* |
||||
* @param sxssfWorkbook |
||||
*/ |
||||
private static void sheetAddPicture(SXSSFWorkbook sxssfWorkbook, int pictureIdx) { |
||||
if (!PluginContexts.currentContext().isAvailable()) { |
||||
return; |
||||
} |
||||
XSSFSheet xssfSheet; |
||||
String rID; |
||||
XSSFWorkbook xssfWorkbook = sxssfWorkbook.getXSSFWorkbook(); |
||||
for (int j = 0; j < xssfWorkbook.getNumberOfSheets(); j++) { |
||||
xssfSheet = xssfWorkbook.getSheetAt(j); |
||||
rID = xssfSheet.addRelation(null, XSSFRelation.IMAGES, xssfWorkbook.getAllPictures().get(pictureIdx)) |
||||
.getRelationship().getId(); |
||||
xssfSheet.getCTWorksheet().addNewPicture().setId(rID); |
||||
} |
||||
} |
||||
|
||||
public static void putWaterRemarkToExcel(ResultWorkBook resultWorkBook, POIWorkbookAction poiWorkbookAction) { |
||||
int pictureIdx = getPictureIdx(resultWorkBook, poiWorkbookAction); |
||||
sheetAddPicture((SXSSFWorkbook) poiWorkbookAction.getWorkbook(), pictureIdx); |
||||
} |
||||
} |
@ -0,0 +1,138 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter |
||||
* FileName: WordHandler |
||||
* Author: Louis |
||||
* Date: 2022/2/23 21:47 |
||||
*/ |
||||
package com.fr.plugin.ifhd.utils; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.third.org.apache.commons.io.FileUtils; |
||||
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; |
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument; |
||||
import org.apache.poi.xwpf.usermodel.XWPFHeader; |
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph; |
||||
import org.apache.xmlbeans.XmlObject; |
||||
|
||||
import javax.xml.namespace.QName; |
||||
import java.io.*; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <WordHandler> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class WordHandler { |
||||
public WordHandler() { |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
try { |
||||
String inputSrc = "E:\\GettingStarted.doc"; |
||||
String outputSrc = "E:\\test_temp.docx"; |
||||
File file = new File(inputSrc); |
||||
byte[] bytes = FileUtils.readFileToByteArray(file); |
||||
addWordWaterMark(bytes, outputSrc, "内部资料 严禁外传"); |
||||
|
||||
// String inputSrc2 = "E:\\test.doc";
|
||||
// String outputSrc2 = "E:\\test_temp.doc";
|
||||
// File file2 = new File(inputSrc2);
|
||||
// byte[] bytes2 = FileUtils.readFileToByteArray(file2);
|
||||
// addWordWaterMark2003(bytes2, outputSrc2, "内部资料 严禁外传");
|
||||
|
||||
} catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* word文件添加文字水印 |
||||
* |
||||
* @param fileData 原始文件字节数组 |
||||
* @param outputSrc 文件输出路径 |
||||
* @param waterMarkName 水印内容 |
||||
*/ |
||||
// private static void addWordWaterMark2003(byte[] fileData, String outputSrc, String waterMarkName) throws Exception {
|
||||
// InputStream input = new ByteArrayInputStream(fileData);
|
||||
// HWPFDocument doc = new HWPFDocument(input);
|
||||
// XWPFHeaderFooterPolicy headerFooterPolicy = doc.createHeaderFooterPolicy();
|
||||
// //添加文字水印
|
||||
// headerFooterPolicy.createWatermark(waterMarkName);
|
||||
// HWPFHeader header = headerFooterPolicy.getHeader(XWPFHeaderFooterPolicy.DEFAULT);
|
||||
// XWPFParagraph paragraph = header.getParagraphArray(0);
|
||||
// paragraph.getCTP().newCursor();
|
||||
// XmlObject[] xmlobjects = paragraph.getCTP().getRArray(0).getPictArray(0).selectChildren(new QName("urn:schemas-microsoft-com:vml", "shape"));
|
||||
// if (xmlobjects.length > 0) {
|
||||
// com.microsoft.schemas.vml.CTShape ctshape = (com.microsoft.schemas.vml.CTShape) xmlobjects[0];
|
||||
// //设置水印颜色
|
||||
// ctshape.setFillcolor("#828282");
|
||||
// //修改水印样式
|
||||
// ctshape.setStyle(getWaterMarkStyle(ctshape.getStyle(), 23) + ";rotation:315");
|
||||
// }
|
||||
// ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
// try {
|
||||
// doc.write(out);
|
||||
// } finally {
|
||||
// out.close();
|
||||
// }
|
||||
// out.writeTo(new BufferedOutputStream(new FileOutputStream(outputSrc)));
|
||||
// }
|
||||
|
||||
/** |
||||
* word文件添加文字水印 |
||||
* |
||||
* @param fileData 原始文件字节数组 |
||||
* @param outputSrc 文件输出路径 |
||||
* @param waterMarkName 水印内容 |
||||
*/ |
||||
private static void addWordWaterMark(byte[] fileData, String outputSrc, String waterMarkName) throws Exception { |
||||
InputStream input = new ByteArrayInputStream(fileData); |
||||
XWPFDocument doc = new XWPFDocument(input); |
||||
XWPFHeaderFooterPolicy headerFooterPolicy = doc.createHeaderFooterPolicy(); |
||||
//添加文字水印
|
||||
headerFooterPolicy.createWatermark(waterMarkName); |
||||
XWPFHeader header = headerFooterPolicy.getHeader(XWPFHeaderFooterPolicy.DEFAULT); |
||||
XWPFParagraph paragraph = header.getParagraphArray(0); |
||||
paragraph.getCTP().newCursor(); |
||||
XmlObject[] xmlobjects = paragraph.getCTP().getRArray(0).getPictArray(0).selectChildren(new QName("urn:schemas-microsoft-com:vml", "shape")); |
||||
if (xmlobjects.length > 0) { |
||||
com.microsoft.schemas.vml.CTShape ctshape = (com.microsoft.schemas.vml.CTShape) xmlobjects[0]; |
||||
//设置水印颜色
|
||||
ctshape.setFillcolor("#828282"); |
||||
//修改水印样式
|
||||
ctshape.setStyle(getWaterMarkStyle(ctshape.getStyle(), 23) + ";rotation:315"); |
||||
} |
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
||||
try { |
||||
doc.write(out); |
||||
} finally { |
||||
out.close(); |
||||
} |
||||
out.writeTo(new BufferedOutputStream(new FileOutputStream(outputSrc))); |
||||
} |
||||
|
||||
/** |
||||
* 设置水印格式 |
||||
* word |
||||
* |
||||
* @param styleStr |
||||
* @param height |
||||
* @return |
||||
*/ |
||||
public static String getWaterMarkStyle(String styleStr, double height) { |
||||
Pattern p = Pattern.compile(";"); |
||||
String[] strs = p.split(styleStr); |
||||
for (String str : strs) { |
||||
if (str.startsWith("height:")) { |
||||
String heightStr = "height:" + height + "pt"; |
||||
styleStr = styleStr.replace(str, heightStr); |
||||
break; |
||||
} |
||||
} |
||||
return styleStr; |
||||
} |
||||
} |
After Width: | Height: | Size: 328 B |
@ -0,0 +1,8 @@
|
||||
Plugin-ifhd=Watermark Plugin |
||||
Plugin-ifhd_Group=Watermark Plugin |
||||
Plugin-ifhd_Config_UriBase=Uri Base |
||||
Plugin-ifhd_Config_UriBase_Description=Uri Base |
||||
Plugin-ifhd_Licence_Expired=Watermark Plugin Licence Expired |
||||
Plugin-ifhd_Engine_Finish_Export=Has been exported |
||||
Plugin-ifhd_Excel_Stream_Export=Excel streaming export |
||||
Plugin-ifhd_Excel_Stream_Export_Layer=Streaming export supports line engine |
@ -0,0 +1,8 @@
|
||||
Plugin-ifhd=Watermark Plugin |
||||
Plugin-ifhd_Group=Watermark Plugin |
||||
Plugin-ifhd_Config_UriBase=Uri Base |
||||
Plugin-ifhd_Config_UriBase_Description=Uri Base |
||||
Plugin-ifhd_Licence_Expired=Watermark Plugin Licence Expired |
||||
Plugin-ifhd_Engine_Finish_Export=Has been exported |
||||
Plugin-ifhd_Excel_Stream_Export=Excel streaming export |
||||
Plugin-ifhd_Excel_Stream_Export_Layer=Streaming export supports line engine |
@ -0,0 +1,8 @@
|
||||
Plugin-ifhd=\u6C34\u5370\u63D2\u4EF6 |
||||
Plugin-ifhd_Group=\u6C34\u5370\u63D2\u4EF6 |
||||
Plugin-ifhd_Config_UriBase=jwt\u6821\u9A8C\u63A5\u53E3\u5730\u5740 |
||||
Plugin-ifhd_Config_UriBase_Description=jwt\u6821\u9A8C\u63A5\u53E3\u5730\u5740 |
||||
Plugin-ifhd_Licence_Expired=\u6C34\u5370\u63D2\u4EF6\u8BB8\u53EF\u8FC7\u671F |
||||
Plugin-ifhd_Engine_Finish_Export=\u5DF2\u7ECF\u5BFC\u51FA\u7ED3\u675F |
||||
Plugin-ifhd_Excel_Stream_Export=Excel\u6D41\u5F0F\u5BFC\u51FA |
||||
Plugin-ifhd_Excel_Stream_Export_Layer=\u6D41\u5F0F\u5BFC\u51FA\u652F\u6301\u884C\u5F0F\u5F15\u64CE |
Loading…
Reference in new issue