1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu')
.addItem('Capitalize', 'proper')
.addToUi();
}
function proper() {
var arr = [],
s = SpreadsheetApp.getActiveSheet();
s.getRange('A2:A')
.getValues()
.forEach(function (r) {
if (r[0]) arr.push([toTitleCase(r[0])])
});
s.getRange(1, 1, arr.length, arr[0].length)
.setValues(arr);
}
function toTitleCase(str) {
return str.replace(/\w\S*/g, function (txt) {
return txt.charAt(0)
.toUpperCase() + txt.substr(1)
.toLowerCase();
});
} |
Partager