2015-03-03 33 views

回答

1

如果您使用的是數據驅動訂閱,則可以使用SQL動態地設置報表名稱。

否則SSRS中無法做到這一點。您可以隨時使用外部腳本在導出後爲您重命名PDF,但它不是完全自動的。

+0

不,我沒有使用數據驅動訂閱 – abiansh 2015-03-03 11:50:41

+0

然後我覺得你運氣不好。 – novabracket 2015-03-03 11:53:02

+0

任何方式來改變點擊事件 – abiansh 2015-03-03 11:59:58

4

請嘗試使用的ReportViewer

ReportViewer.ServerReport.DisplayName = <Your Parameter Value>; 
ReportViewer.LocalReport.DisplayName = <Your Parameter Value>; 
+0

感謝它爲我工作 – abiansh 2015-03-04 05:39:55

+0

偉大,請標記是否有用..這將有助於其他人面臨類似的問題 – 2015-03-05 09:57:50

0

DisplayName屬性還可以在此使用的JavaScript鉤子做。有一個教程here讓我開始,但沒有完全爲我工作。

我最終做的是在<sql server folder>\ReportServer\Pages\的ReportViewer.aspx中,在<body>末尾的腳本標記中添加一些javascript。針對URL的檢查確保它僅影響它應該更改名稱的報告。

這適用於空格和其他特殊字符(只要它們允許在文件名中)。

function modifyExportFileName() { 
    /* Change the name of file exports */ 
    var filename = false; 

    if (window.location.href.indexOf('Folder/Report') !== -1) { //it's the report we want 
     filename = getParameter('parameter'); // returns false if not set 
     // should also have access to report DOM here, also Date(), etc. 
    } // could add more here as needed in else if blocks 


    if (filename) { // we have a filename set. 
     console.log('changing filename of exported reports to ' + filename); 
     changeFilename(filename); 
    } 
} 

function getParameter(param) { 
    //case sensitive parameter extractor. 
    var l = window.location.href; 
    if (l.indexOf(param + '=' > -1)) { 
     var param_location = l.indexOf(param + '=') + (param + '=').length; 
     return l.substring(param_location, l.indexOf('&', param_location + 1)); 
    } 
    return false; 
} 

function changeFilename(filename) { 
    var r = null, 
     url = null; 

    try { 
     r = this.$find('ReportViewerControl')._getInternalViewer(); 
    } catch(e) { 
     setTimeout(function() {changeFilename(filename)}, 1000); //maybe we're not done loading. 
     console.log("trying again"); 
     return false; 
    } 

    url = r.ExportUrlBase; 
    if (url) { 
     var i = url.indexOf('FileName='), 
      j = url.indexOf('&', i+1); 
     r.ExportUrlBase = url.substring(0, i) + 'FileName=' + filename + url.substring(j); 
     console.log('reset filename to ' + filename); 
    } 
} 

modifyExportFileName(); 

編輯:我注意到這段代碼沒有在企業網絡的IE中運行。原因是console.logs。如果您的網站在IE兼容模式下運行,請將它們評論一下,因爲IE5沒有控制檯。