我有40個Google工作表文件,我需要更改標題顏色。他們在第1列和第13列有不同的行。我需要找到他們在哪裏,並改變他們的顏色。通過循環播放會減慢我的google appscript的速度。我如何加快速度?
這工作,痛苦緩慢。無論如何,我可以更有效地寫這篇文章嗎?我感覺像循環行到57(我知道是最後一行可能的標題)正在放慢我的過程,但我想不出有什麼更好的辦法。
function colorchange() {
// The following defines the variable SpreadsheetIDs, which is a list of all the ID's that are going to be changed
var spreadsheetIDs = ["1TZK5s3KvAFn9AMgWjIyPFAkjvhwL-3sGy5ieipQV-R8", //template
"1NSctLmGT0eWzvSj7P_NOUmgR79nIIokEEiaTJo6_Bb8", //1
"1plfjNQx4aFFnwcqMfv_wohbiYnlC_NVjW-etBM-xm5c", //2
"1i7myzXNFiFM6ZtkG590Hg4oEr-cAV8gsWxlV7rjL2b8", //3
"1-3r7D6nsVLT1FEZhGpGP9eF9G9HUZmuEe22aDajNBA0", //4
"1LBob3F3D1E__K6CJyBBIssho_cLkxm9uD00DP03QQz8", //5
"1Bot9TAbAr-g_Dgbqi4WJvXfE-Gt9t2ErxJk3Y-pvWZs", //6
"18kOx3-Q0DQhAA7jm19UZQhBUYShYVORWlQIgU_iicq4", //7
"1aHZ3FHUW6jt5HpuYb0fpBvfgTqSazXzZwJbvQEa8Qcs", //8
"1WkDHWL6sIkSu9qt_nizzXm2er-hxzuXEf8GsCTq3fug", //9
"1ZLDjW3VTMaumQIbihvyELyCuBghcn_GrQmuzCPnno9Y", //10
//ECT until 40ish spreadsheetID's
];
var i=0,color="",sheet,thisID="",e=1,c=1;
// This calls the Browser input box and defines it the color Variable
color = Browser.inputBox("Enter the color");
for (i=0;i<spreadsheetIDs.length;++i) {
thisID=spreadsheetIDs[i];
//This opens the first ID, and opens up the Sheet1 sheet. ALL of the sheets in the territory MUST have this name.
sheet=SpreadsheetApp.openById(thisID).getSheetByName('Sheet1');
//This loops through the column 1 and 13 and checks for the correct font size all the way up to row 59.
//When it finds the correct fontsize, it sets the fontcolor to the color variable value.
for (e=1;e<58;++e) {
//Row A
c=1
if(sheet.getRange(e,c).getFontSize() == '24') {
sheet.getRange(e,c).setFontColor(color);}
//Row M
c=13
if(sheet.getRange(e,c).getFontSize() == '24') {
sheet.getRange(e,c).setFontColor(color);}
}
//Set Background for A1 and Color for D1
sheet.getRange(1,1).setBackground(color);
sheet.getRange(1,4).setFontColor(color);
}
}
當我讀取數組中的值之後,我如何定位所述值以更改我想要的特定值?我需要特別改變FontSize爲X的字體。所以,在將所有這些FontSizes寫回到我的數組後,我如何知道它們來自哪裏以將它們作爲FontColor改變的目標? –
我做了它使用2嵌套循環與他們檢查單元格值的if語句。使用parseint(我不知道爲什麼它在一個字符串值),然後加1到它的單元格值。 (因爲循環從0開始,谷歌表格從1開始。)完美地工作! –
很酷。對不起,延遲迴復。 所以我會讀取整個範圍的兩個數組的大小和值,使用getFontSizes()和getValues(),然後使用嵌套循環遍歷該數組,並更改值數組中的相應值 - 有道理? 聽起來像這就是你做的! – alfiethecoder