【发布时间】:2020-12-17 18:47:07
【问题描述】:
我正在使用 GoogleSheets 使用 HTMLService 打印 png/图像文件。我在 modalDialog 中创建了一个带有 img 标签的临时 Iframe 元素,并在加载 IFrame 元素及其图像后调用 IFrame 元素的 contentWindow.print() 函数。 (我没有设置可见性:IFrame 元素的隐藏属性来检查图像是否正在加载。)
但是,我只看到没有任何打印预览的打印机对话框。我在火狐上测试。我错过了什么吗?
[更新] - 我正在使用 Google 应用程序脚本。 performPrint() 在 printJsSource.html 中,openUrl() 在 Code.gs 中。
Inside printJsSource.html
function performPrint(iframeElement, params) {
try {
iframeElement.focus()
// If Edge or IE, try catch with execCommand
if (Browser.isEdge() || Browser.isIE()) {
try {
iframeElement.contentWindow.document.execCommand('print', false, null)
} catch (e) {
iframeElement.contentWindow.print()
}
} else {
// Other browsers
iframeElement.contentWindow.print() // as I am using Firefox, it is coming here
}
} catch (error) {
params.onError(error)
} finally {
//cleanUp(params)
}
}
Inside Code.gs
function openUrl() {
var html = HtmlService.createHtmlOutputFromFile("printJsSource");
html.setWidth(500).setHeight(500);
var ui = SpreadsheetApp.getUi().showModalDialog(html, "Opening ..." );
}
【问题讨论】:
标签: google-sheets print-preview printing-web-page