我是ASP.net MVC4
的初学者。我正在尝试在我的网页中显示单词和excel文件的内容。
我在HomeController
中编写了此函数,但它没有显示内容。它只下载了文件。
如何在我的网页中预览文件?
感谢
[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");
}
答案 0 :(得分:0)
过去我使用过Microsoft.Office.Interop.Excel.Application。
excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Workbooks.Open(filePath);
然后像这样访问单元格:
int newId = Convert.ToInt32(values[i, GetColumnPosition(newIdColumn)]);
int oldId = Convert.ToInt32(values[i, GetColumnPosition(oldIdColumn)]);
其中
public static int GetColumnPosition(char alpha)
{
return char.ToUpper(alpha) - 64;
}
和
private const char oldIdColumn = 'F';
private const char newIdColumn = 'A';
一些资源: