Set row height and column width.(Microsoft Excel Office Scripts)

Japanese version.

Introduction to how to set the last row and last column using Office scripts.

Operations

Specify a numerical value

The following syntax is used (Red text indicates variable parts)

// Row height
workbook.getWorksheet(Sheet name).getRange(Rows).getFormat().setRowHeight(Height);

// Column width
workbook.getWorksheet(Sheet name).getRange(Columns).getFormat().setColumnWidth(Width);

The height and width specified here do not match the default units or pixels.

(If you specify the same numbers for height and width, they will be the same size.)

However, 3/4ing the values for width and height will result in pixels.

To use this to specify 100 pixels, do the following:

// Row height
workbook.getWorksheet(Sheet name).getRange(Rows).getFormat().setRowHeight(100 * 3/4);

// Column width
workbook.getWorksheet(Sheet name).getRange(Columns).getFormat().setColumnWidth(100 * 3/4);

Auto Adjustment

It is also possible to perform the same automatic adjustment that is performed by double-clicking on the cell borders.

// 行の高さ
workbook.getWorksheet(Sheet name).getRange(Rows).getFormat().autofitRows();

// 列の幅
workbook.getWorksheet(Sheet name).getRange(Columns).getFormat().autofitColumns();

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