This script helps you control calculation mode.

function main(workbook: ExcelScript.Workbook) { 
    // Set the calculation mode to manual.
    // Get and log the calculation mode.
    const calcMode = workbook.getApplication().getCalculationMode();
    // Manually calculate the file.

This script sets cell "A1" to the number 2 and cell "B1" to a formula.
It then displays how Excel stores the cell's formula and value separately.

function main(workbook: ExcelScript.Workbook) { 
  let selectedSheet = workbook.getActiveWorksheet();
  let a1 = selectedSheet.getRange("A1");

  let b1 = selectedSheet.getRange("B1")

  console.log(`B1 - Formula: ${b1.getFormula()} | Value: ${b1.getValue()}`);

This script transposes the range "A1:D2" to "A4:B7" by using the TRANSPOSE function. If the transpose results in a #SPILL error, it clears the target range and applies the formula again.

function main(workbook: ExcelScript.Workbook) { 
  let sheet = workbook.getActiveWorksheet();
  // Use the data in A1:D2 for the sample.
  let dataAddress = "A1:D2"
  let inputRange = sheet.getRange(dataAddress);

  // Place the transposed data starting at A4.
  let targetStartCell = sheet.getRange("A4");

  // Compute the target range.
  let targetRange = targetStartCell.getResizedRange(inputRange.getColumnCount() - 1, inputRange.getRowCount() - 1);

  // Call the transpose helper function.

  // Check if the range update resulted in a spill error.
  let checkValue = targetStartCell.getValue() as string;
  if (checkValue === '#SPILL!') {
    // Clear the target range and call the transpose function again.
    console.log("Target range has data that is preventing update. Clearing target range.");

  // Select the transposed range to highlight it.;

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext