Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

decode

  • decode(data: any[], sheetName?: string): string[][]
  • 读取excel文件二进制内容。

    Parameters

    • data: any[]

      excel文件二进制内容。

    • Optional sheetName: string

      excel文件sheetName, 不传默认取第一个。

    Returns string[][]

decodeAll

  • decodeAll(data: any[]): {}
  • 读取excel文件二进制内容。 获取所有sheet的文件内容,返回map结构数据

    Parameters

    • data: any[]

      excel文件二进制内容。

    Returns {}

    • [id: string]: string[][]

encode

  • encode(columns: string[], data: Object[]): any
  • 把对象数据编码为excel文件二进制内容。

    example
    
    import { encode } from 'excel';
    
    let value = encode(['a', 'b', 'c'], [{'a': 1, 'b': 2, 'c': 3}, {'a': 4, 'b': 5, 'c': 6}, {'a': 7, 'b': 2, 'c': 3}]);
    // 输出内容:
    // a b   c
    // 1 2   3
    // 4 5   6
    // 7 2   3
    

    Parameters

    • columns: string[]

      excel表格列名数组。

    • data: Object[]

      对象数据

    Returns any

encodeV2

  • encodeV2(columns: string[], data: any[]): any
  • 把数组内容编码为excel文件二进制内容。 与encode的区别时,对象输入是一个一维数组。

    example
    
    import { encodeV2 } from 'excel';
    
    let value = encodeV2(['a', 'b', 'c'], [1, 2, 3, 4, 5, 6, 7, 2, 3]);
    // 输出内容:
    // a b   c
    // 1 2   3
    // 4 5   6
    // 7 2   3
    

    Parameters

    • columns: string[]

      excel表格列名数组。

    • data: any[]

      数据数组,不能缺少一个数据。

    Returns any

encodeV3

  • encodeV3(sheets: string[], columns: {}, data: {}): any[]
  • 支持创建多个Sheet页,返回excel文件的二进制流。

    example
    
    import { encodeV3 } from 'excel';
    import * as context from 'context'
    
    let value = encodeV3(
        ['sheet1','sheet2'],
        {'sheet1':['a', 'b', 'c'], 'sheet2':['d', 'e', 'f']},
        {'sheet1':[1, 2, 3, 4, 5, 6, 7, 2, 3], 'sheet2':[1, 2, 3, 4, 5, 6, 7, 2, 3]});
    let response = context.getHttp().response;
    response.setBody(value)
    // 输出内容为excel文件,内容如下:
    // sheet1
    // a b   c
    // 1 2   3
    // 4 5   6
    // 7 2   3
    // sheet2
    // d e   f
    // 1 2   3
    // 4 5   6
    // 7 2   3
    

    Parameters

    • sheets: string[]

      excel表格的sheet数组。

    • columns: {}

      excel表格各页sheet的列名。

      • [id: string]: string[]
    • data: {}

      多sheet数据。key为sheet名,值为sheet中数据的数组。

      • [id: string]: any[]

    Returns any[]

    excel文件数据流