angular2 把请求到的json文件下载成Excel
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
ts文件
downLoadReport(content, filename) { // content:需要下载的内容;filename: 下载下来的文件类型
// 下载文件方法
const eleLink = document.createElement('a');
eleLink.download = filename;
eleLink.style.display = 'none';
// 字符内容转变成blob地址
const blob = new Blob([content]);
eleLink.href = URL.createObjectURL(blob);
// 触发点击
document.body.appendChild(eleLink);
eleLink.click();
// 然后移除
document.body.removeChild(eleLink);
}
downInitClick(content, filename) {
// 参数--pagesize:0;pageIndex:0--查询全部报表;
const data = {
ReportViewObjectPara: this.reportViewObjectPara,
ShowColumn: [],
pagesize: 0,
pageIndex: 0
};
for (const key in this.ShowColumnCheckbox) {
if (this.ShowColumnCheckbox[key]) {
data.ShowColumn.push(key);
}
}
if ('download' in document.createElement('a')) {
this.interfaceService.downloadService({//这里是封装过的axios请求
data: data,
onSuccess: (response) => {
// console.log('获取所有报表');
// console.log(JSON.parse(response.data.result.data.jsonStr));
const html = this.reportHtml(JSON.parse(response.data.result.data.jsonStr));
this.downLoadReport(html, '报表.xls');
},
onFalied: (error) => {
console.log(error);
}
});
} else {
alert('浏览器不支持');
}
}
// 拼接需要下载报表的HTML,并返回html;
reportHtml(reporttData) {
let html = `<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head><!--[if gte mso 9]>
<meta http-equiv="Content-Type"" content="text/html;charset=utf-8" />
<style> .xl24 {
mso-style-parent: style0;
mso-number-format: "" \\@ "";
text-align: right;
vnd . ms-excel .
numberformat: @
} </style>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>报表</x:Name>
<x:WorksheetOptions>
<x:DisplayGridlines/>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]--></head>
<body>`
html += `<table><thead>
<tr>
<th>姓名</th>
<th>航班号</th>
<th>是否泛嘉会员</th>
<th>起飞时间</th>
<th>起飞机场</th>
<th>到厅时间</th>
<th>离厅时间</th>
<th>操作人</th>
<th>操作机构</th>
<th>厅内消费</th>
<th>备注</th>
</tr>
</thead><tbody>`;
reporttData.forEach(item => {
html += `<tr>
<td>${item.PassengerName}</td>
<td>${item.FlightNo}</td>
<td>${item.IsVip}</td>
<td>${item.DepartureTime}</td>
<td>${item.DepartureAirportName}</td>
<td>${item.CheckInTime}</td>
<td>${item.CheckOutTime}</td>
<td>${item.CreatorUserName}</td>
<td>${item.InstitutionName}</td>
<td>${item.ConsumerGoodsRemark}</td>
<td>${item.Remark}</td></tr>`;
})
html += `</tbody></table></body></html>`;
return html;
}
html文件
<span class="s-btn-blue" (click)="downInitClick()">下载报表</span>
GitHub 加速计划 / js / json
18
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:3 个月前 )
f06604fc
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com> 2 天前
d23291ba
* add a ci step for Json_Diagnostic_Positions
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* Update ci.cmake to address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* address review comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix typo in the comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix typos in ci.cmake
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* invoke the new ci step from ubuntu.yml
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* issue4561 - use diagnostic positions for exceptions
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_documentation check
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci check failures for unit-diagnostic-postions.cpp
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* improvements based on review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix const correctness string
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* further refinements based on reviews
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* add one more test case for full coverage
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* ci check fix - add const
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* add unit tests for json_diagnostic_postions only
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_diagnostics
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_build_documentation check
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
---------
Signed-off-by: Harinath Nampally <harinath922@gmail.com> 3 天前
更多推荐
已为社区贡献2条内容
所有评论(0)