在asp.net mvc4中显示word / excel文件内容 [英] display word/excel file content in asp.net mvc4

查看:127
本文介绍了在asp.net mvc4中显示word / excel文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我是ASP.net MVC4的初学者。我正在尝试在我的网页中显示单词和excel文件的内容。我在HomeController中编写了这个函数,但它没有显示内容。它只下载了文件。如何在我的网页中预览文件?谢谢

 [HttpGet]  public  FileResult downloadFile(){
byte [] fileBytes = System.IO.File.ReadAllBytes( J:\\\p.net \ ViewInformation \ ViewInformation\Content\book.xlsx);
返回文件(fileBytes ,, application / vnd.ms-excel,'book.xlsx');}

解决方案

是的,你可以显示内容,但这完全没有意义。根据微软的Open XML标准,该文件实际上是一些XML文件的ZIP集: https://en.wikipedia.org/wiki/Office_Open_XML [ ^ ]。



一种在语义上读取文件的方法明智的方法是使用Microsoft Open XML SDK。请参阅此CodeProject艺术icle:使用Open XML创建基本的Excel工作簿 [ ^ ]。



另请参阅本文中引用的过去答案:使用Open XML创建基本的Excel工作簿 [ ^ ]。



-SA

Hello,

I'm beginner in ASP.net MVC4. And I'm trying to display the content of the word and excel file in my web page. I wrote this function in the HomeController , but it didn't display the content. it only downloaded the file. how can I preview the file in my webpage? Thanks

[HttpGet] public FileResult downloadFile() { 
byte[] fileBytes = System.IO.File.ReadAllBytes("J:\asp.net\ViewInformation\ViewInformation\Content\book.xlsx);
 return File(fileBytes, ,application/vnd.ms-excel, 'book.xlsx'); }

解决方案

Yes, you can display the content, but it would be totally pointless. The file is actually the ZIPed set of some XML file, according to the Microsoft's Open XML standard: https://en.wikipedia.org/wiki/Office_Open_XML[^].

One way of reading the file in semantically sensible way would be using Microsoft Open XML SDK. Please see this CodeProject article: Creating basic Excel workbook with Open XML[^].

See also my past answers referenced in this one: Creating basic Excel workbook with Open XML[^].

—SA


这篇关于在asp.net mvc4中显示word / excel文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆