问题
I'm planning a upgrade to SQL Server 2017 Reporting Services from 2012.
In version 2012, which my company has been using for several years, we added a extension which abled us to modify the filename when the user exports reports to PDF, Excel,... So instead of having e.g. the filename StudentReport.PDF, we get StudentReport_Student_Name.PDF.
To manage this we added a hidden field into the footer of each report, FileNameExtend=[[Student Name]] in white text so you don't see it unless you change the color of text.
Then the following JavaScript code was added to ReportingServices.js on the server.
function ModifyExportUrlBase() {
var rv = null;
var r = null;
try {
rv = this.$find("ctl31");
r = rv._getInternalViewer();
}
catch (err) {
setTimeout(ModifyExportUrlBase, 1000)
return;
}
if (r != null && r.ExportUrlBase != null) {
// Search for FileNameExtension in all div elements
var fileNameExtend = function () {
var divElements = document.getElementsByTagName("div");
var result = '';
for (var i = 0; i < divElements.length; i++) {
if (divElements[i].innerText.indexOf("FileNameExtend=[[") > -1 && divElements[i].innerText.indexOf("]]") > -1) {
var istart = divElements[i].innerText.indexOf("[[");
var istop = divElements[i].innerText.indexOf("]]");
result = divElements[i].innerText.substring(istart + 2, istop);
}
}
return String(result);
}();
// Change ExportUrlBase if fileNameExtend exist
if (fileNameExtend != null && fileNameExtend.length > 0) {
var url = r.ExportUrlBase;
var i = url.indexOf("FileName=");
var j = url.indexOf("&", i + 1);
var fileName = url.substring(i, j) + '_' + encodeURI(fileNameExtend);
r.ExportUrlBase = r.ExportUrlBase.substring(0, i) + fileName + r.ExportUrlBase.substring(j, r.ExportUrlBase.length);
}
}
else {
setTimeout(ModifyExportUrlBase, 1000);
}
}
ModifyExportUrlBase();
Reporting Service 2017 seems to be implemented in quite different way than 2012. Has any one found a way to implement this functionality?
来源:https://stackoverflow.com/questions/58958486/sql-server-reporting-services-2017-change-export-file-name