【问题标题】:Rendering a Microsoft Word document on a webpage在网页上呈现 Microsoft Word 文档
【发布时间】:2012-08-24 13:48:51
【问题描述】:

我正在设计一个 Web 应用程序,其中大部分网站将显示用户生成的文档。现在,我已经在网站上实现了 LaTeX 源代码和 pdf 渲染,但我仍然无法在网站上渲染 Microsoft Word 文件(.doc 和 .docx)。我环顾四周,发现了一个类似的问题(here),但从未得到回答。我想知道是否使用像 Google Docs 这样的基于 Web 的解决方案或使用 OpenOffice 在服务器上以编程方式执行它是可行的解决方案。不过,纯 JavaScript 解决方案将是理想的。

【问题讨论】:

    标签: javascript web-applications ms-word latex


    【解决方案1】:

    根据 Vikram 的回答,您可以使用 Google Docs Viewer 来渲染文件。这样它应该适用于所有浏览器。

    代替

    <a href="doc1.doc" target="awindow">Doc 1</a>
    

    使用

    <a href="http://docs.google.com/viewer?url=[URLToDoc1.doc]" target="awindow">Doc 1</a>
    

    但是您必须对 URL 进行 urlencode。例如,

    http://research.google.com/archive/bigtable-osdi06.pdf
    

    变成

    http%3A%2F%2Fresearch.google.com%2Farchive%2Fbigtable-osdi06.pdf
    

    您可以转到https://docs.google.com/viewer 以便轻松生成链接。

    此外,Vikram 的代码又旧又丑。你应该使用类似的东西:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Open Doc</title>
    <style type="text/css">
    /*<![CDATA[*/
    .clear{clear:both;}
    #list{float:left;margin-right:50px;}
    #wrapper{overflow:hidden;}
    #awindow{width:100%;height:440px;}
    /*]]>*/
    </style>
    </head>
    <body>
    <ul id="list">
        <li><a href="http://docs.google.com/viewer?url=[URLToDoc1.doc]" target="awindow">Doc 1</a></li>
        <li><a href="http://docs.google.com/viewer?url=[URLToDoc2.docx]" target="awindow">Doc 2</a></li>
        <li><a href="http://docs.google.com/viewer?url=[URLToDoc3.doc]" target="awindow">Doc 3</a></li>
    </ul>
    <div id="wrapper">
      <iframe id="awindow" name="awindow" src="title.html"></iframe>
    </div>
    <div class="clear"></div>
    </body>
    </html>
    

    【讨论】:

      【解决方案2】:

      您是否已经尝试过这样的事情?:

      <html>
      <head>
      <title>Open Doc</title>
      </head>
      <body>
      <DIV align="CENTER">
      <TABLE BORDER="1" CELLSPACING="1" CELLPADDING="1" WIDTH="100%">
      <TR>
      <TD WIDTH="25%" ALIGN="left" VALIGN="TOP">
      <a href="doc1.doc" target="awindow">Doc 1</A><br>
      <a href="doc2.docx" target="awindow">Doc 2</A><br>
      <a href="doc3.doc" target="awindow">Doc 3</A>
      </TD>
      <TD WIDTH="75%" ALIGN="CENTER" VALIGN="TOP">
      <iframe name="awindow" frameborder=2 width=580 height=440 src="title.html"></iframe>
      </TD></TR></TABLE></CENTER>
      </DIV>
      </body>
      </html>
      

      将 href 属性修改为服务器上放置这些文档的路径

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-08-10
        • 2016-05-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-23
        • 1970-01-01
        相关资源
        最近更新 更多