2012-06-13 62 views

回答

5

來源:Grid/MS Excel/MS Word/CSV

使用RadGrid.ExportSettings.FileName屬性,一個字符串,將要創建的文件指定 名(不包括擴展名)。 文件擴展名是根據使用的方法自動添加的 嘗試在ItemCommand事件中設置FileName,如下所示。

來源:When to set RadGrid.ExportSettings.FileName

protected void Radgrid1_ItemCommand(object sender, GridCommandEventArgs e) 
{ 
    if (e.CommandName == RadGrid.ExportToPdfCommandName) 
    { 
     Radgrid1.ExportSettings.FileName = "yourfilename"; 
    } 
    if (e.CommandName == RadGrid.ExportToExcelCommandName) 
    { 
     Radgrid1.ExportSettings.FileName = "yourfilename"; 
    } 
    if (e.CommandName == RadGrid.ExportToWordCommandName) 
    { 
     Radgrid1.ExportSettings.FileName = "yourfilename"; 
    } 
} 

參考:
Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled

+0

有沒有人獲得文件名屬性,以正確工作?當我嘗試設置它時,它會被RadGrid導出忽略。 – Allen

+0

是的,我也是......嘗試了幾個事件,但總是被忽略 – Giox

1

您可以設置文件名以及其他選項對於出口,對電網(不是MasterTableView)的ExportSettings財產。因此,例如:

myGrid.ExportSettings.FileName = "file"; 
myGrid.ExportSettings.Excel.Extension = "xls"; 
myGrid.MasterTableView.ExportToExcel(); 
+0

根據你應該離開了擴展的文檔 - 「字符串指定名稱(不帶擴展名)的」 http:/ /demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/exporting/defaultcs.aspx –

+0

@Kevin Main我忘了這是事實。雖然我確實認爲導出函數會忽略擴展名,但是我現在無法對其進行測試,因此我會對其進行編輯。謝謝! – pyrocumulus

相關問題