2010-11-09 41 views
1

我在我的asp.net項目中使用smartxls與c#。我有以下代碼:使用smartxls dll我無法更改打開的默認名稱

var excel = new SmartXLS.WorkBook(); 
string projPath = AppDomain.CurrentDomain.BaseDirectory; 
excel.readXLSX(projPath + @"ExcelTemplates\" + template); 
excel.ImportDataTable(....) 
Response.ContentType = "application/vnd.ms-excel"; 
excel.write(Context.REsponse.OutputStream); 

這似乎做工精細,我的數據是在我的aspx頁面上的網頁連結開闢了直接,但一旦打開,它會自動命名文件default.xls,我無法弄清楚如何改變這個名字。我嘗試了excel.setSheetName以及excel.DefinedName,但是它在打開時都不會更改該excel表的名稱,它始終是default.xls。 有誰知道如何設置這個名字與我的代碼上面? 我知道我可以重命名,如果我直接將其保存到像C:\ filename這樣的路徑寫入,但我需要它具有特定的名稱並在按鈕或鏈接單擊時自動打開客戶端。

謝謝

回答

2

您需要明確指定文件名。

Response.ContentType =「application/vnd.ms-excel」;

//添加此行

Response.Addheader 「內容處置」, 「附連;文件名=」 & youfileName &是 「.xls」

excel.write(Context.REsponse。 OutputStream的);

+1

正是我所需要的,tx – edosoft 2010-12-13 10:11:22

相關問題