Excel Sheet

Syntax

	excelSheet(content: $content, name: $sheetName, colWidths: $colWidths, rowHeights: $rowHeights)

Description

Creates a worksheet for an Excel file. This function is used within excelFile() to define individual worksheets with names and contents.

A worksheet can either be in matrix format (a list of lists, where each inner list represents a row) or in cell format (a list of excelCell()).

Parameters

name Type Type Description Mandatory Default
Content Object The content of the worksheet. This can be a list of lists (matrix format) or a list of excelCell(). yes
name String The name of the worksheet that is displayed in the Excel tab. If the string is empty, a name is automatically generated. no ""
colWidths Map Map with column numbers as keys and column widths as values. The widths are specified in characters (e.g. {"0": 15, "1": 20}). no null
rowHeights Map Map with row numbers as keys and row heights as values. The heights are specified in points (e.g. {"0": 25, "1": 30}). no null

Return value

Type: Map

A map object containing the worksheet information for processing by excelFile().

Examples

Worksheet in matrix format

	excelSheet(
    name: "Mitarbeiterdaten",
    content: [
      ["Name", "Position", "Gehalt", "Eintrittsdatum"],
      ["Max Mustermann", "Entwickler", 65000, "2023-01-15"],
      ["Anna Schmidt", "Designerin", 58000, "2023-03-20"],
      ["Tom Weber", "Manager", 75000, "2022-11-10"]
    ]
  )

Output: Worksheet with tabular data in a simple grid format.

Worksheet with cell formatting and formulas

	excelSheet(
    name: "Berechnungen",
    content: [
      // Titelzeile
      excelCell(row: 0, col: 0, content: "Budgetübersicht 2024",
                style: excelStyle(bold: true, fontSize: 14, background: "#4472C4", color: "white", colSpan: 3)),

      // Spaltenüberschriften
      excelCell(row: 2, col: 0, content: "Kategorie", style: excelStyle(bold: true, background: "#D9E1F2")),
      excelCell(row: 2, col: 1, content: "Geplant", style: excelStyle(bold: true, background: "#D9E1F2")),
      excelCell(row: 2, col: 2, content: "Tatsächlich", style: excelStyle(bold: true, background: "#D9E1F2")),

      // Datenzeilen
      excelCell(row: 3, col: 0, content: "Marketing"),
      excelCell(row: 3, col: 1, content: 50000, style: excelStyle(numberFormat: "$#,##0")),
      excelCell(row: 3, col: 2, content: 52000, style: excelStyle(numberFormat: "$#,##0")),

      excelCell(row: 4, col: 0, content: "Entwicklung"),
      excelCell(row: 4, col: 1, content: 80000, style: excelStyle(numberFormat: "$#,##0")),
      excelCell(row: 4, col: 2, content: 75000, style: excelStyle(numberFormat: "$#,##0", color: "red")),

      // Summenzeile
      excelCell(row: 5, col: 0, content: "Gesamt", style: excelStyle(bold: true, borderTop: "double")),
      excelCell(row: 5, col: 1, content: excelFormula("SUM(B4:B5)"), style: excelStyle(numberFormat: "$#,##0", bold: true)),
      excelCell(row: 5, col: 2, content: excelFormula("SUM(C4:C5)"), style: excelStyle(numberFormat: "$#,##0", bold: true))
    ]
)

Output: Worksheet with formatted cells, various data types and Excel formulas.

Worksheet with customized column widths and row heights

	excelSheet(
    name: "Produktliste",
    content: [
      ["Produktname", "Beschreibung", "Preis", "Lagerbestand"],
      ["Widget Pro", "Hochwertiges Widget", 299.99, 150],
      ["Widget Basic", "Einfaches Widget", 99.99, 300],
      ["Widget Premium", "Premium Widget mit allen Funktionen", 499.99, 75]
    ],
    colWidths: {
      "0": 25, 
      "1": 40, 
      "2": 12,
      "3": 15 
    },
    rowHeights: {
      "0": 30
    }
  )

Output: Worksheet with customized column widths for better readability and raised header row.

Worksheet with automatic name generation

	excelSheet([
      ["Daten", "Wert"],
      ["Temperatur", 23.5],
      ["Luftfeuchtigkeit", 65]
    ]
  )

Output: Worksheet with automatically generated names such as "Sheet 1", "Sheet 2", etc.