modern-xlsx API Reference - v1.3.0
    Preparing search index...

    Function drawTable

    • Draw a styled table on a worksheet.

      Creates header row, data rows, applies styles, borders, column widths, merge cells, zebra striping, frozen panes, and auto-filter. columns[c].header overrides headers[c]. A Date cell is written as the serial of its UTC instant in the workbook's date system (an invalid Date leaves the cell empty), and a column holding a Date gets the number format yyyy-mm-dd unless columns[c].numberFormat is set; a bigint cell is written as a number when it is a safe integer and as a string otherwise.

      Parameters

      • wb: Workbook

        The parent Workbook (needed for shared styles).

      • ws: Worksheet

        The target Worksheet to draw the table on.

      • opts: DrawTableOptions

        Table configuration: headers, rows, styling, and layout options.

      Returns TableResult

      A TableResult with range metadata and row/column counts.

      When headers is empty.

      const result = drawTable(wb, ws, {
      headers: ['Name', 'Score'],
      rows: [['Alice', 95], ['Bob', 87]],
      headerColor: '4472C4',
      freezeHeader: true,
      });
      console.log(result.range); // 'A1:B3'