下面我附上我的代码。
我正在尝试使用角度打印Excel文件,而无需用户按ctrl + P。我确实在下面的链接中找到了相关的代码,并且能够打开打印弹出窗口,但白纸上没有内容。谢谢您的建议。
printListXcel() {
this.listService.getListExcel(this.ListId).subscribe(data => {
const blobData = new Blob([data], {
type:'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet'});
const blobUrl = URL.createObjectURL(blobData);
const iframexcel = document.createElement('iframe');
iframexcel.style.display = 'none';
iframexcel.src = blobUrl;
document.body.appendChild(iframexcel);
iframexcel.contentWindow.print();
});
}