這篇文章主要介紹了Angular中如何導(dǎo)出表格Excel表格,具有一定借鑒價值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。

克州ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!
現(xiàn)在前端都可以進(jìn)行excel文件的簡單導(dǎo)入導(dǎo)出操作。
下面是使用插件導(dǎo)出表格成excel文件示例
組件是基于ng-alain封裝的 XlsxService,XlsService是基于sheetjs開發(fā)的。
文未附相關(guān)資源
示例代碼
import { Component } from '@angular/core';
import { STColumn, XlsxService } from '@delon/abc';
@Component({
selector: 'components-xlsx-export',
template: `
<button nz-button (click)="download()">Export</button>
<!-- 為了方便使用了ng-alain表格組件,也可以用ng-zorro或者其他庫實現(xiàn)的表格。展現(xiàn)是次要的,重點是數(shù)據(jù) -->
<st [data]="users" [ps]="3" [columns]="columns" class="mt-sm"></st>
`,
})
export class ComponentsXlsxExportComponent {
constructor(private xlsx: XlsxService) {}
// 表格數(shù)據(jù)-模擬數(shù)據(jù)
users: any[] = Array(100)
.fill({})
.map((_item: any, idx: number) => {
return {
id: idx + 1,
name: `name ${idx + 1}`,
age: Math.ceil(Math.random() * 10) + 20,
};
});
columns: STColumn[] = [
{ title: '編號', index: 'id', type: 'checkbox' },
{ title: '姓名', index: 'name' },
{ title: '年齡', index: 'age' },
];
download() {
// 組裝要導(dǎo)出的數(shù)據(jù)
const data = [this.columns.map(i => i.title)];
this.users.forEach(i =>
data.push(this.columns.map(c => i[c.index as string])),
);
// 使用組件XlsxService導(dǎo)出數(shù)據(jù)為xls文件
this.xlsx.export({
filename: '自定義命名列表.xlsx',
sheets: [
{
data: data,
name: 'sheet name',
},
],
}); }
}感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享Angular中如何導(dǎo)出表格Excel表格內(nèi)容對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,遇到問題就找創(chuàng)新互聯(lián),詳細(xì)的解決方法等著你來學(xué)習(xí)!
當(dāng)前文章:Angular中如何導(dǎo)出表格Excel表格
標(biāo)題URL:http://www.chinadenli.net/article4/gspcie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司、微信公眾號、虛擬主機(jī)、全網(wǎng)營銷推廣、Google、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)