增加导出按钮
ActiveReportsJS 提供导出 API,在理论的业务场景中,能够依据本人的需要进行自定义导出。
上面咱们就来看看如何自定义增加导出按钮
1、ActiveReportsJS 增加按钮 API
viewer.toolbar.addItem();
2、导出 API
导出 Excel
function runExcel() {
var ARJS = GC.ActiveReports.Core;
var Excel = GC.ActiveReports.XlsxExport;
var settings = {
sheetName: '快递单',
pageSettings: {
size:'A4',
orientation: 'portrait'
}
}
var pageReport = new ARJS.PageReport();
pageReport.load('Quotation.rdlx-json')
.then(function() {return pageReport.run() })
.then(function(pageDocument) {return Excel.exportDocument(pageDocument, settings) })
.then(function(result) {result.download('arjs-excel') });
}
导出 PDF
function runPdf() {
var ARJS = GC.ActiveReports.Core;
var PDF = GC.ActiveReports.PdfExport;
var settings = {
info: {
title: '快递单',
author: 'GrapeCity inc.',
},
pdfVersion:"1.7"
}
var pageReport = new ARJS.PageReport();
pageReport.load('Quotation.rdlx-json')
.then(function() {return pageReport.run() })
.then(function(pageDocument) {return PDF.exportDocument(pageDocument, settings) })
.then(function(result) {result.download('arjs-pdf') });
}
导出 Html
function runHtml(){
var ARJS = GC.ActiveReports.Core;
var html= GC.ActiveReports.HtmlExport;
var pageReport = new ARJS.PageReport();
pageReport.load('reports/MonthSurvey.rdlx-json')
.then(function() {return pageReport.run() })
.then(function(pageDocument) {return html.exportDocument(pageDocument) })
.then(function(result) {result.download('arjs-html') });
}
**
3、工具栏增加导出按钮 (导出 Excel、PDF、Html)**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>ActiveReportsJS sample</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="/dist/ie-polyfills.js"></script>
<script src="/dist/ar-js-core.js"></script>
<script src="/dist/ar-js-designer.js"></script>
<script src="/dist/ar-js-viewer.js"></script>
<script src="/dist/ar-js-xlsx.js"></script>
<script src="/dist/ar-js-pdf.js"></script>
<script src="/dist/ar-js-html.js"></script>
<script src="/dist/designer/zh-locale.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap"
rel="stylesheet" />
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
crossorigin="anonymous" />
<link rel="stylesheet"
type="text/css"
href="/styles/ar-js-ui.css" />
<link rel="stylesheet"
type="text/css"
href="/styles/ar-js-viewer.css" />
<link rel="stylesheet"
type="text/css"
href="/styles/ar-js-designer.css" />
<style>
#viewer-host {
margin: 0 auto;
width: 100%;
height: 100vh;
}
</style>
<body onload="load()">
<div class="container">
<div style="width:100% ;height:800px;" id="root" ></div>
</div>
<script>
function load() {viewer = new ActiveReports.Viewer('#root', { language: 'zh'});
var svgExcelLogo = atob('PHN2ZyB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOmNjPSJodHRwOi8vY3JlYXRpdmVjb21tb25zLm9yZy9ucyMiIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyIgeG1sbnM6c3ZnPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczpzb2RpcG9kaT0iaHR0cDovL3NvZGlwb2RpLnNvdXJjZWZvcmdlLm5ldC9EVEQvc29kaXBvZGktMC5kdGQiIHhtbG5zOmlua3NjYXBlPSJodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy9uYW1lc3BhY2VzL2lua3NjYXBlIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCA4OC4wMzAwNjYgODYiIHZlcnNpb249IjEuMSIgaWQ9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uMSwwLjksMiwyLDJoMjNjMS4xLDAsMi0wLjksMi0ydi03YzAtMS4xLTAuOS0yLTItMkg2TDYsMTR6IE0yOSwyMnYxaC01di03aDF2NkgyOUwyOSwyMnogTTE0LDE3djZoMXYtNiBoMnYtMWgtNXYxSDE0TDE0LDE3eiBNMTAsMTl2LTNoMXY3aC0xdi0zSDd2M0g2di03aDF2M0gxMEwxMCwxOXogTTIwLjUsMTlMMTksMTZoLTAuNUgxOHY3aDF2LTVsMSwyaDAuNUgyMWwxLTJ2NWgxdi03aC0wLjVIMjIgTDIwLjUsMTlMMjAuNSwxOXoiLz48L2c+PC9nPjwvc3ZnPg==');
//htmlExportButton using svg icon
xlsxExportButton = {
key: 'xlsxExternalExportButton',
icon: {type: 'svg', content: svgExcelLogo},
title: "Excel Export",
checked: true,
enabled: true,
action: function (item) {var settings = { creator: 'Jack', password: 'Pwd'};
var cancelCallback = function () {return false;}
viewer.export('xlsx', settings, { cancel: cancelCallback})
.then(result => result.download("Exported_XLSX"));
}
};
pdfExportButton = {
key: 'pdfExternalExportButton',
iconCssClass: 'mdi mdi-file',
text: "PDF Export",
title: "PDF Export",
checked: true,
enabled: true,
action: function (item) {var settings = { title: 'Invoice List', userPassword: 'user_Pwd'};
var cancelCallback = function () {return false;}
viewer.export('pdf', settings, { cancel: cancelCallback})
.then(result => result.download("Exported_PDF"));
}
};
htmlExportButton = {
key: 'htmlExternalExportButton',
icon: {type: 'svg', content: svgHTMLLogo},
title: "HTML Export",
checked: true,
enabled: true,
action: function (item) {var settings = { autoPrint: 'true'};
var cancelCallback = function () {return false;}
viewer.export('html', settings, { cancel: cancelCallback})
.then(result => result.download("Exported_HTML"));
}
};
//Add ExportExcel button
viewer.toolbar.addItem(xlsxExportButton);
viewer.toolbar.addItem(pdfExportButton);
viewer.toolbar.addItem(htmlExportButton);
viewer.registerFont("fonts/fontsConfig.json").then(function () {viewer.open('reports/ 钻头应用状况.rdlx-json'); });
}
</script>
</body>
</html>
**4、预览展现
**