Here’s an example of an OfficeScript that adds data to a range in an existing worksheet:
function main(worksheet: ExcelScript.Worksheet) { // Define the range where you want to add data let range = worksheet.getRange("A1:C3"); // Define the data to add let data = [ ["Value 1", "Value 2", "Value 3"], ["Value 4", "Value 5", "Value 6"], ["Value 7", "Value 8", "Value 9"] ]; // Set the values in the range range.setValues(data); }
To use this OfficeScript, follow these steps:
- Open Excel Online or Excel for the web.
- Open an existing workbook.
- Select the worksheet where you want to add the data.
- Click on the “Automate” tab in the ribbon.
- Click on the “Script Lab” button.
- In the Script Lab pane, create a new script or open an existing one.
- Replace the default code in the script editor with the code provided above.
- Click the “Run” button to execute the script.
This script adds the data provided in the data
variable to the range specified in the getRange
function. Modify the range and data values according to your needs.
Please note that OfficeScripts are currently only supported in Excel for the web and Excel Online. They are not available in the desktop version of Excel.