L2 Hub
Google
gsheets
Combine Sheets

L2 Construct: combine_sheets

sheets google

Description

UnionSheets combines data from multiple sheets within a Google Sheets spreadsheet into a new sheet. It copies the content of specified sheets, maintaining the header structure of the first sheet, and concatenates the rows into a new sheet.

The function requires:

  • A valid spreadsheet ID
  • A list of sheets to copy, each with a sheet name and optional origin point
  • A name for the new sheet where data will be combined
  • An optional origin point for the new sheet (defaults to top-left if not provided)

It returns the spreadsheet ID, the name of the new combined sheet, and the total number of rows copied. This function requires valid Google Sheets API credentials and appropriate permissions to access and modify the specified spreadsheet.

L2 Data

  1. Provider: google
  2. Module: gsheets
  3. Action: combine_sheets

Example Step

{
  "name": "insert-your-step-name",
  "type": "l2",
  "l2_data": {
    "provider": "google",
    "module": "gsheets",
    "action": "combine_sheets",
    "metadata": {}
  }
}
 

Input

Example

{
  "spreadsheet_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
  "sheets_to_combine": [
    {
      "sheet_name": "Sheet1",
      "start_row": 0,
      "start_col": 0
    },
    {
      "sheet_name": "Sheet2",
      "start_row": 0,
      "start_col": 0
    }
  ],
  "new_sheet_name": "CombinedSheet",
  "new_sheet_origin": {
    "row": 0,
    "col": 0
  }
}
 

Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pontus.bpa/pkgs/l2/google/gsheets/combine-sheets-input",
  "$ref": "#/$defs/CombineSheetsInput",
  "$defs": {
    "CombineSheetsInput": {
      "properties": {
        "spreadsheet_id": {
          "type": "string"
        },
        "sheets_to_combine": {
          "items": {
            "$ref": "#/$defs/CopySheet"
          },
          "type": "array"
        },
        "new_sheet_name": {
          "type": "string"
        },
        "new_sheet_origin": {
          "$ref": "#/$defs/Origin"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["spreadsheet_id", "sheets_to_combine", "new_sheet_name"]
    },
    "CopySheet": {
      "properties": {
        "sheet_name": {
          "type": "string"
        },
        "start_row": {
          "type": "integer"
        },
        "start_col": {
          "type": "integer"
        },
        "margin": {
          "skip_last_n_rows": {
            "type": "integer"
          },
          "max_empty_rows": {
            "type": "integer"
          }
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["sheet_name", "start_row", "start_col"]
    },
    "Origin": {
      "properties": {
        "row": {
          "type": "integer"
        },
        "col": {
          "type": "integer"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["row", "col"]
    }
  }
}
 

Output

Example

{
  "spreadsheet_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
  "new_sheet_name": "CombinedSheet",
  "rows_copied": 100,
  "error": {
    "is_error": false
  }
}
 

Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pontus.bpa/pkgs/l2/google/gsheets/combine-sheets-output",
  "$ref": "#/$defs/CombineSheetsOutput",
  "$defs": {
    "CombineSheetsOutput": {
      "properties": {
        "spreadsheet_id": {
          "type": "string"
        },
        "new_sheet_name": {
          "type": "string"
        },
        "rows_copied": {
          "type": "integer"
        },
        "error": {
          "$ref": "#/$defs/HandlerError"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["spreadsheet_id", "new_sheet_name", "rows_copied", "error"]
    },
    "HandlerError": {
      "properties": {
        "is_error": {
          "type": "boolean"
        },
        "errors": {
          "items": {
            "type": "string"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["is_error"]
    }
  }
}