Browse Source

增加打印导出的API

pull/22/head
richie 5 years ago
parent
commit
32119af862
  1. 112
      src/main/java/com/fanruan/api/report/PrintKit.java

112
src/main/java/com/fanruan/api/report/PrintKit.java

@ -0,0 +1,112 @@
package com.fanruan.api.report;
import com.fanruan.api.log.LogKit;
import com.fr.base.Margin;
import com.fr.main.FineBook;
import com.fr.page.ClippedPageProvider;
import com.fr.page.PaperSettingProvider;
import com.fr.page.ReportPageProvider;
import com.fr.page.ReportSettingsProvider;
import com.fr.report.cell.CellElement;
import com.fr.report.cell.cellattr.CellGUIAttr;
import com.fr.report.stable.ReportSettings;
import com.fr.stable.Constants;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/9/25
* 报表打印导出相关工具类
*/
public class PrintKit {
private PrintKit() {
}
/**
* 根据模板获取打印/导出的页面设置
*
* @param book 模板
* @return 多个待打印对象的页面设置集合
*/
public static List<PaperSettingProvider> getPaperSettings(FineBook book) {
return PrintKit.getPaperSettings(book, null);
}
/**
* 根据模板获取打印/导出的页面设置
*
* @param book 模板
* @param offsetMargin 偏移量
* @return 多个待打印对象的页面设置集合
*/
public static @Nullable List<PaperSettingProvider> getPaperSettings(FineBook book, Margin offsetMargin) {
if (book == null) {
return null;
}
List<PaperSettingProvider> list = new ArrayList<>();
ReportSettingsProvider reportSettings;
for (int i = 0; i < book.getReportCount(); i++) {
reportSettings = book.getReport(i).getReportSettings();
if (reportSettings == null) {
reportSettings = ReportSettings.DEFAULTSETTINGS;
}
try {
PaperSettingProvider setting = (PaperSettingProvider) reportSettings.getPaperSetting().clone();
Margin margin = setting.getMargin();
/*
* 偏移量topleft为加button right为减
*/
if (offsetMargin != null) {
margin.setTop(margin.getTop().add(offsetMargin.getTop()));
margin.setLeft(margin.getLeft().add(offsetMargin.getLeft()));
margin.setBottom(margin.getBottom().subtract(offsetMargin.getBottom()));
margin.setRight(margin.getRight().subtract(offsetMargin.getRight()));
}
list.add(setting);
} catch (CloneNotSupportedException e) {
LogKit.error(e.getMessage(), e);
break;
}
}
return list;
}
/**
* 选取分页结果对象中可导出的对象如果没有可导出对象会返回null
*
* @param reportPage 分页结果对象
* @return 可导出对象
*/
public static @Nullable ClippedPageProvider pick(ReportPageProvider reportPage) {
if (reportPage == null) {
return null;
}
ClippedPageProvider[] clippers = reportPage.getPages();
if (clippers.length == 1 && clippers[0] != null) {
ClippedPageProvider cp = clippers[0];
cp.deriveResolution(Constants.FR_PAINT_RESOLUTION);
return cp;
}
return null;
}
/**
* 单元格是否可打印/导出典型的如以html格式显示的单元格就是不可打印/导出的
*
* @param cell 单元格
* @return 单元格内容可打印/导出则返回true否则返回false
*/
public static boolean isCellPrintable(CellElement cell) {
if (cell == null) {
return false;
}
CellGUIAttr gui = cell.getCellGUIAttr();
return gui == null || gui.isPrintContent();
}
}
Loading…
Cancel
Save