Write data to range using OfficeScripts

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:

  1. Open Excel Online or Excel for the web.
  2. Open an existing workbook.
  3. Select the worksheet where you want to add the data.
  4. Click on the “Automate” tab in the ribbon.
  5. Click on the “Script Lab” button.
  6. In the Script Lab pane, create a new script or open an existing one.
  7. Replace the default code in the script editor with the code provided above.
  8. 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.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Pamai Tech