Skip to content

Commit 0a70949

Browse files
chore: regenerate .osts files
1 parent dd1e7b6 commit 0a70949

16 files changed

Lines changed: 16 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"0.3.0","body":"/**\r\n * Adds one or more rows to an Excel table from a JSON array.\r\n * Columns not present in the input JSON will be left empty for that row.\r\n *\r\n * @param tableName Name of the table to add rows to.\r\n * @param inputJson JSON string containing an array of objects where keys match table column names.\r\n */\r\nfunction main(\r\n workbook: ExcelScript.Workbook,\r\n tableName: string,\r\n inputJson: string\r\n) {\r\n const table = workbook.getTable(tableName);\r\n if (!table) {\r\n throw new Error(`Table '${tableName}' not found.`);\r\n }\r\n\r\n const columnNames = table.getColumns().map(col => col.getName().trim());\r\n\r\n let inputData: Record<string, string>[];\r\n try {\r\n inputData = JSON.parse(inputJson);\r\n } catch (e) {\r\n throw new Error(`Failed to parse input JSON: ${e.message}`);\r\n }\r\n\r\n if (!Array.isArray(inputData) || inputData.length === 0) {\r\n return \"Input JSON contains no rows to add.\";\r\n }\r\n\r\n // validate input keys\r\n const inputKeys = Object.keys(inputData[0]).map(k => k.trim());\r\n for (const key of inputKeys) {\r\n if (!columnNames.includes(key)) {\r\n throw new Error(`Input key '${key}' does not match any column in the table '${tableName}'.`);\r\n }\r\n }\r\n\r\n // build 2D array matching table column order\r\n const rows = inputData.map(obj =>\r\n columnNames.map(colName => obj[colName] ?? undefined)\r\n );\r\n console.log(rows);\r\n\r\n table.addRows(-1, rows);\r\n\r\n return \"Rows added successfully.\";\r\n}","description":"Adds one or more rows to an Excel table from a JSON array. Columns not present in the input JSON will be left empty for that row.","noCodeMetadata":"","parameterInfo":"{\"version\":1,\"originalParameterOrder\":[{\"name\":\"tableName\",\"index\":0},{\"name\":\"inputJson\",\"index\":1}],\"parameterSchema\":{\"type\":\"object\",\"required\":[\"tableName\",\"inputJson\"],\"properties\":{\"tableName\":{\"type\":\"string\"},\"inputJson\":{\"type\":\"string\"}}},\"returnSchema\":{\"type\":\"object\",\"properties\":{}},\"signature\":{\"comment\":\"\",\"parameters\":[{\"name\":\"workbook\",\"comment\":\"\"},{\"name\":\"tableName\",\"comment\":\"\"},{\"name\":\"inputJson\",\"comment\":\"\"}]}}","apiInfo":"{\"variant\":\"synchronous\",\"variantVersion\":2}"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"0.3.0","body":"/**\r\n * Auto-fits the column widths for all columns in a table to best fit their contents.\r\n *\r\n * @param tableName Name of the table to auto-fit columns for.\r\n */\r\nfunction main(\r\n workbook: ExcelScript.Workbook,\r\n tableName: string\r\n) {\r\n const table = workbook.getTable(tableName);\r\n if (!table) {\r\n throw new Error(`Table '${tableName}' not found.`);\r\n }\r\n\r\n table.getRange().getFormat().autofitColumns();\r\n}","description":"Auto-fits the column widths for all columns in a table to best fit their contents.","noCodeMetadata":"","parameterInfo":"{\"version\":1,\"originalParameterOrder\":[{\"name\":\"tableName\",\"index\":0}],\"parameterSchema\":{\"type\":\"object\",\"required\":[\"tableName\"],\"properties\":{\"tableName\":{\"type\":\"string\"}}},\"returnSchema\":{\"type\":\"object\",\"properties\":{}},\"signature\":{\"comment\":\"\",\"parameters\":[{\"name\":\"workbook\",\"comment\":\"\"},{\"name\":\"tableName\",\"comment\":\"\"}]}}","apiInfo":"{\"variant\":\"synchronous\",\"variantVersion\":2}"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"0.3.0","body":"/**\r\n * Clears the contents of a specific cell in a table by column name and row index.\r\n *\r\n * @param tableName Name of the table containing the cell.\r\n * @param columnName Name of the column containing the cell.\r\n * @param rowIndex Zero-based row index within the table's data range (excluding the header row).\r\n */\r\nfunction main(\r\n workbook: ExcelScript.Workbook,\r\n tableName: string,\r\n columnName: string,\r\n rowIndex: number\r\n) {\r\n const table = workbook.getTable(tableName);\r\n if (!table) {\r\n throw new Error(`Table '${tableName}' not found.`);\r\n }\r\n\r\n // Get all headers and find the column index\r\n const headers = table.getHeaderRowRange().getValues()[0];\r\n const columnIndex = headers.indexOf(columnName);\r\n\r\n if (columnIndex === -1) {\r\n throw new Error(`Column '${columnName}' not found.`);\r\n }\r\n\r\n // Get the row (excluding the header row)\r\n const rowRange = table.getRangeBetweenHeaderAndTotal();\r\n const targetCell = rowRange.getCell(rowIndex, columnIndex);\r\n\r\n targetCell.clear(ExcelScript.ClearApplyTo.contents);\r\n}","description":"Clears the contents of a specific cell in a table by column name and row index.","noCodeMetadata":"","parameterInfo":"{\"version\":1,\"originalParameterOrder\":[{\"name\":\"tableName\",\"index\":0},{\"name\":\"columnName\",\"index\":1},{\"name\":\"rowIndex\",\"index\":2}],\"parameterSchema\":{\"type\":\"object\",\"required\":[\"tableName\",\"columnName\",\"rowIndex\"],\"properties\":{\"tableName\":{\"type\":\"string\"},\"columnName\":{\"type\":\"string\"},\"rowIndex\":{\"type\":\"number\"}}},\"returnSchema\":{\"type\":\"object\",\"properties\":{}},\"signature\":{\"comment\":\"\",\"parameters\":[{\"name\":\"workbook\",\"comment\":\"\"},{\"name\":\"tableName\",\"comment\":\"\"},{\"name\":\"columnName\",\"comment\":\"\"},{\"name\":\"rowIndex\",\"comment\":\"\"}]}}","apiInfo":"{\"variant\":\"synchronous\",\"variantVersion\":2}"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"0.3.0","body":"/**\r\n * Converts values in specified table columns to Proper Case if they are entirely uppercase or entirely lowercase.\r\n * Handles accented characters common in European names.\r\n *\r\n * @param tableName Name of the table to process.\r\n * @param columnsToFix Array of column names whose values should be converted to Proper Case.\r\n */\r\nfunction main(\r\n workbook: ExcelScript.Workbook,\r\n tableName: string,\r\n columnsToFix: string[]\r\n) {\r\n const table = workbook.getTable(tableName);\r\n if (!table) {\r\n throw new Error(`Table \"${tableName}\" not found.`);\r\n }\r\n\r\n // Process each column\r\n columnsToFix.forEach(columnName => {\r\n const column = table.getColumnByName(columnName);\r\n if (!column) {\r\n throw new Error(`Input key '${columnName}' does not match any column in the table '${tableName}'.`);\r\n }\r\n\r\n let values = column.getRange().getValues();\r\n\r\n // Loop through each row in the column\r\n for (let i = 0; i < values.length; i++) {\r\n const cellValue = values[i][0];\r\n if (typeof cellValue !== \"string\" || cellValue.trim() === \"\") {\r\n continue;\r\n }\r\n\r\n // Check if the value is all uppercase or all lowercase\r\n if (cellValue === cellValue.toUpperCase() || cellValue === cellValue.toLowerCase()) {\r\n // Convert to Proper Case while handling accents\r\n const properCaseValue = cellValue.toLowerCase().replace(\r\n /(^|\\s)([a-záéíóúüñâàäêëîïôöûüç])/g,\r\n (_, boundary, letter) => boundary + letter.toUpperCase()\r\n );\r\n\r\n // Update the value in the array\r\n values[i][0] = properCaseValue;\r\n }\r\n }\r\n\r\n // Write the updated values back to the column\r\n column.getRange().setValues(values);\r\n });\r\n}","description":"Converts values in specified table columns to Proper Case if they are entirely uppercase or entirely lowercase. Handles accented characters common in European names.","noCodeMetadata":"","parameterInfo":"{\"version\":1,\"originalParameterOrder\":[{\"name\":\"tableName\",\"index\":0},{\"name\":\"columnsToFix\",\"index\":1}],\"parameterSchema\":{\"type\":\"object\",\"required\":[\"tableName\",\"columnsToFix\"],\"properties\":{\"tableName\":{\"type\":\"string\"},\"columnsToFix\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}},\"returnSchema\":{\"type\":\"object\",\"properties\":{}},\"signature\":{\"comment\":\"\",\"parameters\":[{\"name\":\"workbook\",\"comment\":\"\"},{\"name\":\"tableName\",\"comment\":\"\"},{\"name\":\"columnsToFix\",\"comment\":\"\"}]}}","apiInfo":"{\"variant\":\"synchronous\",\"variantVersion\":2}"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"0.3.0","body":"/**\r\n * Converts a table column's formulas to static values by copying the range as values-only.\r\n * Clears any active filters before converting to ensure all rows are affected.\r\n *\r\n * @param tableName Name of the table containing the column.\r\n * @param columnName Name of the column to convert.\r\n * @param fullColumn If true, converts the entire column. If false, only the last n rows are converted.\r\n * @param numberOfRowsFromEnd Number of rows from the end of the column to convert (required when fullColumn is false).\r\n */\r\nfunction main(\r\n workbook: ExcelScript.Workbook,\r\n tableName: string,\r\n columnName: string,\r\n fullColumn: boolean = false,\r\n numberOfRowsFromEnd?: number\r\n) {\r\n const table = workbook.getTable(tableName);\r\n if (!table) {\r\n throw new Error(`Table '${tableName}' not found.`);\r\n }\r\n\r\n const column = table.getColumnByName(columnName);\r\n if (!column) {\r\n throw new Error(`Column '${columnName}' not found.`);\r\n }\r\n\r\n // clear filters so following actions are not impacted\r\n table.getAutoFilter().clearCriteria();\r\n\r\n const totalColRange = column.getRangeBetweenHeaderAndTotal();\r\n\r\n let range: ExcelScript.Range;\r\n if (fullColumn) {\r\n range = totalColRange;\r\n\r\n } else if (numberOfRowsFromEnd) {\r\n range = totalColRange.getLastCell().getOffsetRange(1 - numberOfRowsFromEnd, 0).getAbsoluteResizedRange(numberOfRowsFromEnd, 1);\r\n\r\n } else {\r\n throw new Error(`Parameter 'numberOfRowsFromEnd' is required when fullColumn is set to false.`);\r\n }\r\n\r\n range.copyFrom(\r\n range,\r\n ExcelScript.RangeCopyType.values,\r\n false,\r\n false\r\n );\r\n}","description":"Converts a table column's formulas to static values by copying the range as values-only. Clears any active filters before converting to ensure all rows are affected.","noCodeMetadata":"","parameterInfo":"{\"version\":1,\"originalParameterOrder\":[{\"name\":\"tableName\",\"index\":0},{\"name\":\"columnName\",\"index\":1},{\"name\":\"fullColumn\",\"index\":2},{\"name\":\"numberOfRowsFromEnd?\",\"index\":3}],\"parameterSchema\":{\"type\":\"object\",\"required\":[\"tableName\",\"columnName\",\"fullColumn\",\"numberOfRowsFromEnd?\"],\"properties\":{\"tableName\":{\"type\":\"string\"},\"columnName\":{\"type\":\"string\"},\"fullColumn\":{\"type\":\"string\"},\"numberOfRowsFromEnd?\":{\"type\":\"number\"}}},\"returnSchema\":{\"type\":\"object\",\"properties\":{}},\"signature\":{\"comment\":\"\",\"parameters\":[{\"name\":\"workbook\",\"comment\":\"\"},{\"name\":\"tableName\",\"comment\":\"\"},{\"name\":\"columnName\",\"comment\":\"\"},{\"name\":\"fullColumn\",\"comment\":\"\"},{\"name\":\"numberOfRowsFromEnd?\",\"comment\":\"\"}]}}","apiInfo":"{\"variant\":\"synchronous\",\"variantVersion\":2}"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"0.3.0","body":"/**\r\n * Creates a pivot table from an existing table with specified row and value aggregations.\r\n * \r\n * @param tableName Name of the source table for the pivot table.\r\n * @param location Where to place the pivot table: \"New sheet\" creates a new worksheet, \"Existing sheet\" places it below the source table unless a sheet name is specified.\r\n * @param rowsColumn Column name to use for pivot table rows.\r\n * @param valuesColumns Array of column names to aggregate in the pivot table values area.\r\n * @param valuesOperation Aggregation function to apply to the values columns.\r\n * @param sheetName The name of the sheet the pivot table should be placed on when location is Existing sheet (defaults to same sheet as table). If location is New sheet, this is the name the new sheet should have.\r\n * @param pivotTableName Optional name for the pivot table (auto-generates if blank or already exists)\r\n */\r\nfunction main(\r\n workbook: ExcelScript.Workbook,\r\n tableName: string,\r\n location: \"New sheet\" | \"Existing sheet\" = \"New sheet\",\r\n rowsColumn: string,\r\n valuesColumns: Array<string>,\r\n valuesOperation: \"Sum\" | \"Count\" | \"Average\" | \"Product\" | \"Max\" | \"Min\" = \"Sum\",\r\n columnsColumn?: string,\r\n sheetName?: string,\r\n pivotTableName?: string\r\n) {\r\n const table = workbook.getTable(tableName);\r\n if (!table) {\r\n throw new Error(`Table '${tableName}' not found.`);\r\n }\r\n\r\n if (table.getRowCount() === 0) {\r\n throw new Error(`Table '${tableName}' has no data.`);\r\n }\r\n\r\n // make sure specified columns exist\r\n const tableCols = table.getColumns().map((col) => col.getName());\r\n if (!tableCols.includes(rowsColumn)) {\r\n throw new Error(`There is no column '${rowsColumn}' in table '${tableName}'.`);\r\n }\r\n else {\r\n valuesColumns.forEach((colName) => {\r\n if (!tableCols.includes(colName)) {\r\n throw new Error(`There is no column '${colName}' in table '${tableName}'.`);\r\n }\r\n });\r\n }\r\n\r\n // validate operation\r\n const operation = ExcelScript.AggregationFunction[valuesOperation.toLowerCase() as keyof typeof ExcelScript.AggregationFunction];\r\n if (!operation) {\r\n throw new Error(`Invalid operation: ${valuesOperation}`);\r\n }\r\n\r\n // get range of where to add pivot table\r\n let locationRange: ExcelScript.Range;\r\n if (location === \"New sheet\") {\r\n locationRange = workbook.addWorksheet(sheetName).getRange(\"A1\");\r\n } else {\r\n let locationReference: ExcelScript.Worksheet;\r\n if (sheetName) {\r\n const sheet = workbook.getWorksheet(sheetName);\r\n if (!sheet) {\r\n throw new Error(`There is no worksheet \"${sheetName}\" in the Excel file.`);\r\n }\r\n\r\n locationReference = sheet;\r\n } else {\r\n locationReference = table.getWorksheet();\r\n }\r\n const lastUsedRow = locationReference.getUsedRange().getLastRow();\r\n // 2 for offset + 1 for 0-based index\r\n console.log(`Destination: '${locationReference.getName()}'!A${lastUsedRow.getRowIndex() + 3}`);\r\n locationRange = lastUsedRow.getCell(0, 0).getOffsetRange(2, 0);\r\n }\r\n\r\n const usedSheetName = locationRange.getWorksheet().getName();\r\n\r\n // get next available pivot table name if provided one is taken or blank\r\n const existingPivotTables = workbook.getPivotTables().map((pvtTbl) => pvtTbl.getName());\r\n if (!pivotTableName || existingPivotTables.includes(pivotTableName)) {\r\n const defaultName = \"PivotTable\";\r\n let i = 1;\r\n const maxAttempts = 100;\r\n while (existingPivotTables.includes(defaultName + i) && i < maxAttempts) {\r\n i++;\r\n }\r\n\r\n if (i >= maxAttempts) {\r\n throw new Error(`Unable to generate unique pivot table name after ${i} attempts`);\r\n }\r\n\r\n pivotTableName = defaultName + i;\r\n }\r\n\r\n const pivotTable = workbook.addPivotTable(pivotTableName, table, locationRange);\r\n\r\n // add rows field to pivot table\r\n pivotTable.addRowHierarchy(pivotTable.getHierarchy(rowsColumn));\r\n\r\n // add columns field to pivot table if it exists\r\n if (columnsColumn) {\r\n pivotTable.addColumnHierarchy(pivotTable.getHierarchy(columnsColumn));\r\n }\r\n\r\n // add values fields to pivot table\r\n valuesColumns.forEach((colName) => {\r\n const valuesField = pivotTable.addDataHierarchy(pivotTable.getHierarchy(colName));\r\n valuesField.setSummarizeBy(operation);\r\n });\r\n\r\n return {\r\n \"message\": \"Successfully created a pivot table.\",\r\n \"createdPivotTableName\": pivotTableName,\r\n \"usedSheetName\": usedSheetName\r\n }\r\n}","description":"Creates a pivot table from an existing table with specified row and value aggregations.","noCodeMetadata":"","parameterInfo":"{\"version\":1,\"originalParameterOrder\":[{\"name\":\"tableName\",\"index\":0},{\"name\":\"location\",\"index\":1},{\"name\":\"rowsColumn\",\"index\":2},{\"name\":\"valuesColumns\",\"index\":3},{\"name\":\"valuesOperation\",\"index\":4},{\"name\":\"columnsColumn?\",\"index\":5},{\"name\":\"sheetName?\",\"index\":6},{\"name\":\"pivotTableName?\",\"index\":7}],\"parameterSchema\":{\"type\":\"object\",\"required\":[\"tableName\",\"location\",\"rowsColumn\",\"valuesColumns\",\"valuesOperation\",\"columnsColumn?\",\"sheetName?\",\"pivotTableName?\"],\"properties\":{\"tableName\":{\"type\":\"string\"},\"location\":{\"type\":\"string\"},\"rowsColumn\":{\"type\":\"string\"},\"valuesColumns\":{\"type\":\"string\"},\"valuesOperation\":{\"type\":\"string\"},\"columnsColumn?\":{\"type\":\"string\"},\"sheetName?\":{\"type\":\"string\"},\"pivotTableName?\":{\"type\":\"string\"}}},\"returnSchema\":{\"type\":\"object\",\"properties\":{}},\"signature\":{\"comment\":\"\",\"parameters\":[{\"name\":\"workbook\",\"comment\":\"\"},{\"name\":\"tableName\",\"comment\":\"\"},{\"name\":\"location\",\"comment\":\"\"},{\"name\":\"rowsColumn\",\"comment\":\"\"},{\"name\":\"valuesColumns\",\"comment\":\"\"},{\"name\":\"valuesOperation\",\"comment\":\"\"},{\"name\":\"columnsColumn?\",\"comment\":\"\"},{\"name\":\"sheetName?\",\"comment\":\"\"},{\"name\":\"pivotTableName?\",\"comment\":\"\"}]}}","apiInfo":"{\"variant\":\"synchronous\",\"variantVersion\":2}"}

0 commit comments

Comments
 (0)