ngx-doc-viewer downloading xlsx rather than previewing?

huangapple go评论67阅读模式
英文:

ngx-doc-viewer downloading xlsx rather than previewing?

问题

我使用ngx-doc-viewer设置预览各种文件类型的URL,对于PDF、JPEG和其他我尝试过的文件类型都有效,但是Excel文件似乎无法预览(不像我之前遇到的情况那样显示“无法预览”),而是下载该文件。

这不是文件大小的问题,因为我尝试过几乎空白的电子表格。这可能是什么原因呢?

我的计划是使用Google提供的URL,但我目前正在使用URL以便在本地查看我的预览。

这是我的代码:

<ngx-doc-viewer
   [url]="fileName"
   viewer="url"
   style="width:100%;height:70vh;"
></ngx-doc-viewer>
英文:

I setup ngx-doc-viewer to preview various file types using url, and while it works for pdfs, jpegs, and everything else I've tried, excel files just seem to not preview anything(it doesn't say "no preview available" like I've ran into before) and instead it downloads the file as well.

It isn't a file size issue as I've tried it with near empty spreadsheets. Any reason why this would be?

My plan is to use google over url, but I am using url so that I can see my previews in local

Here is my code

&lt;ngx-doc-viewer
   
=&quot;fileName&quot; viewer=&quot;url&quot; style=&quot;width:100%;height:70vh;&quot; &gt;&lt;/ngx-doc-viewer&gt;

答案1

得分: 2

from the package's documentation:
https://www.npmjs.com/package/ngx-doc-viewer

>公开可用的文档可以使用谷歌或办公室文档查看器在iframe中显示。

传递一个公开可用的URL是预览xlsx文件的唯一方法。

一个iframe只是你的应用程序中嵌入的另一个网站,在这种情况下,它使用谷歌和办公室自己的网站来显示预览。由于iframe无法验证用户并检查您是否有权限查看文档,因此它必须是公开的。

这也意味着您不能从您自己的计算机加载文件以进行预览。

编辑:我成功地通过将其上传到Firebase并获取链接来预览xlsx文件。我还看到其他人说他们成功通过将文件上传到AWS云存储来显示它。如果这对您是一个选择,也许值得一试,您首先将文件上传到一些在线云存储,然后获取公开链接来显示它。否则,下面的原始帖子仍然有效。

如果您只想在您的应用程序中显示一个静态文件: <br>
将其上传到Google Drive或Office,使其公开,并获取链接来显示它。

如果您需要用户上传预览,正如我所假设的那样,除了读取xlsx文件并解析数据以显示在您的HTML中之外,没有其他方法。

为此,您可以使用XLSX包:
https://www.npmjs.com/package/xlsx

英文:

from the package's documentation:
https://www.npmjs.com/package/ngx-doc-viewer

>Documents that are publicly available can be shown in an iframe using the google or office document viewer.

passing a publicly available url is the only way to preview a xlsx file.

a Iframe it's just another website embedded in your application, in this case it's using google's and office's own websites to display the previews. since the iframe cannot authenticate the user and check If you have permission to view the document, it has to be public.

this also mean that you can't load a file from your own computer to preview it.

EDIT: I managed to preview a xlsx file by uploading it to firebase and getting the link. I also saw other people saying that they managed to display it by uploading the file to AWS Cloud Storage. If this is a option to you then maybe it's worth a try, you would first upload the file to some online cloud storage and then grab the public link to display it. otherwise the original post bellow stands.

If you only want to show a static file in your application: <br>
upload it to google drive or office, make it public and grab the link to display it.

If you need the preview to be uploaded by the user as I assume it's what you are trying to do, there's no other way besides reading the xlsx file and parsing the data to display in your html.

for that you can use the XLSX package:
https://www.npmjs.com/package/xlsx

huangapple
  • 本文由 发表于 2023年4月20日 03:01:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058010.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定