'Custom Date format values in array
I want to format dates in a Table column in Excel 365 Web using a custom format. I can format a cell but not the cell value picked up in a variable or array.
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Set number format for range A2 on selectedSheet
// selectedSheet.getRange("A2").setNumberFormatLocal("yyyy-mmm");
let v = selectedSheet.getRange("A2").getValue() ;
console.log(v);
}
I want the dates to show up as yyyy-mmm. Can anyone show how to custom date format an array of values?
Solution 1:[1]
If you use getTexts() it will return an array of the formatted text values. I updated the v variable in your example to have the range A2:A3 and changed the method from getValue() to getTexts():
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Set number format for range A2 on selectedSheet
// selectedSheet.getRange("A2").setNumberFormatLocal("yyyy-mmm");
let v = selectedSheet.getRange("A2:A3").getTexts();
console.log(v);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brian Gonzalez |
