问题
Im putting together a pretty lengthy spreadsheet in google spreadsheets. This spreadsheet contains information about products ie name, brand, part number, ect... I was helped previously and given some nice solutions but I am still running into limitations.
What I am trying to do is generate, automatically, a description field based on information in other cells.
The formula I am using in the descriptions column is ="Brand Name"&" "&A3&" "&B3&" "&(joinVals(E3:G3," x "))&" "&K3
joinVals(E3:G3," x ")
is joining together separate columns containing Length(E) Width(F) Height(G) and adding 'x' between the values. That results in E x F x G
This Script does work for the above formula
function joinVals( rangeValues, separator ) {
function notBlank(element) {return element != '';}
return rangeValues[0].filter(notBlank).join(separator);
}
However I keep getting this error
Script invoked too many times per second for this Google user account.
I am wondering If I can do this as an array to avoid the error as this doc contains 1000+ ROWS.
When all is said and done my result I would like to achieve should be something like this "Brand Name" Part Number(A) Product Name(B) Dimensions(E x F x G) Size(K)
Should I be running an ARRAY Script?
Thank you all so much, this forum has been such a help!
回答1:
It is possible to use an Array solution, but you'd have to change a lot how you use formulas in your spreadsheet. The easiest solution is to use built-in spreadsheet formulas directly. There's no need for a custom Apps Script formula for this.
="Brand Name"&" "&A3&" "&B3&" "&(join(" x ";filter(E3:G3;E3:G3<>"")))&" "&K3
As shown by AdamL in the comments, here's an ArrayFormula
solution that uses only built-in formulas.
=ArrayFormula(IF(LEN(A3:A),REGEXREPLACE("Brand Name "&A3:A&" "&B3:B&" "&REPT(E3:E&" x ",E3:E<>"")&REPT(F3:F&" x ",F3:F<>"")&REPT(G3:G&" x ",G3:G<>"")&CHAR(9)&" "&K3:K,"( x \t)|\t",""),))
As I said, such ArrayFormula
style of solution can be used when writing custom Apps Script as well. I just don't think that's worth it when there's (arguably) simpler built-in solutions (but surely faster and way larger quotas).
来源:https://stackoverflow.com/questions/21006478/combining-data-from-many-cells-into-one