OfficeScripts to read various properties of range

Here’s a sample OfficeScript that demonstrates how to read various properties of a range in Excel:

function readRangeProperties() {
  // Get the active worksheet
  var worksheet = context.workbook.getActiveWorksheet();

  // Get a range to read properties from
  var range = worksheet.getRange("A1:C3");

  // Read range properties
  var rangeAddress = range.address;
  var rangeValues = range.values;
  var rangeNumberFormat = range.numberFormat;
  var rangeFontColor = range.format.font.color;
  var rangeBackgroundColor = range.format.fill.color;

  // Logging the range properties
  console.log("Range Address: " + rangeAddress);
  console.log("Range Values: ");
  console.log(rangeValues);
  console.log("Range Number Format: " + rangeNumberFormat);
  console.log("Range Font Color: " + rangeFontColor);
  console.log("Range Background Color: " + rangeBackgroundColor);
}

In this example, the readRangeProperties function performs the following steps:

  1. It gets the active worksheet using the getActiveWorksheet method.

  2. It defines a range (A1:C3) within the worksheet using the getRange method.

  3. It reads various properties of the range, such as the address, values, number format, font color, and background color.

  4. The range properties are stored in variables: rangeAddress, rangeValues, rangeNumberFormat, rangeFontColor, and rangeBackgroundColor, respectively.

  5. Finally, it logs the range properties to the console.

You can call the readRangeProperties function to see the range properties in the console output.

Please note that this example assumes that you have a workbook open and a worksheet active in Excel for the web or Excel Online, where you can execute the OfficeScript.

Additionally, remember to set up the necessary context and load the OfficeScript runtime to ensure the script executes successfully.

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