text 将数据导出为ex​​cel

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 将数据导出为ex​​cel相关的知识,希望对你有一定的参考价值。

import { Injectable } from '@angular/core';
import * as _filesaver from 'file-saver';
import * as XLSX from 'xlsx';
import { HttpClient } from '@angular/common/http';

const EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
const EXCEL_EXTENSION = '.xlsx';

@Injectable()
export class ExportExcelService {

  constructor(private Http: HttpClient) { }

  public exportAsExcelFile(json: any[], excelFileName: string): void {

    const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);

    const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };

    const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });

    this.saveAsExcelFile(excelBuffer, excelFileName);
  }

  public saveAsExcelFile(buffer: any, fileName: string): void {

    const data: Blob = new Blob([buffer], {
      type: EXCEL_TYPE
    });

    _filesaver.saveAs(data, fileName+EXCEL_EXTENSION);

  }

}

以上是关于text 将数据导出为ex​​cel的主要内容,如果未能解决你的问题,请参考以下文章

csharp 将数据导出为ex​​cel

需要将XML文件数据导出为ex​​cel文件

角度材料数据表导出为ex cel

RadGrid导出为ex cel

如何在Laravel中将子数组元素导出为ex cel

SAS将数据集导出为csv或excel,保留换行符