我有一個代碼,我對兩個以上的元素應用相同的規則:
activities.forEach((act) => {
mainSheet.getRange(rowIndex, columnIndex)
.setValue(act.text)
.setFontStyle('italic')
.setFontFamily('Verdana')
.setFontSize(12)
.setBorder(null, null, true, null, null, null, act.color, SpreadsheetApp.BorderStyle.SOLID_MEDIUM)
mainSheet.getRange(rowIndex, columnIndex 2)
.setFontStyle('italic')
.setFontFamily('Verdana')
.setFontSize(10)
.setBorder(null, null, true, null, null, null, act.color, SpreadsheetApp.BorderStyle.SOLID_MEDIUM)
rowIndex = 2;
})
我重復:
字體樣式
字體系列
設定邊框
關于如何使它更整潔的任何建議?
我想在 Google 表格中使用復制格式,但我不想為它創建一個單元格。也許可以創建一個不存在的單元格,這樣我就可以在那里撰寫我的格式,然后將其應用于我的元素?
uj5u.com熱心網友回復:
您可以通過創建一個RangeList物件來一次設定所有單元格的值和格式。要創建RangeList物件,請使用Array.map()或其他Array方法來收集范圍,如下所示:
const rowNumbers = [2, 4, 6, 8, 10, 12,];
const columnLabels = ['C', 'E'];
const rangeList = rowNumbers.map(row => columnLabels.map(col => col row));
mainSheet.getRangeList(rangeList)
.setValue(act.text)
.setFontStyle('italic')
.setFontFamily('Verdana')
.setFontSize(12)
.setBorder(null, null, true, null, null, null, act.color, SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
activities.forEach()如果您打算對所有單元格使用相同的格式,則不清楚為什么要回圈。如果您只想在某些單元格而不是所有單元格中設定值RangeList,請創建另一個物件并呼叫其.setValue()方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/536960.html
標籤:谷歌应用脚本谷歌表格
