本帖最后由 lin666 于 2019-10-24 17:11 编辑
这边是这么处理的:把整个workbook转换为PDF然后根据每个sheet遍历居中打印,打印取每张表的打印区域(这个在原表上已经设置好)。像这样:
然后打印的时候发现上面那张表不居中效果如下:
正常表打印效果应该如下:
注:虽然是遍历sheet,但是一楼里只有第一张表格有这个问题,所以只截这部分的图。
相关代码如下:
print(e) {
let self = this;
var serializationOption = {
}
var jsonString = JSON.stringify(self.spread.toJSON(serializationOption));
var jsonOptions = {
}
let printSpread = new GC.Spread.Sheets.Workbook();
printSpread.fromJSON(JSON.parse(jsonString), jsonOptions);
let deleteColumnNum;
for(let sheetIndex = 0;sheetIndex < printSpread.getSheetCount()-1;sheetIndex++){
let sheet = printSpread.getSheet(sheetIndex);
if(条件){
deleteColumnNum = 1;
this.setPrintInfo(sheet, deleteColumnNum);
}else{
deleteColumnNum = 3;
this.setPrintInfo(sheet, deleteColumnNum);
}
}
printSpread.savePDF(function(blob) {
window.open(URL.createObjectURL(blob))
}, function(error) {
console.log(error);
}, {
title: 'Print',
});
}
setPrintInfo(sheet, deleteColumnNum) {
var printInfo = sheet.printInfo();
printInfo.paperSize(new GC.Spread.Sheets.Print.PaperSize(GC.Spread.Sheets.Print.PaperKind.a4));
printInfo.margin({ top: 0, bottom: 0, left: 0, right: 0, header: 0, footer: 0 });
printInfo.showColumnHeader(GC.Spread.Sheets.Print.PrintVisibilityType.hide);//获取或设置是否打印列标题。
printInfo.showRowHeader(GC.Spread.Sheets.Print.PrintVisibilityType.hide);
if(deleteColumnNum === 1){
printInfo.orientation(GC.Spread.Sheets.Print.PrintPageOrientation.landscape);//打印的页面方向。portrait纵 landscape
}else{
printInfo.orientation(GC.Spread.Sheets.Print.PrintPageOrientation.portrait);//打印的页面方向。portrait纵 landscape
}
printInfo.centering(GC.Spread.Sheets.Print.PrintCentering.both);//打印页面的居中方式。
//是否打印控件的外边框
printInfo.showBorder(false);
//是否打印网格线(默认打印)
printInfo.showGridLine(false);
printInfo.zoomFactor(0.90);
}
用的是angular
|