Html5Viewer默认会提供打印和导出按钮,这样会给我们带来很多方便,而不需要自己定制,但是HTML5Viewer 导出按钮默认是以ActiveReports 命名的,因此我们需要来修改可另存为报表的名称。
在本篇文章来学习如何修改HTML5Viewer的导出文件名.
因为H5提供了Export方法来导出报表,所以修改导出文件名称,也需要从这个方法下手。
1.初始化Html5Viewer
var reportName = 'Reports/Symbol.rdlx'; var viewer; // init viewer $(function () { viewer = GrapeCity.ActiveReports.Viewer({ element: '#viewer', uiType: 'desktop', reportService: { url: '/ActiveReports.ReportService.asmx' }, report: { id: reportName }, availableExports: ['Xls', 'Pdf', 'Word', 'Image', 'Mht'] });
2. 添加调用window.bind 事件
var customExport = function () { viewer.export("Xls", function (uri) { window.open(uri); }, true, { FileName: "MyFileName" }); // viewer.export("Pdf", function (uri) { window.open(uri); }, true, { FileName: "MyFileName" }); };
3. 拦截下载链接,并修改文件名称
$(document).ready(function () {
////pdfDocument: "PDF Document",
//wordDocument: "Word Document",
//imageFile: "Image File",
//mhtDocument: "MHTML Web Archives",
//excelWorkbook: "Excel Workbook",
var list = ["PDF Document", "Excel Workbook"];
for (var i = 0; i < list.length; i++) {
var excelLink = $('a:contains("' + list[i] + '")');
ko.cleanNode(excelLink[0]);
excelLink.removeAttr('data-bind');
excelLink.removeAttr('disabled');
excelLink.attr('target', '_blank');
excelLink.attr('href', 'javascript:customExport()');
}
});
源码下载: