如何在浏览器中打开Word文档
本文关键字:Word 文档 浏览器 | 更新日期: 2023-09-27 18:30:49
我想在浏览器中打开二进制Word文档文件,而不是从物理路径打开。使用下面给出的代码,我可以在浏览器中打开PDF文件,但不能打开其他文件。
法典:
byte[] obFile = null;
obFile = (byte[])fds.Tables[0].Rows[0]["File"];
String aFileName = "abc";
Response.Expires = 0;
Response.ClearContent();
Response.Buffer = true;
Response.BufferOutput = true;
Response.ContentType = "application/msword;name=abc.docx";
Response.AddHeader("content-transfer-encoding", "binary");
Response.AddHeader("content-length", obFile.Length.ToString());
Response.AddHeader("Content-Disposition", "inline; filename=abc.docx";
Response.CacheControl = "public";
Response.ContentEncoding = System.Text.Encoding.GetEncoding(1251);
Response.OutputStream.Write(obFile, 0, obFile.Length);
Response.End();
Word 的默认行为是在浏览器窗口之外打开文档。这是客户端设置,无法从服务器端代码更改。
请参阅如何配置 Internet Explorer 以在相应的 Office 程序中打开 Office 文档,而不是在支持站点上的 Internet Explorer 中打开 Office 文档,了解如何重新配置计算机。
您可以使用 Flash/Silverlight 库来显示文档。Microsoft还具有可以在浏览器上显示和编辑 Office 文档的 Office Web 应用程序(需要许可证)