实时数据填充的时候报错,但是我的数据集名称已经完全改成一样的了
- <template>
- <div>
- <button @click="generateReport">生成并打印报表</button>
- </div>
- </template>
- <script>
- import { ref, onMounted } from 'vue';
- export default {
- name: 'PrintReport',
- setup() {
- const reportLoaded = ref(false);
- // 动态加载 ar-js-core.js 脚本
- const loadScript = (src) => {
- return new Promise((resolve, reject) => {
- const script = document.createElement('script');
- script.src = src;
- script.onload = resolve;
- script.onerror = reject;
- document.head.appendChild(script);
- });
- };
- // 加载 ActiveReportsJS 核心库
- onMounted(() => {
- loadScript('../../../../../node_modules/@grapecity/activereports/dist/ar-js-core.js') // 替换为实际的路径
- .then(() => {
- console.log('ActiveReportsJS 核心库加载成功');
- reportLoaded.value = true;
- })
- .catch((err) => {
- console.error('加载 ActiveReportsJS 核心库失败:', err);
- });
- });
- // 生成报表的方法
- const generateReport = () => {
- if (!window.GC || !window.GC.ActiveReports || !reportLoaded.value) {
- console.error('ActiveReportsJS 核心库未加载或尚未准备好');
- return;
- }
- const ARJS = window.GC.ActiveReports.Core;
- const report = new ARJS.PageReport();
- report
- .load('V2.rdlx-json') // 你的报表文件
- .then(() => {
- const dataSet = {
- name: 'MyData', // 数据集名称必须匹配报表中的名称
- data: [
- { pieceName: 1, colorName1: 'Item 1', barcodeQty: 10 },
- { pieceName: 2, colorName1: 'Item 2', barcodeQty: 20 },
- { pieceName: 3, colorName1: 'Item 3', barcodeQty: 30 },
- ],
- };
- report.dataSets = [dataSet];
- return report.run();
- })
- .then((pageDocument) => {
- pageDocument.print();
- })
- .catch((err) => {
- console.error('生成报表失败: ', err);
- });
- };
- return {
- generateReport,
- };
- },
- };
- </script>
- <style scoped>
- button {
- margin-top: 20px;
- padding: 10px 20px;
- background-color: #4caf50;
- color: white;
- border: none;
- border-radius: 5px;
- cursor: pointer;
- }
- </style>
复制代码- {
- "Name": "multisectionreport1111",
- "Width": "0in",
- "Layers": [
- {
- "Name": "default"
- }
- ],
- "CustomProperties": [
- {
- "Name": "DisplayType",
- "Value": "Page"
- },
- {
- "Name": "SizeType",
- "Value": "Default"
- },
- {
- "Name": "CollapseWhiteSpace",
- "Value": "True"
- }
- ],
- "Version": "7.6.0",
- "Page": {
- "PageWidth": "8.5in",
- "PageHeight": "11in",
- "RightMargin": "0in",
- "LeftMargin": "0in",
- "TopMargin": "0in",
- "BottomMargin": "0in",
- "Columns": 1,
- "ColumnSpacing": "0.5in",
- "PaperOrientation": "Portrait"
- },
- "DataSources": [
- {
- "Name": "MyData",
- "ConnectionProperties": {
- "DataProvider": "JSONEMBED",
- "ConnectString": "jsondata="
- }
- }
- ],
- "ReportSections": [
- {
- "Type": "Continuous",
- "Name": "报表区域1",
- "Page": {
- "PageWidth": "8.5in",
- "PageHeight": "11in",
- "RightMargin": "1in",
- "LeftMargin": "1in",
- "TopMargin": "1in",
- "BottomMargin": "1in",
- "Columns": 1,
- "ColumnSpacing": "0in",
- "PaperOrientation": "Portrait"
- },
- "Width": "8.0972in",
- "Body": {
- "Height": "1.3534in",
- "ReportItems": [
- {
- "Type": "list",
- "Name": "列表1",
- "DataSetName": "MyData",
- "RowsOrColumnsCount": 2,
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "ExtraLight"
- },
- "ReportItems": [
- {
- "Type": "inputfield",
- "Name": "输入字段2",
- "ZIndex": 18,
- "Value": "="裁片號 " & Fields!serialNumber.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Left": "0.008in",
- "Top": "0.2238in",
- "Width": "1.2606in",
- "Height": "0.191in"
- },
- {
- "Type": "inputfield",
- "Name": "输入字段3",
- "ZIndex": 15,
- "Value": "="制單 " & Fields!worksheetCode.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Left": "0.004in",
- "Top": "0.4247in",
- "Width": "1.2606in",
- "Height": "0.1876in"
- },
- {
- "Type": "inputfield",
- "Name": "输入字段4",
- "Value": "="尺碼 " & Fields!size.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Left": "0.004in",
- "Top": "0.6123in",
- "Width": "1.2606in",
- "Height": "0.1876in"
- },
- {
- "Type": "inputfield",
- "Name": "输入字段5",
- "ZIndex": 7,
- "Value": "="件數 " & Fields!barcodeQty.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Top": "0.8054in",
- "Width": "1.2606in",
- "Height": "0.1876in"
- },
- {
- "Type": "inputfield",
- "Name": "输入字段6",
- "ZIndex": 9,
- "Value": "="單號 " & Fields!splitCode.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Left": "1.514in",
- "Top": "0.008in",
- "Width": "1.7665in",
- "Height": "0.1876in"
- },
- {
- "Type": "inputfield",
- "Name": "输入字段7",
- "ZIndex": 10,
- "Value": "="款式 " & Fields!productCode.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Left": "1.5079in",
- "Top": "0.2061in",
- "Width": "1.7397in",
- "Height": "0.1876in"
- },
- {
- "Type": "inputfield",
- "Name": "输入字段8",
- "ZIndex": 11,
- "Value": "="顏色 " & Fields!colorName1.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Left": "1.5203in",
- "Top": "0.4193in",
- "Width": "1.2605in",
- "Height": "0.1876in"
- },
- {
- "Type": "inputfield",
- "Name": "输入字段9",
- "ZIndex": 12,
- "Value": "="編號 " & Fields!barcodeNum.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Left": "1.5161in",
- "Top": "0.8101in",
- "Width": "1.2605in",
- "Height": "0.1876in"
- },
- {
- "Type": "inputfield",
- "Name": "输入字段10",
- "ZIndex": 13,
- "Value": "="床號 " & Fields!bedNum.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Left": "1.5205in",
- "Top": "0.6091in",
- "Width": "1.2605in",
- "Height": "0.1876in"
- },
- {
- "Type": "inputfield",
- "Name": "输入字段11",
- "ZIndex": 14,
- "Value": "="裁片名稱 " & Fields!pieceName.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Left": "1.5018in",
- "Top": "1.0336in",
- "Width": "1.2605in",
- "Height": "0.1876in"
- },
- {
- "Type": "barcode",
- "Name": "条形码1",
- "ZIndex": 20,
- "Value": "=Fields!qrCodeValue.Value",
- "Symbology": "EAN_13",
- "CaptionLocation": "Below",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "ExtraLight"
- },
- "Left": "0.0521in",
- "Top": "1.0234in",
- "Width": "1.2837in",
- "Height": "0.2615in"
- },
- {
- "Type": "inputfield",
- "Name": "输入字段1",
- "ZIndex": 21,
- "Value": "="合同 " & Fields!contract.Value",
- "Style": {
- "TopBorder": {
- "Style": "None"
- },
- "BottomBorder": {
- "Style": "None"
- },
- "LeftBorder": {
- "Style": "None"
- },
- "RightBorder": {
- "Style": "None"
- },
- "FontSize": "8pt",
- "FontWeight": "Bold"
- },
- "Left": "0.004in",
- "Top": "0.012in",
- "Width": "1.2606in",
- "Height": "0.191in"
- }
- ],
- "Width": "8.0972in",
- "Height": "1.3534in"
- }
- ]
- }
- }
- ]
- }
复制代码
|