-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample hdr script.osts
More file actions
1 lines (1 loc) · 2.98 KB
/
sample hdr script.osts
File metadata and controls
1 lines (1 loc) · 2.98 KB
1
{"version":"0.2.0","body":"function main(workbook: ExcelScript.Workbook, input: string): string {\n let inputData: unknown[][] = [];\n let foundValues: string[] = [];\n\n try {\n // Parse the input as JSON to get the copiedData\n inputData = JSON.parse(input);\n\n // Get the target worksheet by name\n let targetWorksheet = workbook.getWorksheet(\"data_sheet\");\n\n let lastRow = targetWorksheet.getUsedRange().getLastRow();\n\n // Get the range in column A (assuming data starts from A2)\n let columnARange = targetWorksheet.getRange(\"A2:A50000\" + lastRow.getRowIndex());\n\n // Get the values in column A\n let columnAValues: string[] = columnARange.getValues().flat(); // Flatten the array\n\n // Loop through each row in the input data\n for (let i = 0; i < inputData.length; i++) {\n // Check if the value in the 1 index is present in column A\n let valueToCheck = inputData[i][1];\n let valueFound = false;\n\n for (let j = 0; j < columnAValues.length; j++) {\n if (columnAValues[j] == valueToCheck) {\n // If value found, update the 1 index in the input data\n inputData[i][1] = columnAValues[j];\n valueFound = true;\n\n // Take the respective student ID from column B\n let studentID = targetWorksheet.getRange(\"B\" + (j + 2)).getValue(); // Assuming data starts from B3\n let supervisor = targetWorksheet.getRange(\"AA\" + (j + 2)).getValue();\n\n // Insert the student ID at fixed index 2\n inputData[i].splice(2, 0, studentID);\n // Insert supervisor at fixed index 3\n inputData[i].splice(3, 0, supervisor);\n\n // Store the found value in the array\n foundValues.push(valueToCheck);\n\n break;\n }\n }\n\n // If value is not found, you can handle it as needed\n if (valueFound) {\n // Handle the case when the value is not found in column A\n // For example, you might want to set some default values or skip this row\n //console.log(\"Value found in column A:\", valueToCheck);\n }\n }\n\n // Your further processing or sending the data as needed\n\n // Log the found values\n // console.log(\"Found values in column A:\", foundValues);\n } catch (error) {\n console.log(\"Error while processing data:\", error);\n }\n\n // Return the modified inputData as a JSON string\n let overallData = JSON.stringify(inputData);\n console.log(overallData);\n return overallData;\n}\n","description":"","parameterInfo":"{\"version\":1,\"originalParameterOrder\":[{\"name\":\"input\",\"index\":0}],\"parameterSchema\":{\"type\":\"object\",\"required\":[\"input\"],\"properties\":{\"input\":{\"type\":\"string\"}}},\"returnSchema\":{\"type\":\"object\",\"properties\":{\"result\":{\"type\":\"string\"}}},\"signature\":{\"comment\":\"\",\"parameters\":[{\"name\":\"workbook\",\"comment\":\"\"},{\"name\":\"input\",\"comment\":\"\"}]}}","apiInfo":"{\"variant\":\"synchronous\",\"variantVersion\":2}"}