如何使用 PHP 或 HTML 在浏览器中查看/打开 Word 文档
如何在浏览器中打开并查看 .doc
文件扩展名?该文件位于我的服务器上。
How can I open and view a .doc
file extension in my browser? The file is located on my server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
有两个选项:第一个是仅链接到它,例如
My Word Document
,第二个是使用 iframe 并将其指向该文件。然而,要实现此功能,大多数浏览器要求服务器随文档一起发送Content-disposition: inline
标头。如果您无法配置您的 Web 服务器来执行此操作,您可以将文档包装在一些 php: 中,然后链接到该脚本而不是您的 Word 文档。
但这并不能保证一定有效; content-disposition 标头只是一个提示,任何浏览器都可以选择将其视为附件。
另外,请注意 .doc 并不完全可移植;基本上,您需要 Word 才能正确显示它(Open Office 和其他一些开源应用程序做得不错,但还不够),并且浏览器必须支持将 Word 作为插件打开。
如果 .doc 文件格式要求不是一成不变的,PDF 将是更好的选择(转换通常就像在 PDF 打印机上打印一样简单,例如,CutePDF,从 Word 内部),或者您甚至可以转换将文档转换为 HTML(尽管情况可能会有所不同)。
Two options: First is to just link to it, e.g.
<a href="MyWordDocument.doc">My Word Document</a>
, the second is to use an iframe and point it to the document. For this to work, however, most browsers require that the server sends aContent-disposition: inline
header with the document. If you cannot configure your web server to do this, you can wrap the document in a bit of php:And then link to that script instead of your word document.
This isn't guaranteed to work though; the content-disposition header is just a hint, and any browser may choose to treat it as an attachment anyway.
Also, note that .doc isn't exactly portable; basically, you need Word to display it properly (Open Office and a few other Open Source applications do kind of a decent job, but they're not quite there yet), and the browser must support opening Word as a plugin.
If the .doc file format requirement isn't set in stone, PDF would be a better choice (the conversion is usually as simple as printing it on a PDF printer, say, CutePDF, from inside Word), or maybe you can even convert the document to HTML (mileage may vary though).
您将需要一个安装了 Office 文档插件的浏览器。我相信 Microsoft Office 默认情况下至少会为 Internet Explorer 安装一个。
如果您想在没有插件的情况下工作,那么您需要将文档转换为另一种格式 - HTML 以获得最大兼容性。这不是一个简单的操作,特别是对于复杂的文档(甚至那些只包含图像的文档)。
You will need a browser with a plugin for Office documents installed. I believe Microsoft Office will install one for at least Internet Explorer by default.
If you want to work without a plugin, then you will need to convert the document to another format — HTML for maximum compatibility. This isn't a trivial operation, especially for complex documents (or even those which just contain images).
您可以使用谷歌文档,因为它是免费且可靠的
您可以将文件路径分配给 iframe。
例如 iframe1.Attributes.Add("Src", "http://docs.google. com/gview?url=http://YOUR_FILE_PATH&embedded=true");
You can use google docs instead as it is free and reliable
You can assign your file path to iframe.
e.g. iframe1.Attributes.Add("Src", "http://docs.google.com/gview?url=http://YOUR_FILE_PATH&embedded=true");
如果您的 .doc 文件可以在线访问,您可以尝试 Office Web 查看器 服务。
如果您的文档存储在 Intranet 中,您可以使用 Microsoft Office Web Apps Server。它允许用户通过浏览器查看Word、PowerPoint、Excel 文档。
If your .doc file is accessable online, you can try Office Web Viewer service.
If your documents stored in Intranet, you can use Microsoft Office Web Apps Server. It allows users to view Word, PowerPoint, Excel documents via browser.