如何使用PHP显示Word文件和Excel文件

时间:2018-10-23 12:13:21

标签: php

我已经使用php上传了word文件和excel文件,我想显示此文件以查看页面。

我尝试了以下代码:

<td>
   <img style="width:12px !important; height:12px !important;"
    class="w-h-12"
    src="/manage/public/uploads/docs/2018/10/208149311.docx">
</td>

视图列表中未显示任何内容。然后我试着画框

 <iframe src="/manage/public/uploads/docs/2018/10/208149311.docx" style="width:200px; height:200px;" frameborder="0"></iframe> 

它对我也不起作用

对于jpg图片,效果很好

2 个答案:

答案 0 :(得分:0)

Google文档查看器可以处理此问题。

# from django.conf.urls import patterns, include, url from django.conf.urls import include, url from django.urls import path from YAASApp.views import * from django.views.decorators.csrf import csrf_exempt

from django.contrib import admin
# admin.autodiscover()

urlpatterns = url('',
    path('admin/', admin.site.urls),
    #url(r'^', include('YAASApp.urls')),
    (r'^home/$', home),
    (r'^createuser/$', register),
    (r'^login/$', login),
    (r'^logout/$', logout),
    (r'^edituser/$',edit_user_info),
    (r'^addauction/$',add_auction),
    (r'^saveauction/$',save_auction),
    (r'^editauction/(?P<id>\w+)/$', edit_auction),
    (r'^saveeditedauction/(?P<id>\w+)/$',save_edited_auction),
    (r'^canceledit/(?P<id>\w+)/$',canceledit),
    (r'^auction/(?P<id>\w+)/$', view_auction),
    (r'^banauction/(?P<id>\w+)/$', ban_auction),
    (r'^changelang/$', changelang),
    # (ur'^search/(\w+)/$', search),
    # (ur'^search/$', search),
    (r'^bidauction/(?P<id>\w+)/$', bid_auction),

    #url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),

    # (ur'^api/v1/search/$', apisearch),
    # (ur'^api/v1/search/(\w+)/$', apisearch),

    # (ur'^api/v2/bid/(?P<id>\w+)/$', apibid),

    # path('admin/', admin.site.urls), )

答案 1 :(得分:0)

浏览器本身不支持查看.doc或.docx或excel文件。您必须在这样的iframe中使用Google文档查看器

<iframe style="width: 100%" height="500px" src="//docs.google.com/gview?url=http://www.picssel.com/demos/downloads/Fancybox.doc&embedded=true"></iframe>

但是请记住,它在localhost上不起作用,因为它将首先将文件下载到它自己的驱动器中,然后它将向您显示该文件。