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

编程入门 行业动态 更新时间:2024-10-22 19:24:19
本文介绍了如何在asp 4.0,C#Web应用程序中在线查看MS office文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

目前我正在开发一个用c#和& amp; asp 用户可以存储批量文件。现在我想查看在浏览器中打开的所有可查看格式的文件(即图像,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 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# 在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#[^], Read a word file without using Interop.word dll...Do not want to install word in IIS..[^].
—SA

更多推荐

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

本文发布于:2023-11-12 11:57:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581441.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在线   应用程序   文件   如何在   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!