2015-08-29 97 views
1

我是初學者ASP.net MVC4。我試圖在我的網頁上顯示word和excel文件的內容。 我在HomeController中寫了這個函數,但沒有顯示內容。它只下載該文件。 如何在我的網頁中預覽該文件? 感謝在asp.net中顯示word/excel文件內容mvc4

[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

一個選項 - [ASP.NET文檔查看器(https://code.msdn.microsoft.com/ASPNET-Document-Viewer-e7c2a39f) –

回答

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'; 

一些資源: