Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
C#
[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'); }
Posted

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900