iSNN
V2EX  ›  程序员

请教各位上传文件后在 web 直接查看有什么好的方案吗

By iSNN at 2021 年 5 月 26 日 · 3795 次点击

img 和 pdf 都好解决,其中还有 office 文件

目前就是 office 文件有点麻烦,先想的是转成 pdf,用了 spire 相关的来转,但是中文全是白框,但是服务器上的中文都是正常显示的

不知各位大佬们有没有什么好的办法

17 条回复    2021-05-28 18:47:46 +08:00
yakumo520
   1
yakumo520  
   2021 年 5 月 26 日
白框是编码字符集不对,检查一下 pdf 转 word 比较成熟,多看看吧
iSNN
   2
iSNN  
OP
   2021 年 5 月 26 日
@yakumo520 服务器上命令行打开文件显示中文是正常的,你说的哪个字符集就不知道了...
wyx119911
   3
wyx119911  
   2021 年 5 月 26 日
office 想预览花钱买服务吧,自己做效果不行的
DonaldY
   4
DonaldY  
   2021 年 5 月 26 日
白框可能是识别不了字体(没有对应的字体),excel 可转 html
libreoffice 可以试试
iSNN
   5
iSNN  
OP
   2021 年 5 月 26 日
@wyx119911 看到微软有个 view.officeapps.live.com/op/embed.aspx 接口,不知道能不能商用。

或者老哥能推荐比较靠谱的接口吗
renmu123
   6
renmu123  
   2021 年 5 月 26 日 via Android
ie 支持 word 预览(笑)
jtacm
   7
jtacm  
   2021 年 5 月 26 日
libreoffice 可以把 Office 转成 PDF
0044200420
   8
0044200420  
   2021 年 5 月 26 日
后端转换 pdf
vueli
   9
vueli  
   2021 年 5 月 27 日
我记得有个微软的一个接口, 在线转换阅读. 找不到了, 我可以肯定有
h4de5
   10
h4de5  
   2021 年 5 月 27 日
iSNN
   11
iSNN  
OP
   2021 年 5 月 27 日
@vueli 5L 的接口,但是可商用吗...
iSNN
   12
iSNN  
OP
   2021 年 5 月 27 日
@DonaldY libreoffice 有上方 v 友所说的字符集问题的,虽然我从表现看是字符问题,但没确定,因为服务器上打开中文的文件是正常的
DonaldY
   13
DonaldY  
   2021 年 5 月 27 日
@iSNN 字符集指什么?
MilkShake
   14
MilkShake  
   2021 年 5 月 27 日
libreoffice
image72
   15
image72  
   2021 年 5 月 28 日
使用 google docs 或者 office 365 在线预览
···
<iframe src="https://docs.google.com/gview?url=http://remote.url.tld/path/to/document.doc&embedded=true"></iframe>

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=http://remote.url.tld/path/to/document.doc' width='1366px' height='623px' frameborder='0'>This is an embedded <a target='_blank' href='http://office.com'>Microsoft Office</a> document, powered by <a target='_blank' href='http://office.com/webapps'>Office Online</a>.</iframe>
···

Convert Word documents (.docx files) to HTML

mammoth.js
MarioLuo
   16
MarioLuo  
   2021 年 5 月 28 日 via Android
可搭建独立的文件预览服务,使用: https://github.com/kekingcn/kkFileView
iSNN
   17
iSNN  
OP
   2021 年 5 月 28 日
@MarioLuo 谢谢老哥,我昨晚也看到这个项目了,很好用。开源大法好,根据业务需求也修改了一些地方
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
© 2026 V2EX · 28ms · 3.9.8.5