当WebViewer选择HtmlViewer浏览方式时,仅需添加以下代码就可以增加打印和导出功能。
源码下载:
- <script language="javascript" type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function () {
- $(".arvToolBar").append("<span style='margin-right:5px;'><input id='btnPrint' type='Button' value='打印' onclick='OnPrint()'/></span>");
- $(".arvToolBar").append("<span style='margin-right:5px;'><input id='btnExportPDF' type='Button' value='PDF' onclick='OnExportPDF()'/></span>");
- $(".arvToolBar").append("<span style='margin-right:5px;'><input id='btnExportWord' type='Button' value='Word' onclick='OnExportWord()'/></span>");
- $(".arvToolBar").append("<span style='margin-right:5px;'><input id='btnExportExcel' type='Button' value='Excel' onclick='OnExportExcel()'/></span>");
- });
- function OnExportPDF() {
- var viewModel = GetViewModel('WebViewer1');
- if (!viewModel.PageLoaded())
- return;
- viewModel.Export(ExportType.Pdf, function (url) {
- try {
- window.open(url, '_blank');
- } catch (e) {
- }
- }, true, { FileName: 'ActiveReports报表.pdf' });
- };
- function OnPrint() {
- var viewModel = GetViewModel('WebViewer1');
- if (!viewModel.PageLoaded())
- return;
- viewModel.Print();
- };
- function OnExportWord() {
- var viewModel = GetViewModel('WebViewer1');
- if (!viewModel.PageLoaded())
- return;
- viewModel.Export(ExportType.Word, function (url) {
- try {
- window.open(url, '_blank');
- } catch (e) {
- }
- }, true, { FileName: 'ActiveReports报表.doc' });
- };
- function OnExportExcel() {
- var viewModel = GetViewModel('WebViewer1');
- if (!viewModel.PageLoaded())
- return;
- viewModel.Export(ExportType.Xls, function (url) {
- try {
- window.open(url, '_blank');
- } catch (e) {
- }
- }, true, { FileName: 'ActiveReports报表.xlsx' });
- };
- </script>
复制代码
|