From 9f9eb79638d7ffe081b089a246c8ca6321086e84 Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Tue, 2 Jun 2020 10:36:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=89=93=E5=8D=B0=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReportService/wwwroot/js/site.js | 32 ++++++++++++++++++++- ReportService/wwwroot/report/报表1.html | 37 +++++++++++++++++-------- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/ReportService/wwwroot/js/site.js b/ReportService/wwwroot/js/site.js index 445941c..a732032 100644 --- a/ReportService/wwwroot/js/site.js +++ b/ReportService/wwwroot/js/site.js @@ -83,5 +83,35 @@ var myjs = { this.post(this.urls.GetServerTime, { format: format }, function (r) { callback(r.str); }); - } + }, + toExcel: { + uri: 'data:application/vnd.ms-excel;base64,', + template: '' + + ' ' + + '{table}
', + base64(s) { + return window.btoa(unescape(encodeURIComponent(s))); + }, + format(s, c) { + return s.replace(/{(\w+)}/g, + function (m, p) { + return c[p]; + }); + }, + tableToExcel(tableid, sheetName) { + if (!tableid.nodeType) tableid = document.getElementById(tableid); + var ctx = { worksheet: sheetName || 'Worksheet', table: tableid.innerHTML }; + window.open(this.uri + this.base64(this.format(this.template, ctx))); + }, + }, }; \ No newline at end of file diff --git a/ReportService/wwwroot/report/报表1.html b/ReportService/wwwroot/report/报表1.html index b845cf8..942f29f 100644 --- a/ReportService/wwwroot/report/报表1.html +++ b/ReportService/wwwroot/report/报表1.html @@ -1,27 +1,29 @@ 
- - - + + + - + - + +
+ - - - - - + + + + + @@ -34,6 +36,7 @@
姓名年龄性别登录用户编号登录用户名姓名年龄性别登录用户编号登录用户名
+
@@ -41,6 +44,13 @@ var findPerson = new Vue({ el: "#findPerson", data: { + //存储过程名称 + ProcedureName: "example", + //报表名称 + reportName: "报表1", + + //除非你知道以下数据含义,否则不要修改 + sqlStr: "", url: myjs.urls.getresult, result: [], uid: "", @@ -53,7 +63,7 @@ methods: { find() { var sql = myjs.createSql("#para"); - $("input[name='sqlStr']").val(sql); + this.sqlStr = sql; console.log(sql); myjs.post(this.url, { sql: sql }, function (d) { findPerson.result = d; @@ -61,9 +71,12 @@ }, print() { var sql = myjs.createSql("#para"); - $("input[name='sqlStr']").val(sql); + this.sqlStr = sql; myjs.print(); }, + down() { + myjs.toExcel.tableToExcel("resultTable", this.reportName); + }, } });