本帖最后由 sssssss 于 2024-9-14 10:52 编辑
使用
public getScreenshotBlbo() {
return new Promise(function (resolve, reject) {
let sheet = window.spread.getActiveSheet()
let oldPrintInfo = window.sheet.printInfo();
let printInfo = new GC.Spread.Sheets.Print.PrintInfo()
//打印质量大于4时才会生成图片
printInfo.qualityFactor(5)
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)
printInfo.paperSize(new GC.Spread.Sheets.Print.PaperSize(GC.Spread.Sheets.Print.PaperKind.a3))
printInfo.showBorder(false)
printInfo.showGridLine(true)
let selection = window.sheet.getSelections()[0]
printInfo.rowStart(selection.row);
printInfo.rowEnd(selection.row + selection.rowCount - 1);
printInfo.columnStart(selection.col);
printInfo.columnEnd(selection.col + selection.colCount - 1);
printInfo.fitPagesTall(1);
printInfo.fitPagesWide(1);
window.sheet.printInfo(printInfo)
window.spread.bind(GC.Spread.Sheets.Events.BeforePrint + ".screenshot", (s, e) => {
console.log(s,e, 'sdfeefee')
let iframe = e.iframe
let imgs = iframe.contentWindow.document.getElementsByTagName("img")
if (imgs && imgs.length) {
let img = imgs[0]
console.log(img)
let canvas = document.createElement("canvas")
canvas.height = img.naturalHeight
canvas.width = img.naturalWidth
let ctx = canvas.getContext('2d')
if (ctx) {
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img, 0, 0);
for (let i = 0; i <= canvas.height; i += 180) {
for (let j = 0; j <= canvas.width; j += 130) {
ctx.save();
ctx.translate(j, i);
ctx.rotate(-20 * Math.PI / 180);
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.font = '16px Vedana';
ctx.fillText(localStorage.getItem('oa'), 0, 0);
ctx.restore();
}
}
canvas.toBlob((blob) => {
resolve(blob)
// navigator.clipboard.write([
// new ClipboardItem({
// [blob.type]: blob
// })
// ]);
})
e.cancel = true
window.spread.unbind(GC.Spread.Sheets.Events.BeforePrint + ".screenshot")
window.sheet.printInfo(oldPrintInfo)
}
}
})
window.spread.print(window.spread.getActiveSheetIndex());
});
}
这个方法截图,多选里的颜色没有了,如何解决
|
|