vue-cli使用stimulsoft.reports.js的詳細(xì)教程
vue-cli使用stimulsoft.reports.js(保姆級(jí)教程)
第一部分:數(shù)據(jù)源準(zhǔn)備
以下是JSON數(shù)據(jù)的教程







json數(shù)據(jù)結(jié)構(gòu)
{
"數(shù)據(jù)源名":[
// ...數(shù)據(jù)列表
]
}
自己的測(cè)試JSON數(shù)據(jù)
{
"data": [
{
"a": "我是A",
"b": "我是B",
"c": "我是C"
},
{
"a": "我是A",
"b": "我是B",
"c": "我是C"
},
{
"a": "我是A",
"b": "我是B",
"c": "我是C"
}
]
}
附上官方處數(shù)據(jù)(自己刪減了一些數(shù)據(jù)讓讀者能更好看懂結(jié)構(gòu))
{
"Customers": [{
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"Address": "Obere Str. 57",
"City": "Berlin",
"Region": null,
"PostalCode": "12209",
"Country": "Germany",
"Phone": "030-0074321",
"Fax": "030-0076545"
}, {
"CustomerID": "ANATR",
"CompanyName": "Ana Trujillo Emparedados y helados",
"ContactName": "Ana Trujillo",
"ContactTitle": "Owner",
"Address": "Avda. de la Constitución 2222",
"City": "México D.F.",
"Region": null,
"PostalCode": "05021",
"Country": "Mexico",
"Phone": "(5) 555-4729",
"Fax": "(5) 555-3745"
}]
}
第二部分:vue-cli引入stimulsoft.reports.js


附上App.vue代碼
分別有展示數(shù)據(jù)、打印數(shù)據(jù)、保存數(shù)據(jù)、導(dǎo)入json數(shù)據(jù)的功能測(cè)試
<template>
<div id="app">
<div>
<h2>Stimulsoft Reports.JS Viewer</h2>
<button @click="print">打印</button>
<button @click="save">保存</button>
<button @click="setJson">設(shè)置JSON</button>
<div id="viewer"></div>
</div>
</div>
</template>
<script>
export default {
name: "app",
data() {
return {};
},
// 加載官方示例模板代碼
mounted: function () {
console.log("加載查看器視圖");
// 工具欄
console.log("創(chuàng)建具有默認(rèn)選項(xiàng)的報(bào)表查看器");
var viewer = new window.Stimulsoft.Viewer.StiViewer(
null,
"StiViewer",
false
);
// 報(bào)表
console.log("創(chuàng)建一個(gè)新的報(bào)表實(shí)例");
var report = new window.Stimulsoft.Report.StiReport();
// 加載文件
console.log("從url加載報(bào)告");
report.loadFile("/reports/SimpleList.mrt");
// 創(chuàng)建報(bào)表
console.log("將報(bào)表分配給查看器,報(bào)表將在呈現(xiàn)查看器之后自動(dòng)生成 ");
viewer.report = report;
// 注入標(biāo)簽
console.log("將查看器呈現(xiàn)給選定的元素");
viewer.renderHtml("viewer");
console.log("加載成功完成!");
},
methods: {
// 調(diào)用打印機(jī)打印數(shù)據(jù)
print() {
var report = new window.Stimulsoft.Report.StiReport();
report.loadFile("/reports/SimpleList.mrt");
report.print();
},
// 導(dǎo)出保存數(shù)據(jù)
save() {
var report = new window.Stimulsoft.Report.StiReport();
report.loadFile("/reports/SimpleList.mrt");
// 將呈現(xiàn)的報(bào)告保存為JSON字符串
var json = report.saveDocumentToJsonString();
console.log("json", json);
// 獲取報(bào)告文件名
var fileName = report.reportAlias
? report.reportAlias
: report.reportName;
console.log("report.reportName", report.reportName);
console.log("report.reportAlias", report.reportAlias);
console.log("fileName", fileName);
// 將數(shù)據(jù)保存到文件
window.Stimulsoft.System.StiObject.saveAs(
json,
fileName + ".mdc",
"application/json;charset=utf-8"
);
},
// 獲取json數(shù)據(jù)并寫入頁(yè)面
setJson() {
var report = new window.Stimulsoft.Report.StiReport();
// report.loadFile("/reports/SimpleList.mrt");// 官方數(shù)據(jù)模板
report.loadFile("/reports/Test.mrt");// 自己的數(shù)據(jù)模板
// 創(chuàng)建新的DataSet對(duì)象
var dataSet = new window.Stimulsoft.System.Data.DataSet("JSON");
// 將JSON數(shù)據(jù)文件從指定的URL加載到DataSet對(duì)象
// dataSet.readJsonFile("/reports/Demo.json");//官方數(shù)據(jù)
dataSet.readJsonFile("/reports/Test.json");// 自己的json數(shù)據(jù)
//文件用上面的readJsonFile方式導(dǎo)入,接口網(wǎng)絡(luò)請(qǐng)求用下面這種方式進(jìn)行導(dǎo)入
// let json=/*此處省略獲取數(shù)據(jù)請(qǐng)求*/
// dataSet.readJson(JSON.stringify(json));
// 清除報(bào)告模板中數(shù)據(jù)
report.dictionary.databases.clear();
// 注冊(cè)數(shù)據(jù)集對(duì)象
report.regData("JSON", "JSON", dataSet);
// 用注冊(cè)數(shù)據(jù)呈現(xiàn)報(bào)表
// report.render();
// 工具欄
var viewer = new window.Stimulsoft.Viewer.StiViewer(
null,
"StiViewer",
false
);
// 創(chuàng)建報(bào)表
viewer.report = report;
// 注入標(biāo)簽
viewer.renderHtml("viewer");
},
},
};
</script>
<style>
</style>
最后附上本人測(cè)試項(xiàng)目連接
項(xiàng)目鏈接
鏈接: https://pan.baidu.com/s/1HahzqHgFXvHT6OuE4IqzgQ
提取碼: vr57?
工具鏈接
鏈接: https://pan.baidu.com/s/1374m-kCBZBeOdlDrAbXtbQ?
提取碼: dfkc
官方教程鏈接
https://www.evget.com/serializedetail/510
到此這篇關(guān)于vue-cli使用stimulsoft.reports.js的文章就介紹到這了,更多相關(guān)vue-cli使用stimulsoft.reports.js內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
crypto-js對(duì)稱加密解密的使用方式詳解(vue與java端)
這篇文章主要介紹了如何在Vue前端和Java后端使用crypto-js庫(kù)進(jìn)行AES加密和解密,前端通過(guò)創(chuàng)建AES.js文件來(lái)實(shí)現(xiàn)加密解密功能,并在Vue文件或JavaScript中使用,后端則可以直接使用Java代碼進(jìn)行AES加密和解密操作,需要的朋友可以參考下2025-01-01
vue中使用AJAX實(shí)現(xiàn)讀取來(lái)自XML文件的信息
這篇文章主要為大家詳細(xì)介紹了vue中如何使用AJAX實(shí)現(xiàn)讀取來(lái)自XML文件的信息,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的小伙伴可以參考下2023-12-12
vue webpack打包后圖片路徑錯(cuò)誤的完美解決方法
這篇文章主要介紹了vue webpack打包后圖片路徑錯(cuò)誤的解決方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-12-12
vue3.0路由自動(dòng)導(dǎo)入的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于vue3.0路由自動(dòng)導(dǎo)入的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04
vue實(shí)現(xiàn)移動(dòng)端touch拖拽排序
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)移動(dòng)端touch拖拽排序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07

