美文网首页IT技术篇
在PC项目中将上传的文件(word, excel, pdf)直接

在PC项目中将上传的文件(word, excel, pdf)直接

作者: 燕自浩 | 来源:发表于2021-05-11 17:41 被阅读0次
思路: 可以使用任何方式将本地文件上传到后端得到一个地址后使用iframe直接在项目中展示出来
这是一张最终的效果图
代码实现
                   <iframe
                      title="1"
                      width="100%"
                      height="600"
                      frameBorder="0"
                      src={`https://view.officeapps.live.com/op/view.aspx?src=${domainName}/${info.attachment_path}`}
                    />

src属性后面的为文件上传之后得到的url

在当前浏览器中新开一个标签页进行预览

const a = document.createElement('a')
      a.setAttribute(
        'href',
        `https://view.officeapps.live.com/op/view.aspx?src=${domainName}/${attachment_path}`,
      )
      a.setAttribute('target', '_blank')
      a.click()
      a.remove()
2.简单预览把word解析成文本展示并支持文字放大缩小
<iframe
    :src="'//www.xdocin.com/xdoc?_func=to&_format=html&_cache=1&_xdoc='+fileUrl"
    width="100%"
    height="100%"
    frameborder="0">
</iframe>

使用方式://www.xdocin.com/xdoc?_func=to&_format=html&_cache=1&_xdoc=文档地址
ps:适用PC,移动端使用,不能处理比较老的word文件,比如.doc后缀的文件,但是显示很清晰,可惜会有个很大的微信二维码,暂时没想到办法怎么去掉

3.功能稍微强大的预览支持下载打印等功能
<iframe
    src="http://api.idocv.com/view/url?url=<UTF-8 Encoded URL>&name=<可选文件名>"
    width="100%"
    height="100%"
    frameborder="0">
</iframe>
4.在线可编辑
<iframe
    src="https://api.idocv.com/edit/url?url=<UTF-8 Encoded URL>&name=<可选文件名>"
    width="100%"
    height="100%"
    frameborder="0">
</iframe>
5.同步在线预览
演讲方
<iframe
    src="https://api.idocv.com/view/url?url=<UTF-8 Encoded URL>&type=speaker&name=<可选文件名>"
    width="100%"
    height="100%"
    frameborder="0">
</iframe>

听众方
<iframe
    src="https://api.idocv.com/view/url?url=<UTF-8 Encoded URL>&type=audience&name=<可选文件名>"
    width="100%"
    height="100%"
    frameborder="0">
</iframe>

相关文章

网友评论

    本文标题:在PC项目中将上传的文件(word, excel, pdf)直接

    本文链接:https://www.haomeiwen.com/subject/blrndltx.html