Set Font(Microsoft Excel Office Scripts)
Introduces how to set up fonts with Office scripts.
Operations
Font
The following syntax is used.(Red text indicates a variable portion)
// Get the current font
let font = workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().getName();
// Set Font
workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().setName("Font name");
Font Size
The following syntax is used.(Red text indicates a variable portion)
// Get current font size
let fontSize = workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().getSize();
// Set font size
workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().setSize(Size);
Font color
The following syntax is used.(Red letters indicate variable parts)
The color code is specified as a hex triplet (HEX). (Color picker)
// Get current font color
let fontColor = workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().getColor();
// Set font color
workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().setColor("color code");
Bold
The following syntax is used (Red text is variable)
//
Get whether currently bold or not
let bold = workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().getBold();
// Set Bold
workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().setBold(true);
// Unbold
workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().setBold(false);
Italic
The following syntax is used (Red text indicates variable parts)
// Get current, italic or not
let italic = workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().getItalic();
// Set Italic
workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().setItalic(true);
// Unitalicize
workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().setItalic(false);
underline
The following syntax is used (Red text indicates variable parts)
// Get current underline
let underLine = workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().getUnderline();
// Set Underline
workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().setUnderline(Line style);
Select a line style from the following
Set value | Description. |
---|---|
ExcelScript.RangeUnderlineStyle.double | Double line |
ExcelScript.RangeUnderlineStyle.doubleAccountant | Double line (accounting) |
ExcelScript.RangeUnderlineStyle.single | Single line |
ExcelScript.RangeUnderlineStyle.singleAccountant | Single line (accounting) |
ExcelScript.RangeUnderlineStyle.none | None (Release) |
strike-through line
The following syntax is used (Red text indicates variable parts)
// Get the current strikethrough status
let strikethrough = workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().getStrikethrough();
// Set strikeout lines
workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().setStrikethrough(true);
// Undo strikeout
workbook.getWorksheet("sheet").getRange("cell address").getFormat().getFont().setStrikethrough(false);
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.
Discussion
New Comments
No comments yet. Be the first one!