[英]display word/excel file content in asp.net mvc4
我是ASP.net MVC4
。 我正在嘗試在我的網頁中顯示word和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");
}
過去,我使用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';
一些資源:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.