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

    Function drawTableFromData

    • Create a styled table from a JSON array.

      Automatically extracts headers from object keys and maps values to rows. With no data and no explicit headers, nothing is drawn and the result has an empty range; with explicit headers only the header row is drawn.

      Parameters

      • wb: Workbook

        The parent Workbook (needed for shared styles).

      • ws: Worksheet

        The target Worksheet to draw the table on.

      • data: Record<string, unknown>[]

        Array of JSON objects representing the table rows.

      • Optionalopts: DrawTableFromDataOptions

        Optional overrides for headers, header labels, styling, and layout.

      Returns TableResult

      A TableResult with range metadata and row/column counts.

      const result = drawTableFromData(wb, ws, [
      { name: 'Alice', score: 95 },
      { name: 'Bob', score: 87 },
      ], { autoWidth: true });