如何在asp.net 4.0,C#Web应用程序中在线查看MS office文件

问题描述:

目前我正在开发一个用c#和& amp; asp.net

用户可以存储批量文件。现在我想查看在浏览器中打开的所有可查看格式的文件(即图像,ms office,pdf等)(无需在客户端本地计算机中下载)。我已经完成了一半的工作,即我的应用程序适用于所有图像文件和pdf文件。但我面临ms office文件(即xls,xlsx,doc,docx,ppt等)格式的问题。我尝试了一些代码

Currently I am working on a file management system which developed in c# & asp.net
Where user can store bulk files. Now I want to view all viewable formats of file (i.e. image, ms office, pdf etc) open in browser (without downloading in clients local machine). I already done half of my job i.e. my application working fine for all image files and pdf files. But I facing problem with ms office files (i.e. xls, xlsx, doc, docx, ppt etc) formats. I tried some piece of code

protected void Page_Load(object sender, EventArgs e)
        {
            //Set the appropriate ContentType.
            string FilePath = MapPath("Test/xyz.pdf");
            Response.Buffer = true;
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "Application/pdf";
            Response.AddHeader("content-disposition", "inline; filename=\"" + "xyz.pdf" + "\"");
            Response.Write(FilePath);
            Response.End();
        }





此代码仅适用于.pdf文件,但当我更改内容类型为Response.ContentType for word或excel文件Application / msword(对于Microsoft Word文件)Application / x-msexcel(对于Microsoft Excel文件)然后此代码不起作用。请指导我该怎么办。我应该使用任何工具,如谷歌文档查看器或其他东西。如果只有工具,那么请建议我一个很好的工具。



提前谢谢



This code works fine only for .pdf files but when I changed my content type Response.ContentType for word or excel files Application/msword (for Microsoft Word files) Application/x-msexcel (for Microsoft Excel files) then this code not works. Please guide me what can I do. Should I use any tool like google documents viewer or some thing else.If it is possible only with tool then please suggest me a good tool for this.

Thanks in advance

简而言之:Office格式现已公开发布并标准化(请参阅下面的链接),但Web标准不支持它们,因此您需要代表他们的内容并显示为HTML。



请参阅我过去的答案,了解如何处理这些文件。您应该将自己的映射设计为HTML并实现HTML内容的生成。请参阅:

将Office文档转换为PDF而无需互操作 [ ^ ],

需要一个相当独特的WPF文本编辑器控件 [ ^ ],

您好如何使用c#.net 在Windows应用程序中显示word文件[ ^ ],
不使用Interop读取word文件.word dll ...不想在IIS中安装单词。 [ ^ ]。



-SA
In brief: the Office formats are now publicly available and standardized (please see links below), but they are not supported by Web standards, so you would need to represent their content and show as HTML.

Please see my past answer on how to deal with these files. You should devise your own mapping to HTML and implementation of generation of the HTML content. Please see:
Convert Office-Documents to PDF without interop[^],
Need a rather unique WPF text editor control[^],
Hi how can i display word file in windows application using c#.net[^],
Read a word file without using Interop.word dll...Do not want to install word in IIS..[^].

—SA