spreadJs V14.0.9
场景描述:
在打印的时候,生成一个新的sheet页,将同一workbook下的其它sheet页复制合并到新sheet页中新生成的sheet如下图所示:
问题描述:
在打印的时候,预览发现有些地方无数据
请问是什么原因?
代码如下:
printInfo.js 文件
- /**打印相关:新建汇总sheet页、打印 */
- import GC from "@grapecity/spread-sheets";
- import {print} from "@grapecity/spread-sheets-print";
- /**
- * 新建汇总sheet页
- * @param {spread} spread
- * @param {Number} colCount
- * @returns sheet
- */
- export function createSummarySheet(spread, colCount) {
- let sheetCount = spread.getSheetCount();
- spread.suspendPaint();
- let summarySheet = new GC.Spread.Sheets.Worksheet("汇总");
- summarySheet.setColumnCount(colCount);
- for (let col = 0; col < colCount; col++) {
- summarySheet.setColumnWidth(col, 78);
- }
- spread.addSheet(sheetCount + 1, summarySheet);
- spread.resumePaint();
- return summarySheet;
- }
- /**
- * 复制其它sheet内容至汇总sheet, 公共sheet页除外
- * @param {spread} spread
- * @param {sheet} summarySheet 汇总sheet页
- * @param {Boolean} excludeTitle true:排除folderno、title
- */
- export function copySheetsDataToSummarySheet(spread, summarySheet, excludeTitle) {
- let sheets = spread.sheets;
- let sheetCount = spread.getSheetCount();
- let fromRangeRowIndex = excludeTitle ? 2 : 0,
- toRangeBeginRowIndex = 0;
- spread.suspendPaint();
- for (let i = 0; i < sheetCount; i++) {
- let sheet = sheets[i];
- if (sheet.visible() && sheet.name() !== summarySheet.name()) {
- let rowCount = sheet.getRowCount();
- let colCount = sheet.getColumnCount();
- let showTitle = `${sheet.tag()}-${sheet.name()}`;
- setSheetShowTitle(summarySheet, showTitle, toRangeBeginRowIndex, colCount);
- let fromRange = [new GC.Spread.Sheets.Range(fromRangeRowIndex, 0, rowCount-fromRangeRowIndex, colCount)];
- let toRanges = [new GC.Spread.Sheets.Range(toRangeBeginRowIndex+1, 0, rowCount-fromRangeRowIndex, colCount)];
- if (sheet.tag() === "Common") {
- fromRange = commonSheetFromRange(sheet, rowCount, colCount)
- }
- spread.commandManager().execute({
- cmd: "clipboardPaste",
- sheetName: summarySheet.name(),
- fromSheet: sheet,
- fromRanges: fromRange,
- pastedRanges: toRanges,
- isCutting: false,
- clipboardText: "",
- pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.valuesAndFormatting,
- });
- toRangeBeginRowIndex += (rowCount - fromRangeRowIndex);
- }
- }
- summarySheet.setRowCount(toRangeBeginRowIndex + 3)
- spread.resumePaint();
- }
- function setSheetShowTitle(summarySheet, showTitle, toRangeBeginRowIndex, colCount) {
- summarySheet.addSpan(toRangeBeginRowIndex, 0, 1, colCount);
- summarySheet.setValue(toRangeBeginRowIndex, 0, showTitle);
- }
- function commonSheetFromRange(commonSheet, rowCount, colCount) {
- let beginCol = !commonSheet.getColumnVisible(0) ? 1 : 0;
- let fromRange = [new GC.Spread.Sheets.Range(0, beginCol, rowCount, colCount-beginCol)];
- return fromRange;
- }
- /**
- * 通过创建临时spread表单
- * @param {*} spread
- */
- export function printSheets(spread) {
- let printIndex = spread.getSheetCount()-1;
- let printSheet = spread.sheets[printIndex];
- console.log(printSheet.name());
- try {
- let printInfo = printSheet.printInfo();
- printInfo.paperSize(new GC.Spread.Sheets.Print.PaperSize(GC.Spread.Sheets.Print.PaperKind.a4));
- printInfo.centering(GC.Spread.Sheets.Print.PrintCentering.horizontal)
- printInfo.showRowHeader(GC.Spread.Sheets.Print.PrintVisibilityType.hide);
- printInfo.showColumnHeader(GC.Spread.Sheets.Print.PrintVisibilityType.hide);
- // printInfo.zoomFactor(1.2);
- // printInfo.paperSize(new GC.Spread.Sheets.Print.PaperSize(800, 1200));
- // printInfo.bestFitColumns(true);
- // printInfo.bestFitRows(true);
- spread.print(printIndex);
- } catch (error) {
- console.log("print err:", error);
- }
- finally {
- // spread.removeSheet(printIndex)
- }
- }
复制代码
调用printInfo.js进行打印:
print() {
let spread = this.$store.state.spread;
let summarySheet = createSummarySheet(spread, 11);
copySheetsDataToSummarySheet(spread, summarySheet, true);
printSheets(spread)
},
|
-
|