Function writeExcelFile

  • Write multiple tables to an Excel file as worksheets.

    Type Parameters

    • T

      The type of the data that will be written to the Excel file.

    Parameters

    • filepath: string

      The path where the Excel file will be written.

    • data: Record<string, T[][]>

      An object where each key is a worksheet name and the corresponding value is a 2D array of data to be written to that worksheet.

    Returns Promise<void>

    A Promise that resolves when the file has been written.

    Remarks

    This function creates a new Excel file or overwrites an existing one. Each key in the data object will be used as a worksheet name, and the corresponding 2D array will be written to that worksheet.

    Throws

    If there is an error writing the file.

    Example

    await writeExcelFile('path/to/file.xlsx', {
    employees: [
    ['Name', 'Age', 'Title'],
    ['John', 30, 'Software Developer'],
    ['Jane', 28, 'Data Scientist'],
    ],
    locations: [
    ['ID', 'Country', 'City'],
    [1, 'DK', 'Aarhus'],
    [2, 'DK', 'Copenhagen'],
    ],
    })

Generated using TypeDoc