[英]display word/excel file content in asp.net mvc4
I'm beginner in ASP.net MVC4
. 我是
ASP.net MVC4
。 And I'm trying to display the content of the word and excel file in my web page. 我正在尝试在我的网页中显示word和excel文件的内容。 I wrote this function in the
HomeController
, but it didn't display the content. 我在
HomeController
编写了此函数,但未显示内容。 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");
}
In the past I used Microsoft.Office.Interop.Excel.Application. 过去,我使用Microsoft.Office.Interop.Excel.Application。
excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Workbooks.Open(filePath);
Then access cells like so: 然后像这样访问单元格:
int newId = Convert.ToInt32(values[i, GetColumnPosition(newIdColumn)]);
int oldId = Convert.ToInt32(values[i, GetColumnPosition(oldIdColumn)]);
Where 哪里
public static int GetColumnPosition(char alpha)
{
return char.ToUpper(alpha) - 64;
}
and 和
private const char oldIdColumn = 'F';
private const char newIdColumn = 'A';
Some resources: 一些资源:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.