以角度打印办公文件(.doc、.docx、.xls)

问题描述 投票:0回答:0

我有角度的办公文件 url 链接(.doc、.xls)。想要单击按钮打印文件内容。

我尝试了下面的代码,但它正在下载文件而不是打印并显示这个没有内容的打印窗口

see image

this.http.get(`${fileUrl}`, options).subscribe((res: any) => {
      /* istanbul ignore next */
      if (res) {
        let blob = new Blob([res], {type: res.type});
        const blobUrl = URL.createObjectURL(blob);
        const iframe = document.createElement('iframe');
        iframe.style.display = 'none';
        iframe.src = blobUrl;
        document.body.appendChild(iframe);
        iframe.contentWindow.focus();
        iframe.contentWindow.print();
      }
 });

但是上面代码中的 pdf、img 和文本文件 url 工作正常并且也在打印窗口中显示内容。

see image

** 文件网址 - **

对于pdf文件- https://somepath/testpdf4afdd7ea-5b55-44f4-af2d-f30767764ca9.pdf

对于文档文件 - https://somepath/file-sample_100kB8de49893-0e1c-4b8f-8f50-fac5e9fc759f.doc

任何帮助都会非常有用谢谢

我想通过它的 url 以角度打印 office 文件(可以是 doc、excel、ppt)。 我已经有了 pdf、img 和文本文件的工作代码。

angular excel iframe printing doc
© www.soinside.com 2019 - 2024. All rights reserved.