Site icon Kaizen.Personal computer work.

Get/Change the current position of the chart.(Microsoft Excel Office Scripts)

Japanese version.

How to get/Change (move) the current position of a chart in Office scripts.

Operations

You must first get the target chart.

chart variable = workbook.getWorksheet("Sheet name").getCharts()[index];
chart variable = workbook.getWorksheet("Sheet name").getChart("Chart name");

This can also be done with the return value (variable) of the result added with addChart().

If the acquisition fails, the result is undefined.

The chart name specified to getChart() is displayed in the name box.

Get position

chart variable.getTop();  // Vertical position with the topmost 0.
chart variable.getLeft(); // Horizontal position with leftmost 0.
function main(workbook: ExcelScript.Workbook) {
  let chart = workbook.getWorksheet("Test").getChart("Chart 1");
  console.log("Vertical position:" + chart.getTop());
  console.log("Horizontal position:" + chart.getLeft());
}

Change position (move)

Specify position

chart variable.setTop(Vertical position with the topmost 0); 
chart variable.setLeft(Horizontal position with leftmost 0); 
function main(workbook: ExcelScript.Workbook) {
  let chart = workbook.getWorksheet("Test").getChart("Chart 1");
  chart.setTop(30);
  chart.setLeft(300);
}

Specify cell

chart variable.setPosition("Start cell address","End cell address")

The "End cell address" is optional.

function main(workbook: ExcelScript.Workbook) {
  let chart = workbook.getWorksheet("Test").getChart("Chart 1");
  chart.setPosition("F5");
}

If only the start cell is specified, only the move is performed; if the end cell is also specified, the size is changed at the same time.

For those who want to learn Office script effectively

The information on this site is now available in an easy-to-read e-book format.

Or Kindle Unlimited (unlimited reading).

You willl discover how to about basic operations.

By the end of this book, you will be equipped with the knowledge you need to use Excel Office Script to streamline your workflow.

Links

Office Scripts Articles

Exit mobile version