21 changed files with 1110 additions and 1 deletions
@ -1,3 +1,6 @@
|
||||
# open-JSD-8649 |
||||
|
||||
JSD-8649 开源任务材料 |
||||
JSD-8649 导出文件水印(不支持WORD) 开源任务材料\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
Binary file not shown.
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.fr.plugin.ws.exp.xlsx</id> |
||||
<name><![CDATA[水印导出]]></name> |
||||
<active>yes</active> |
||||
<version>1.1.3</version> |
||||
<group>bi</group> |
||||
<bi-env-version>5.1.14~5.2</bi-env-version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2021-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[]]></description> |
||||
<change-notes><![CDATA[ |
||||
]]></change-notes> |
||||
|
||||
<lifecycle-monitor class="com.fr.plugin.WmLifeCycleMonitor"/> |
||||
<extra-report> |
||||
<ExcelExportAppProvider class="com.fr.plugin.excel.fr.provider.PageExportProvider"/> |
||||
<ExcelExportAppProvider class="com.fr.plugin.excel.fr.provider.SimpleExportProvider"/> |
||||
<ExcelExportAppProvider class="com.fr.plugin.excel.fr.provider.PageToSheetExportProvider"/> |
||||
</extra-report> |
||||
|
||||
<extra-core> |
||||
<ExcelRowCreatorProvider class="com.fr.plugin.excel.bi.NewWorkBookRowCreator"/> |
||||
<JavaScriptFileHandler class="com.fr.plugin.JSFileLoader"/> |
||||
</extra-core> |
||||
<function-recorder class="com.fr.plugin.JSFileLoader"/> |
||||
</plugin> |
@ -0,0 +1,21 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.stable.EncodeConstants; |
||||
import com.fr.stable.fun.impl.AbstractJavaScriptFileHandler; |
||||
|
||||
/** |
||||
* 定义该插件要引入的公用js |
||||
*/ |
||||
public class JSFileLoader extends AbstractJavaScriptFileHandler { |
||||
@Override |
||||
public String[] pathsForFiles() { |
||||
return new String[]{ |
||||
"/com/fr/plugin/js/hideprint.js" |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public String encode() { |
||||
return EncodeConstants.ENCODING_UTF_8; |
||||
} |
||||
} |
@ -0,0 +1,49 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.decision.webservice.bean.security.WatermarkBean; |
||||
import com.fr.decision.webservice.v10.security.SecurityService; |
||||
import com.fr.io.collection.ExportCollection; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.plugin.excel.ExAppExporter; |
||||
import com.fr.plugin.transform.ExecuteFunctionRecord; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.web.core.ReportSessionIDInfor; |
||||
import com.fr.web.core.reserve.DefaultExportExtension; |
||||
import com.fr.web.core.reserve.ExportFactory; |
||||
import com.fr.web.core.reserve.Operate; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
@FunctionRecorder |
||||
public class WmExportProcessor extends DefaultExportExtension { |
||||
@Override |
||||
@ExecuteFunctionRecord |
||||
public ExportCollection createCollection(HttpServletRequest req, HttpServletResponse res, |
||||
ReportSessionIDInfor sessionIDInfor, String format, |
||||
String fileName, boolean isEmbed) throws Exception { |
||||
Operate operate = ExportFactory.getOperate(format.toLowerCase()); |
||||
if(StringUtils.equals("image",format)){ |
||||
res.setHeader("Content-Disposition", "attachment;filename="+fileName+".png"); |
||||
}else{ |
||||
res.setHeader("Content-Disposition", "attachment;filename="+fileName+"."+format); |
||||
} |
||||
if (StringUtils.equals(format, "excel")) { |
||||
SecurityService securityService = SecurityService.getInstance(); |
||||
WatermarkBean parsedWatermarkBean = securityService.getParsedWatermarkBean(req); |
||||
if (StringUtils.isNotBlank(parsedWatermarkBean.getText())) { |
||||
if (operate != null) { |
||||
//先获取到真的AppExporter 然后构造我们自己的导出器
|
||||
ExportCollection exportCollection = operate.newExportCollection(req, res, sessionIDInfor, fileName); |
||||
AppExporter exporter = exportCollection.getExporter(); |
||||
ExAppExporter exAppExporter = new ExAppExporter(exporter, parsedWatermarkBean); |
||||
exportCollection.setExporter(exAppExporter); |
||||
return exportCollection; |
||||
} |
||||
} |
||||
} |
||||
ExportCollection exportCollection = operate.newExportCollection(req, res, sessionIDInfor, fileName); |
||||
return exportCollection; |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
public class WmLifeCycleMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
public void afterRun(PluginContext pluginContext) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,89 @@
|
||||
package com.fr.plugin.excel; |
||||
|
||||
import com.fr.decision.webservice.bean.security.WatermarkBean; |
||||
import com.fr.io.exporter.AbstractAppExporter; |
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.plugin.ws.wapper.WsUtils; |
||||
import com.fr.third.v2.org.apache.poi.POIXMLDocumentPart; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.PackagePartName; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.PackageRelationship; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.TargetMode; |
||||
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 java.io.*; |
||||
|
||||
public class ExAppExporter extends AbstractAppExporter { |
||||
AppExporter realExporter; |
||||
WatermarkBean parsedWatermarkBean; |
||||
|
||||
|
||||
public ExAppExporter(AppExporter realExporter, WatermarkBean parsedWatermarkBean) { |
||||
this.realExporter = realExporter; |
||||
this.parsedWatermarkBean = parsedWatermarkBean; |
||||
} |
||||
|
||||
// @Override
|
||||
// public void export(OutputStream orginOutputStream, ResultWorkBook resultWorkBook) throws Exception {
|
||||
// //先用真的导出器把resultWorkBook 导出成excel 我们获取二进制再加工
|
||||
// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(4096);
|
||||
// File tempFile = File.createTempFile("ExportExcel", ".xlsx");
|
||||
// FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
|
||||
// realExporter.export(fileOutputStream, resultWorkBook);
|
||||
// byte[] bytes = byteArrayOutputStream.toByteArray();
|
||||
// ByteArrayInputStream in = new ByteArrayInputStream(bytes);
|
||||
// //加水印
|
||||
// XSSFWorkbook workbook = new XSSFWorkbook(in);
|
||||
// byte[] watterMarker = WsUtils.getWatterMarker(parsedWatermarkBean);
|
||||
// int pictureIdx = workbook.addPicture(watterMarker, Workbook.PICTURE_TYPE_PNG);
|
||||
// POIXMLDocumentPart poixmlDocumentPart = workbook.getAllPictures().get(pictureIdx);
|
||||
// for (int i = 0; i < workbook.getNumberOfSheets(); i++) {//获取每个Sheet表
|
||||
// XSSFSheet sheet = workbook.getSheetAt(i);
|
||||
// PackagePartName ppn = poixmlDocumentPart.getPackagePart().getPartName();
|
||||
// String relType = XSSFRelation.IMAGES.getRelation();
|
||||
// PackageRelationship pr = sheet.getPackagePart().addRelationship(ppn, TargetMode.INTERNAL, relType, null);
|
||||
// sheet.getCTWorksheet().addNewPicture().setId(pr.getId());
|
||||
// }
|
||||
// workbook.write(orginOutputStream);
|
||||
// FineLoggerFactory.getLogger().info("excel导出加水印成功");
|
||||
// }
|
||||
|
||||
@Override |
||||
public void export(OutputStream orginOutputStream, ResultWorkBook resultWorkBook) throws Exception { |
||||
//先存到临时文件
|
||||
File tempFile = File.createTempFile("ExportExcel", ".xlsx"); |
||||
FileOutputStream fileOutputStream = new FileOutputStream(tempFile); |
||||
realExporter.export(fileOutputStream, resultWorkBook); |
||||
//用SXSSFWorkbook 读取出来处理
|
||||
SXSSFWorkbook workbook = new SXSSFWorkbook(new XSSFWorkbook(tempFile)); |
||||
//获取XSSFWorkbook来加水印
|
||||
XSSFWorkbook xssfWorkbook = workbook.getXSSFWorkbook(); |
||||
byte[] watterMarker = WsUtils.getWatterMarker(parsedWatermarkBean); |
||||
int pictureIdx = workbook.addPicture(watterMarker, Workbook.PICTURE_TYPE_PNG); |
||||
POIXMLDocumentPart poixmlDocumentPart = xssfWorkbook.getAllPictures().get(pictureIdx); |
||||
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {//获取每个Sheet表
|
||||
XSSFSheet sheet = xssfWorkbook.getSheetAt(i); |
||||
PackagePartName ppn = poixmlDocumentPart.getPackagePart().getPartName(); |
||||
String relType = XSSFRelation.IMAGES.getRelation(); |
||||
PackageRelationship pr = sheet.getPackagePart().addRelationship(ppn, TargetMode.INTERNAL, relType, null); |
||||
sheet.getCTWorksheet().addNewPicture().setId(pr.getId()); |
||||
} |
||||
//写回原始导出流
|
||||
workbook.write(orginOutputStream); |
||||
workbook.dispose(); |
||||
workbook.close(); |
||||
FineLoggerFactory.getLogger().info("--excel导出加水印成功"); |
||||
//删除临时文件
|
||||
if (tempFile.exists() &&tempFile.canWrite()) { |
||||
tempFile.delete(); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,107 @@
|
||||
package com.fr.plugin.excel; |
||||
|
||||
import com.finebi.dashboard.api.service.export.TableRangeAddress; |
||||
import com.finebi.dashboard.api.service.export.TableRow; |
||||
import com.finebi.dashboard.api.service.export.provider.WorkbookRowCreator; |
||||
import com.finebi.dashboard.impl.service.export.creator.sheet.ExcelTableRow; |
||||
import com.finebi.dashboard.impl.service.export.monitor.ExcelBuildMonitor; |
||||
import com.finebi.dashboard.impl.service.export.monitor.ExcelBuildMonitorImpl; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Row; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Sheet; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Workbook; |
||||
import com.fr.third.v2.org.apache.poi.ss.util.CellRangeAddress; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
public class MyExcelWorkbookRowCreator implements WorkbookRowCreator { |
||||
Map<Integer, Sheet> sheetMap; |
||||
private Workbook workbook; |
||||
private String sheetName; |
||||
private int sheetMaxRow = 1048575; |
||||
private ExcelBuildMonitor monitor = new ExcelBuildMonitorImpl(); |
||||
|
||||
public MyExcelWorkbookRowCreator(Workbook workBook, String sheetName) { |
||||
this.workbook = workBook; |
||||
this.sheetName = sheetName; |
||||
this.init(); |
||||
} |
||||
|
||||
private void init() { |
||||
this.sheetMap = new HashMap(); |
||||
} |
||||
|
||||
private Sheet getExcelSheet(int rowIndex) { |
||||
int sheetIndex = this.getSheetIndex(rowIndex); |
||||
if (!this.sheetMap.containsKey(sheetIndex)) { |
||||
Sheet sheet; |
||||
if (sheetIndex == 0) { |
||||
sheet = this.workbook.createSheet(this.sheetName); |
||||
} else { |
||||
sheet = this.workbook.createSheet(this.sheetName + "_" + sheetIndex); |
||||
} |
||||
|
||||
this.sheetMap.put(sheetIndex, sheet); |
||||
} |
||||
|
||||
return (Sheet)this.sheetMap.get(sheetIndex); |
||||
} |
||||
|
||||
private int getSheetIndex(int rowIndex) { |
||||
return rowIndex / this.sheetMaxRow; |
||||
} |
||||
|
||||
private int getRealRowIndex(int rowIndex) { |
||||
return rowIndex % this.sheetMaxRow; |
||||
} |
||||
|
||||
private Row createExcelRow(int rownum) { |
||||
Sheet sheet = this.getExcelSheet(rownum); |
||||
int rindex = this.getRealRowIndex(rownum); |
||||
Row row = sheet.getRow(rindex); |
||||
if (row != null) { |
||||
return row; |
||||
} else { |
||||
this.monitor.monitorAddRow(); |
||||
return sheet.createRow(rindex); |
||||
} |
||||
} |
||||
|
||||
private TableRow excelRowToTableRow(Row sxssfRow) { |
||||
return new ExcelTableRow(this.monitor, sxssfRow); |
||||
} |
||||
|
||||
private void addMergedRegion(CellRangeAddress region) { |
||||
int firstRow = region.getFirstRow(); |
||||
int lastRow = region.getLastRow(); |
||||
int firstSheetIndex = this.getSheetIndex(firstRow); |
||||
int lastSheetIndex = this.getSheetIndex(lastRow); |
||||
if (firstSheetIndex == lastSheetIndex) { |
||||
Sheet sheet = this.getExcelSheet(firstRow); |
||||
CellRangeAddress rangeAddress = new CellRangeAddress(this.getRealRowIndex(firstRow), this.getRealRowIndex(lastRow), region.getFirstColumn(), region.getLastColumn()); |
||||
sheet.addMergedRegion(rangeAddress); |
||||
} |
||||
|
||||
} |
||||
|
||||
public TableRow createRow(int rowNum) { |
||||
Row sxssfRow = this.createExcelRow(rowNum); |
||||
return this.excelRowToTableRow(sxssfRow); |
||||
} |
||||
|
||||
public void addMergedRegion(TableRangeAddress region) { |
||||
CellRangeAddress address = new CellRangeAddress(region.getFirstRowIndex(), region.getLastRowIndex(), region.getFirstColIndex(), region.getLastColIndex()); |
||||
this.addMergedRegion(address); |
||||
} |
||||
|
||||
public TableRow getRow(int rowNum) { |
||||
Row row = this.getExcelRow(rowNum); |
||||
return row != null ? this.excelRowToTableRow(row) : null; |
||||
} |
||||
|
||||
public Row getExcelRow(int rowNum) { |
||||
Sheet sheet = this.getExcelSheet(rowNum); |
||||
int realIndex = this.getRealRowIndex(rowNum); |
||||
return sheet.getRow(realIndex); |
||||
} |
||||
} |
@ -0,0 +1,153 @@
|
||||
package com.fr.plugin.excel; |
||||
|
||||
import com.finebi.dashboard.api.service.export.TableRangeAddress; |
||||
import com.finebi.dashboard.api.service.export.TableRow; |
||||
import com.finebi.dashboard.api.service.export.provider.WorkbookRowCreator; |
||||
import com.finebi.dashboard.impl.service.export.creator.sheet.ExcelTableRow; |
||||
import com.finebi.dashboard.impl.service.export.monitor.ExcelBuildMonitor; |
||||
import com.finebi.dashboard.impl.service.export.monitor.ExcelBuildMonitorImpl; |
||||
import com.fr.decision.webservice.bean.security.WatermarkBean; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.ws.wapper.WsUtils; |
||||
import com.fr.third.v2.org.apache.poi.POIXMLDocumentPart; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.PackagePartName; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.PackageRelationship; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.TargetMode; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Row; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Sheet; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Workbook; |
||||
import com.fr.third.v2.org.apache.poi.ss.util.CellRangeAddress; |
||||
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 java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
public class NewExcelWorkbookRowCreator implements WorkbookRowCreator { |
||||
Map<Integer, Sheet> sheetMap; |
||||
private Workbook workbook; |
||||
private XSSFWorkbook xssfWorkbook; |
||||
private String sheetName; |
||||
private int sheetMaxRow = 1048575; |
||||
private ExcelBuildMonitor monitor = new ExcelBuildMonitorImpl(); |
||||
private POIXMLDocumentPart poixmlDocumentPart; |
||||
private boolean isSxs; |
||||
|
||||
public NewExcelWorkbookRowCreator(WatermarkBean parsedWatermarkBean, SXSSFWorkbook workBook, String sheetName) { |
||||
isSxs = true; |
||||
this.workbook = workBook; |
||||
this.xssfWorkbook = workBook.getXSSFWorkbook(); |
||||
this.sheetName = sheetName; |
||||
this.init(); |
||||
byte[] watterMarker = WsUtils.getWatterMarker(parsedWatermarkBean); |
||||
int pictureIdx = workbook.addPicture(watterMarker, Workbook.PICTURE_TYPE_PNG); |
||||
poixmlDocumentPart = xssfWorkbook.getAllPictures().get(pictureIdx); |
||||
} |
||||
|
||||
public NewExcelWorkbookRowCreator(WatermarkBean parsedWatermarkBean, XSSFWorkbook workBook, String sheetName) { |
||||
isSxs = false; |
||||
this.workbook = workBook; |
||||
this.xssfWorkbook = workBook; |
||||
this.sheetName = sheetName; |
||||
this.init(); |
||||
byte[] watterMarker = WsUtils.getWatterMarker(parsedWatermarkBean); |
||||
int pictureIdx = workbook.addPicture(watterMarker, Workbook.PICTURE_TYPE_PNG); |
||||
poixmlDocumentPart = xssfWorkbook.getAllPictures().get(pictureIdx); |
||||
} |
||||
|
||||
private void init() { |
||||
this.sheetMap = new HashMap(); |
||||
} |
||||
|
||||
private Sheet getExcelSheet(int rowIndex) { |
||||
int sheetIndex = this.getSheetIndex(rowIndex); |
||||
if (!this.sheetMap.containsKey(sheetIndex)) { |
||||
Sheet sheet; |
||||
XSSFSheet wssheet; |
||||
String sheetName=""; |
||||
if (sheetIndex == 0) { |
||||
sheetName= this.sheetName; |
||||
} else { |
||||
sheetName=this.sheetName + "_" + sheetIndex; |
||||
} |
||||
//先通过SXSSFWorkbook 创建这个sheet
|
||||
sheet = this.workbook.createSheet(sheetName); |
||||
if (isSxs) { |
||||
//如果是SXSSFWorkbook表格,先拿他的XSSFWorkbook获取他真实的
|
||||
wssheet=this.xssfWorkbook.getSheet(sheetName); |
||||
}else{ |
||||
wssheet = (XSSFSheet) sheet; |
||||
} |
||||
//加水印
|
||||
PackagePartName ppn = poixmlDocumentPart.getPackagePart().getPartName(); |
||||
String relation = XSSFRelation.IMAGES.getRelation(); |
||||
PackageRelationship pr = wssheet.getPackagePart().addRelationship(ppn, TargetMode.INTERNAL, relation, null); |
||||
wssheet.getCTWorksheet().addNewPicture().setId(pr.getId()); |
||||
FineLoggerFactory.getLogger().error("添加sheet{}并 添加水印成功", sheetIndex); |
||||
//加水印结束
|
||||
this.sheetMap.put(sheetIndex, sheet); |
||||
} |
||||
|
||||
return (Sheet) this.sheetMap.get(sheetIndex); |
||||
} |
||||
|
||||
private int getSheetIndex(int rowIndex) { |
||||
return rowIndex / this.sheetMaxRow; |
||||
} |
||||
|
||||
private int getRealRowIndex(int rowIndex) { |
||||
return rowIndex % this.sheetMaxRow; |
||||
} |
||||
|
||||
private Row createExcelRow(int rownum) { |
||||
Sheet sheet = this.getExcelSheet(rownum); |
||||
int rindex = this.getRealRowIndex(rownum); |
||||
Row row = sheet.getRow(rindex); |
||||
if (row != null) { |
||||
return row; |
||||
} else { |
||||
this.monitor.monitorAddRow(); |
||||
return sheet.createRow(rindex); |
||||
} |
||||
} |
||||
|
||||
private TableRow excelRowToTableRow(Row sxssfRow) { |
||||
return new ExcelTableRow(this.monitor, sxssfRow); |
||||
} |
||||
|
||||
private void addMergedRegion(CellRangeAddress region) { |
||||
int firstRow = region.getFirstRow(); |
||||
int lastRow = region.getLastRow(); |
||||
int firstSheetIndex = this.getSheetIndex(firstRow); |
||||
int lastSheetIndex = this.getSheetIndex(lastRow); |
||||
if (firstSheetIndex == lastSheetIndex) { |
||||
Sheet sheet = this.getExcelSheet(firstRow); |
||||
CellRangeAddress rangeAddress = new CellRangeAddress(this.getRealRowIndex(firstRow), this.getRealRowIndex(lastRow), region.getFirstColumn(), region.getLastColumn()); |
||||
sheet.addMergedRegion(rangeAddress); |
||||
} |
||||
|
||||
} |
||||
|
||||
public TableRow createRow(int rowNum) { |
||||
Row sxssfRow = this.createExcelRow(rowNum); |
||||
return this.excelRowToTableRow(sxssfRow); |
||||
} |
||||
|
||||
public void addMergedRegion(TableRangeAddress region) { |
||||
CellRangeAddress address = new CellRangeAddress(region.getFirstRowIndex(), region.getLastRowIndex(), region.getFirstColIndex(), region.getLastColIndex()); |
||||
this.addMergedRegion(address); |
||||
} |
||||
|
||||
public TableRow getRow(int rowNum) { |
||||
Row row = this.getExcelRow(rowNum); |
||||
return row != null ? this.excelRowToTableRow(row) : null; |
||||
} |
||||
|
||||
public Row getExcelRow(int rowNum) { |
||||
Sheet sheet = this.getExcelSheet(rowNum); |
||||
int realIndex = this.getRealRowIndex(rowNum); |
||||
return sheet.getRow(realIndex); |
||||
} |
||||
} |
@ -0,0 +1,45 @@
|
||||
package com.fr.plugin.excel; |
||||
|
||||
import com.finebi.dashboard.api.service.export.ExportContext; |
||||
import com.finebi.dashboard.api.service.export.provider.WorkbookRowCreator; |
||||
import com.finebi.provider.api.export.AbstractExcelRowCreatorProvider; |
||||
import com.fr.decision.webservice.bean.security.WatermarkBean; |
||||
import com.fr.decision.webservice.v10.security.SecurityService; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.third.springframework.web.context.request.RequestContextHolder; |
||||
import com.fr.third.springframework.web.context.request.ServletRequestAttributes; |
||||
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.XSSFWorkbook; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
public class NewWorkBookRowCreator extends AbstractExcelRowCreatorProvider { |
||||
|
||||
|
||||
@Override |
||||
public WorkbookRowCreator getRowCreator(Workbook workbook, String s, ExportContext exportContext) { |
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder |
||||
.getRequestAttributes()).getRequest(); |
||||
if (request != null) { |
||||
try { |
||||
WatermarkBean parsedWatermarkBean = SecurityService.getInstance().getParsedWatermarkBean(request); |
||||
//如果是SXSSFWorkbook 就手动获取getXSSFWorkbook
|
||||
FineLoggerFactory.getLogger().error("水印导出开始"); |
||||
if (workbook instanceof SXSSFWorkbook) { |
||||
FineLoggerFactory.getLogger().error("水印导出开始---SXSSFWorkbook 模式"); |
||||
return new NewExcelWorkbookRowCreator(parsedWatermarkBean, (SXSSFWorkbook) workbook, s); |
||||
} else if (workbook instanceof XSSFWorkbook) { //如果本身就是XSSFWorkbook 就直接用
|
||||
FineLoggerFactory.getLogger().error("水印导出开始+++XSSFWorkbook 模式"); |
||||
return new NewExcelWorkbookRowCreator(parsedWatermarkBean, (XSSFWorkbook) workbook, s); |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error("创建水印导出失败"); |
||||
} |
||||
} |
||||
FineLoggerFactory.getLogger().error("未能获取到请求 使用默认导出程序处理-----"); |
||||
//解析异常的拿不到请求的用默认处理器
|
||||
return new MyExcelWorkbookRowCreator(workbook, s); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,107 @@
|
||||
package com.fr.plugin.excel.bi; |
||||
|
||||
import com.finebi.dashboard.api.service.export.TableRangeAddress; |
||||
import com.finebi.dashboard.api.service.export.TableRow; |
||||
import com.finebi.dashboard.api.service.export.provider.WorkbookRowCreator; |
||||
import com.finebi.dashboard.impl.service.export.creator.sheet.ExcelTableRow; |
||||
import com.finebi.dashboard.impl.service.export.monitor.ExcelBuildMonitor; |
||||
import com.finebi.dashboard.impl.service.export.monitor.ExcelBuildMonitorImpl; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Row; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Sheet; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Workbook; |
||||
import com.fr.third.v2.org.apache.poi.ss.util.CellRangeAddress; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
public class MyExcelWorkbookRowCreator implements WorkbookRowCreator { |
||||
Map<Integer, Sheet> sheetMap; |
||||
private Workbook workbook; |
||||
private String sheetName; |
||||
private int sheetMaxRow = 1048575; |
||||
private ExcelBuildMonitor monitor = new ExcelBuildMonitorImpl(); |
||||
|
||||
public MyExcelWorkbookRowCreator(Workbook workBook, String sheetName) { |
||||
this.workbook = workBook; |
||||
this.sheetName = sheetName; |
||||
this.init(); |
||||
} |
||||
|
||||
private void init() { |
||||
this.sheetMap = new HashMap(); |
||||
} |
||||
|
||||
private Sheet getExcelSheet(int rowIndex) { |
||||
int sheetIndex = this.getSheetIndex(rowIndex); |
||||
if (!this.sheetMap.containsKey(sheetIndex)) { |
||||
Sheet sheet; |
||||
if (sheetIndex == 0) { |
||||
sheet = this.workbook.createSheet(this.sheetName); |
||||
} else { |
||||
sheet = this.workbook.createSheet(this.sheetName + "_" + sheetIndex); |
||||
} |
||||
|
||||
this.sheetMap.put(sheetIndex, sheet); |
||||
} |
||||
|
||||
return (Sheet)this.sheetMap.get(sheetIndex); |
||||
} |
||||
|
||||
private int getSheetIndex(int rowIndex) { |
||||
return rowIndex / this.sheetMaxRow; |
||||
} |
||||
|
||||
private int getRealRowIndex(int rowIndex) { |
||||
return rowIndex % this.sheetMaxRow; |
||||
} |
||||
|
||||
private Row createExcelRow(int rownum) { |
||||
Sheet sheet = this.getExcelSheet(rownum); |
||||
int rindex = this.getRealRowIndex(rownum); |
||||
Row row = sheet.getRow(rindex); |
||||
if (row != null) { |
||||
return row; |
||||
} else { |
||||
this.monitor.monitorAddRow(); |
||||
return sheet.createRow(rindex); |
||||
} |
||||
} |
||||
|
||||
private TableRow excelRowToTableRow(Row sxssfRow) { |
||||
return new ExcelTableRow(this.monitor, sxssfRow); |
||||
} |
||||
|
||||
private void addMergedRegion(CellRangeAddress region) { |
||||
int firstRow = region.getFirstRow(); |
||||
int lastRow = region.getLastRow(); |
||||
int firstSheetIndex = this.getSheetIndex(firstRow); |
||||
int lastSheetIndex = this.getSheetIndex(lastRow); |
||||
if (firstSheetIndex == lastSheetIndex) { |
||||
Sheet sheet = this.getExcelSheet(firstRow); |
||||
CellRangeAddress rangeAddress = new CellRangeAddress(this.getRealRowIndex(firstRow), this.getRealRowIndex(lastRow), region.getFirstColumn(), region.getLastColumn()); |
||||
sheet.addMergedRegion(rangeAddress); |
||||
} |
||||
|
||||
} |
||||
|
||||
public TableRow createRow(int rowNum) { |
||||
Row sxssfRow = this.createExcelRow(rowNum); |
||||
return this.excelRowToTableRow(sxssfRow); |
||||
} |
||||
|
||||
public void addMergedRegion(TableRangeAddress region) { |
||||
CellRangeAddress address = new CellRangeAddress(region.getFirstRowIndex(), region.getLastRowIndex(), region.getFirstColIndex(), region.getLastColIndex()); |
||||
this.addMergedRegion(address); |
||||
} |
||||
|
||||
public TableRow getRow(int rowNum) { |
||||
Row row = this.getExcelRow(rowNum); |
||||
return row != null ? this.excelRowToTableRow(row) : null; |
||||
} |
||||
|
||||
public Row getExcelRow(int rowNum) { |
||||
Sheet sheet = this.getExcelSheet(rowNum); |
||||
int realIndex = this.getRealRowIndex(rowNum); |
||||
return sheet.getRow(realIndex); |
||||
} |
||||
} |
@ -0,0 +1,153 @@
|
||||
package com.fr.plugin.excel.bi; |
||||
|
||||
import com.finebi.dashboard.api.service.export.TableRangeAddress; |
||||
import com.finebi.dashboard.api.service.export.TableRow; |
||||
import com.finebi.dashboard.api.service.export.provider.WorkbookRowCreator; |
||||
import com.finebi.dashboard.impl.service.export.creator.sheet.ExcelTableRow; |
||||
import com.finebi.dashboard.impl.service.export.monitor.ExcelBuildMonitor; |
||||
import com.finebi.dashboard.impl.service.export.monitor.ExcelBuildMonitorImpl; |
||||
import com.fr.decision.webservice.bean.security.WatermarkBean; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.ws.wapper.WsUtils; |
||||
import com.fr.third.v2.org.apache.poi.POIXMLDocumentPart; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.PackagePartName; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.PackageRelationship; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.TargetMode; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Row; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Sheet; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Workbook; |
||||
import com.fr.third.v2.org.apache.poi.ss.util.CellRangeAddress; |
||||
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 java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
public class NewExcelWorkbookRowCreator implements WorkbookRowCreator { |
||||
Map<Integer, Sheet> sheetMap; |
||||
private Workbook workbook; |
||||
private XSSFWorkbook xssfWorkbook; |
||||
private String sheetName; |
||||
private int sheetMaxRow = 1048575; |
||||
private ExcelBuildMonitor monitor = new ExcelBuildMonitorImpl(); |
||||
private POIXMLDocumentPart poixmlDocumentPart; |
||||
private boolean isSxs; |
||||
|
||||
public NewExcelWorkbookRowCreator(WatermarkBean parsedWatermarkBean, SXSSFWorkbook workBook, String sheetName) { |
||||
isSxs = true; |
||||
this.workbook = workBook; |
||||
this.xssfWorkbook = workBook.getXSSFWorkbook(); |
||||
this.sheetName = sheetName; |
||||
this.init(); |
||||
byte[] watterMarker = WsUtils.getWatterMarker(parsedWatermarkBean); |
||||
int pictureIdx = workbook.addPicture(watterMarker, Workbook.PICTURE_TYPE_PNG); |
||||
poixmlDocumentPart = xssfWorkbook.getAllPictures().get(pictureIdx); |
||||
} |
||||
|
||||
public NewExcelWorkbookRowCreator(WatermarkBean parsedWatermarkBean, XSSFWorkbook workBook, String sheetName) { |
||||
isSxs = false; |
||||
this.workbook = workBook; |
||||
this.xssfWorkbook = workBook; |
||||
this.sheetName = sheetName; |
||||
this.init(); |
||||
byte[] watterMarker = WsUtils.getWatterMarker(parsedWatermarkBean); |
||||
int pictureIdx = workbook.addPicture(watterMarker, Workbook.PICTURE_TYPE_PNG); |
||||
poixmlDocumentPart = xssfWorkbook.getAllPictures().get(pictureIdx); |
||||
} |
||||
|
||||
private void init() { |
||||
this.sheetMap = new HashMap(); |
||||
} |
||||
|
||||
private Sheet getExcelSheet(int rowIndex) { |
||||
int sheetIndex = this.getSheetIndex(rowIndex); |
||||
if (!this.sheetMap.containsKey(sheetIndex)) { |
||||
Sheet sheet; |
||||
XSSFSheet wssheet; |
||||
String sheetName=""; |
||||
if (sheetIndex == 0) { |
||||
sheetName= this.sheetName; |
||||
} else { |
||||
sheetName=this.sheetName + "_" + sheetIndex; |
||||
} |
||||
//先通过SXSSFWorkbook 创建这个sheet
|
||||
sheet = this.workbook.createSheet(sheetName); |
||||
if (isSxs) { |
||||
//如果是SXSSFWorkbook表格,先拿他的XSSFWorkbook获取他真实的
|
||||
wssheet=this.xssfWorkbook.getSheet(sheetName); |
||||
}else{ |
||||
wssheet = (XSSFSheet) sheet; |
||||
} |
||||
//加水印
|
||||
PackagePartName ppn = poixmlDocumentPart.getPackagePart().getPartName(); |
||||
String relation = XSSFRelation.IMAGES.getRelation(); |
||||
PackageRelationship pr = wssheet.getPackagePart().addRelationship(ppn, TargetMode.INTERNAL, relation, null); |
||||
wssheet.getCTWorksheet().addNewPicture().setId(pr.getId()); |
||||
FineLoggerFactory.getLogger().error("添加sheet{}并 添加水印成功", sheetIndex); |
||||
//加水印结束
|
||||
this.sheetMap.put(sheetIndex, sheet); |
||||
} |
||||
|
||||
return (Sheet) this.sheetMap.get(sheetIndex); |
||||
} |
||||
|
||||
private int getSheetIndex(int rowIndex) { |
||||
return rowIndex / this.sheetMaxRow; |
||||
} |
||||
|
||||
private int getRealRowIndex(int rowIndex) { |
||||
return rowIndex % this.sheetMaxRow; |
||||
} |
||||
|
||||
private Row createExcelRow(int rownum) { |
||||
Sheet sheet = this.getExcelSheet(rownum); |
||||
int rindex = this.getRealRowIndex(rownum); |
||||
Row row = sheet.getRow(rindex); |
||||
if (row != null) { |
||||
return row; |
||||
} else { |
||||
this.monitor.monitorAddRow(); |
||||
return sheet.createRow(rindex); |
||||
} |
||||
} |
||||
|
||||
private TableRow excelRowToTableRow(Row sxssfRow) { |
||||
return new ExcelTableRow(this.monitor, sxssfRow); |
||||
} |
||||
|
||||
private void addMergedRegion(CellRangeAddress region) { |
||||
int firstRow = region.getFirstRow(); |
||||
int lastRow = region.getLastRow(); |
||||
int firstSheetIndex = this.getSheetIndex(firstRow); |
||||
int lastSheetIndex = this.getSheetIndex(lastRow); |
||||
if (firstSheetIndex == lastSheetIndex) { |
||||
Sheet sheet = this.getExcelSheet(firstRow); |
||||
CellRangeAddress rangeAddress = new CellRangeAddress(this.getRealRowIndex(firstRow), this.getRealRowIndex(lastRow), region.getFirstColumn(), region.getLastColumn()); |
||||
sheet.addMergedRegion(rangeAddress); |
||||
} |
||||
|
||||
} |
||||
|
||||
public TableRow createRow(int rowNum) { |
||||
Row sxssfRow = this.createExcelRow(rowNum); |
||||
return this.excelRowToTableRow(sxssfRow); |
||||
} |
||||
|
||||
public void addMergedRegion(TableRangeAddress region) { |
||||
CellRangeAddress address = new CellRangeAddress(region.getFirstRowIndex(), region.getLastRowIndex(), region.getFirstColIndex(), region.getLastColIndex()); |
||||
this.addMergedRegion(address); |
||||
} |
||||
|
||||
public TableRow getRow(int rowNum) { |
||||
Row row = this.getExcelRow(rowNum); |
||||
return row != null ? this.excelRowToTableRow(row) : null; |
||||
} |
||||
|
||||
public Row getExcelRow(int rowNum) { |
||||
Sheet sheet = this.getExcelSheet(rowNum); |
||||
int realIndex = this.getRealRowIndex(rowNum); |
||||
return sheet.getRow(realIndex); |
||||
} |
||||
} |
@ -0,0 +1,45 @@
|
||||
package com.fr.plugin.excel.bi; |
||||
|
||||
import com.finebi.dashboard.api.service.export.ExportContext; |
||||
import com.finebi.dashboard.api.service.export.provider.WorkbookRowCreator; |
||||
import com.finebi.provider.api.export.AbstractExcelRowCreatorProvider; |
||||
import com.fr.decision.webservice.bean.security.WatermarkBean; |
||||
import com.fr.decision.webservice.v10.security.SecurityService; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.third.springframework.web.context.request.RequestContextHolder; |
||||
import com.fr.third.springframework.web.context.request.ServletRequestAttributes; |
||||
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.XSSFWorkbook; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
public class NewWorkBookRowCreator extends AbstractExcelRowCreatorProvider { |
||||
|
||||
|
||||
@Override |
||||
public WorkbookRowCreator getRowCreator(Workbook workbook, String s, ExportContext exportContext) { |
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder |
||||
.getRequestAttributes()).getRequest(); |
||||
if (request != null) { |
||||
try { |
||||
WatermarkBean parsedWatermarkBean = SecurityService.getInstance().getParsedWatermarkBean(request); |
||||
//如果是SXSSFWorkbook 就手动获取getXSSFWorkbook
|
||||
FineLoggerFactory.getLogger().error("水印导出开始"); |
||||
if (workbook instanceof SXSSFWorkbook) { |
||||
FineLoggerFactory.getLogger().error("水印导出开始---SXSSFWorkbook 模式"); |
||||
return new NewExcelWorkbookRowCreator(parsedWatermarkBean, (SXSSFWorkbook) workbook, s); |
||||
} else if (workbook instanceof XSSFWorkbook) { //如果本身就是XSSFWorkbook 就直接用
|
||||
FineLoggerFactory.getLogger().error("水印导出开始+++XSSFWorkbook 模式"); |
||||
return new NewExcelWorkbookRowCreator(parsedWatermarkBean, (XSSFWorkbook) workbook, s); |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error("创建水印导出失败"); |
||||
} |
||||
} |
||||
FineLoggerFactory.getLogger().error("未能获取到请求 使用默认导出程序处理-----"); |
||||
//解析异常的拿不到请求的用默认处理器
|
||||
return new MyExcelWorkbookRowCreator(workbook, s); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.fr.plugin.excel.fr.exporter; |
||||
|
||||
import com.fr.io.attr.ReportExportAttr; |
||||
import com.fr.io.exporter.PageExcel2007Exporter; |
||||
import com.fr.plugin.ws.wapper.WsUtils; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.third.v2.org.apache.poi.xssf.streaming.SXSSFWorkbook; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Data 2021/10/28 17:06 |
||||
* @Description TODO |
||||
* @Version 10.0 |
||||
**/ |
||||
public class NewPageExcel2007Exporter extends PageExcel2007Exporter { |
||||
|
||||
public NewPageExcel2007Exporter(List list) { |
||||
super(list); |
||||
} |
||||
|
||||
@Override |
||||
protected void innerExportReport(Report report, ReportExportAttr reportExportAttr, String s, SXSSFWorkbook sxssfWorkbook, List list, List list1, int i) throws Exception { |
||||
super.innerExportReport(report, reportExportAttr, s, sxssfWorkbook, list, list1, i); |
||||
WsUtils.addWatterMarker2SXSSFWorkbook(sxssfWorkbook); |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.fr.plugin.excel.fr.exporter; |
||||
|
||||
import com.fr.io.attr.ReportExportAttr; |
||||
import com.fr.io.exporter.PageToSheetExcel2007Exporter; |
||||
import com.fr.plugin.ws.wapper.WsUtils; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.third.v2.org.apache.poi.xssf.streaming.SXSSFWorkbook; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Data 2021/10/28 17:07 |
||||
* @Description TODO |
||||
* @Version 10.0 |
||||
**/ |
||||
public class NewPageToSheetExcel2007Exporter extends PageToSheetExcel2007Exporter { |
||||
|
||||
public NewPageToSheetExcel2007Exporter(List list) { |
||||
super(list); |
||||
} |
||||
|
||||
@Override |
||||
protected void innerExportReport(Report report, ReportExportAttr reportExportAttr, String s, SXSSFWorkbook sxssfWorkbook, List list, List list1, int i) throws Exception { |
||||
super.innerExportReport(report, reportExportAttr, s, sxssfWorkbook, list, list1, i); |
||||
WsUtils.addWatterMarker2SXSSFWorkbook(sxssfWorkbook); |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.fr.plugin.excel.fr.exporter; |
||||
|
||||
import com.fr.decision.webservice.bean.security.WatermarkBean; |
||||
import com.fr.decision.webservice.v10.security.SecurityService; |
||||
import com.fr.io.attr.ReportExportAttr; |
||||
import com.fr.io.exporter.excel.stream.StreamExcel2007Exporter; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.ws.wapper.WsUtils; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.third.springframework.web.context.request.RequestContextHolder; |
||||
import com.fr.third.springframework.web.context.request.ServletRequestAttributes; |
||||
import com.fr.third.v2.org.apache.poi.POIXMLDocumentPart; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.PackagePartName; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.PackageRelationship; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.TargetMode; |
||||
import com.fr.third.v2.org.apache.poi.ss.usermodel.Workbook; |
||||
import com.fr.third.v2.org.apache.poi.xssf.streaming.SXSSFSheet; |
||||
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 javax.servlet.http.HttpServletRequest; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Data 2021/10/28 16:38 |
||||
* @Description TODO |
||||
* @Version 10.0 |
||||
**/ |
||||
public class NewStreamExcel2007Exporter extends StreamExcel2007Exporter { |
||||
|
||||
public NewStreamExcel2007Exporter(List list) { |
||||
super(list); |
||||
} |
||||
|
||||
@Override |
||||
protected void innerExportReport(Report report, ReportExportAttr reportExportAttr, String s, SXSSFWorkbook sxssfWorkbook, List list, List list1, int i) throws Exception { |
||||
super.innerExportReport(report, reportExportAttr, s, sxssfWorkbook, list, list1, i); |
||||
WsUtils.addWatterMarker2SXSSFWorkbook(sxssfWorkbook); |
||||
} |
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.fr.plugin.excel.fr.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.main.FineBook; |
||||
import com.fr.plugin.excel.fr.exporter.NewPageExcel2007Exporter; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.fun.impl.AbstractExcelExportAppProvider; |
||||
import com.fr.stable.web.SessionProvider; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Data 2021/10/28 17:09 |
||||
* @Description TODO |
||||
* @Version 10.0 |
||||
**/ |
||||
public class PageExportProvider extends AbstractExcelExportAppProvider { |
||||
|
||||
@Override |
||||
public String exportType() { |
||||
return "page"; |
||||
} |
||||
|
||||
@Override |
||||
public AppExporter<Boolean> newAppExporter(ExportCollection exportCollection, ExcelExportType excelExportType, SessionProvider sessionProvider) { |
||||
AppExporter exporter = new NewPageExcel2007Exporter(ReportUtils.getPaperSettingListFromWorkBook((FineBook) sessionProvider.getOriginalObject())); |
||||
exportCollection.setExporter(exporter); |
||||
exportCollection.setRecordType(ReportDeclareRecordType.EXPORT_TYPE_EXCEL_PAGE); |
||||
return exporter; |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.fr.plugin.excel.fr.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.main.FineBook; |
||||
import com.fr.plugin.excel.fr.exporter.NewPageExcel2007Exporter; |
||||
import com.fr.plugin.excel.fr.exporter.NewPageToSheetExcel2007Exporter; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.fun.impl.AbstractExcelExportAppProvider; |
||||
import com.fr.stable.web.SessionProvider; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Data 2021/10/28 17:20 |
||||
* @Description TODO |
||||
* @Version 10.0 |
||||
**/ |
||||
public class PageToSheetExportProvider extends AbstractExcelExportAppProvider { |
||||
|
||||
@Override |
||||
public String exportType() { |
||||
return "sheet"; |
||||
} |
||||
|
||||
@Override |
||||
public AppExporter<Boolean> newAppExporter(ExportCollection exportCollection, ExcelExportType excelExportType, SessionProvider sessionProvider) { |
||||
AppExporter exporter = new NewPageToSheetExcel2007Exporter(ReportUtils.getPaperSettingListFromWorkBook((FineBook) sessionProvider.getOriginalObject())); |
||||
exportCollection.setExporter(exporter); |
||||
exportCollection.setRecordType(ReportDeclareRecordType.EXPORT_TYPE_EXCEL_PAGESHEET); |
||||
return exporter; |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.fr.plugin.excel.fr.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.main.FineBook; |
||||
import com.fr.plugin.excel.fr.exporter.NewPageExcel2007Exporter; |
||||
import com.fr.plugin.excel.fr.exporter.NewStreamExcel2007Exporter; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.fun.impl.AbstractExcelExportAppProvider; |
||||
import com.fr.stable.web.SessionProvider; |
||||
|
||||
/** |
||||
* @Author fr.open |
||||
* @Data 2021/10/28 17:18 |
||||
* @Description TODO |
||||
* @Version 10.0 |
||||
**/ |
||||
public class SimpleExportProvider extends AbstractExcelExportAppProvider { |
||||
|
||||
@Override |
||||
public String exportType() { |
||||
return "simple"; |
||||
} |
||||
|
||||
@Override |
||||
public AppExporter<Boolean> newAppExporter(ExportCollection exportCollection, ExcelExportType excelExportType, SessionProvider sessionProvider) { |
||||
AppExporter exporter = new NewStreamExcel2007Exporter(ReportUtils.getPaperSettingListFromWorkBook((FineBook) sessionProvider.getOriginalObject())); |
||||
exportCollection.setExporter(exporter); |
||||
exportCollection.setRecordType(ReportDeclareRecordType.EXPORT_TYPE_EXCEL_ORIGINAL); |
||||
return exporter; |
||||
} |
||||
} |
@ -0,0 +1,78 @@
|
||||
package com.fr.plugin.ws.wapper; |
||||
|
||||
import com.fr.base.iofile.attr.WatermarkAttr; |
||||
import com.fr.decision.config.WatermarkConfig; |
||||
import com.fr.decision.security.WatermarkData; |
||||
import com.fr.decision.webservice.bean.security.WatermarkBean; |
||||
import com.fr.decision.webservice.v10.security.SecurityService; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.page.WatermarkPainter; |
||||
import com.fr.stable.ImageUtils; |
||||
import com.fr.third.springframework.web.context.request.RequestContextHolder; |
||||
import com.fr.third.springframework.web.context.request.ServletRequestAttributes; |
||||
import com.fr.third.v2.org.apache.poi.POIXMLDocumentPart; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.PackagePartName; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.PackageRelationship; |
||||
import com.fr.third.v2.org.apache.poi.openxml4j.opc.TargetMode; |
||||
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 javax.imageio.ImageIO; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.awt.*; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.FileNotFoundException; |
||||
import java.io.FileOutputStream; |
||||
import java.io.IOException; |
||||
|
||||
public class WsUtils { |
||||
|
||||
public static byte[] getWatterMarker(WatermarkBean parsedWatermarkBean) { |
||||
WatermarkData watermarkData = WatermarkConfig.getInstance().getWatermarkData(); |
||||
WatermarkAttr watermarkAttr = new WatermarkAttr(watermarkData); |
||||
watermarkAttr.setText(parsedWatermarkBean.getText()); |
||||
WatermarkPainter painter = WatermarkPainter.createPainter(watermarkAttr); |
||||
int width=1024 + parsedWatermarkBean.getHorizontalGap(); |
||||
int height=768+ parsedWatermarkBean.getVerticalGap(); |
||||
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
||||
// 背景透明 开始
|
||||
Graphics2D g = bufferedImage.createGraphics(); |
||||
bufferedImage = g.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); |
||||
g.dispose(); |
||||
g = bufferedImage.createGraphics(); |
||||
painter.paint(g, width, height); |
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
||||
ImageUtils.writeImage(bufferedImage, "PNG", byteArrayOutputStream); |
||||
try { |
||||
ImageIO.write(bufferedImage, "PNG", new FileOutputStream("E:\\11.png")); |
||||
} catch (FileNotFoundException e) { |
||||
e.printStackTrace(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
|
||||
return byteArrayOutputStream.toByteArray(); |
||||
} |
||||
|
||||
public static void addWatterMarker2SXSSFWorkbook(SXSSFWorkbook sxssfWorkbook) throws Exception { |
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder |
||||
.getRequestAttributes()).getRequest(); |
||||
if (request == null) { |
||||
FineLoggerFactory.getLogger().error("未能获取到请求 使用默认导出程序处理-----"); |
||||
return; |
||||
} |
||||
WatermarkBean parsedWatermarkBean = SecurityService.getInstance().getParsedWatermarkBean(request); |
||||
byte[] watterMarker = WsUtils.getWatterMarker(parsedWatermarkBean); |
||||
int pictureIdx = sxssfWorkbook.addPicture(watterMarker, Workbook.PICTURE_TYPE_PNG); |
||||
POIXMLDocumentPart poixmlDocumentPart = sxssfWorkbook.getXSSFWorkbook().getAllPictures().get(pictureIdx); |
||||
PackagePartName ppn = poixmlDocumentPart.getPackagePart().getPartName(); |
||||
String relType = XSSFRelation.IMAGES.getRelation(); |
||||
XSSFSheet xssfSheet = sxssfWorkbook.getXSSFWorkbook().getSheetAt(sxssfWorkbook.getNumberOfSheets() - 1); |
||||
PackageRelationship pr = xssfSheet.getPackagePart().addRelationship(ppn, TargetMode.INTERNAL, relType, null); |
||||
xssfSheet.getCTWorksheet().addNewPicture().setId(pr.getId()); |
||||
FineLoggerFactory.getLogger().error("添加sheet{}并 添加水印成功", sxssfWorkbook.getNumberOfSheets()); |
||||
} |
||||
} |
@ -0,0 +1,17 @@
|
||||
; |
||||
function init(){ |
||||
var g=_g(); |
||||
if(g){ |
||||
var word = _g().toolbar.options.items.filter(function (item) { |
||||
return item.xtype === 'excel-menu' |
||||
})[0].options.menu.filter(function (item) { |
||||
return item.src === 'Word' |
||||
})[0]; |
||||
_g().toolbar.options.items.filter(function (item) { |
||||
return item.xtype === 'excel-menu' |
||||
})[0].options.menu.remove(word); |
||||
}else{ |
||||
timer=setTimeout(init,500); |
||||
} |
||||
} |
||||
var timer=setTimeout(init,1000); |
Loading…
Reference in new issue