如何使用Google Script将Google电子表格中的特定列除外的所有工作表大写?

时间:2016-12-13 11:03:23

标签: javascript google-apps-script google-sheets

此代码将所有工作表单元格大写,但某些列除外。然而,删除了排除细胞的公式。 我不希望脚本将我的公式删除到这些列中。

select stuff((select ', ' + t.letter from(
    select * from @alphabets a
    where not exists(
        select 1 from [your_table_name] e
        where a.letter = left(e.empname, 1)
    )
)t
for xml path('')
), 1, 2, '');

1 个答案:

答案 0 :(得分:0)

请注意Zig的评论。由于很少需要更改,请使用下面的功能替换您的正常功能,看看是否有效..

更新的代码(在排除的列中保存公式,请参阅注释)

function proper() {
var s = SpreadsheetApp.getActiveSheet(),
    excludedCols = [2, 4, 6, 8, 10];
formulas = s.getDataRange()
    .getFormulas()
s.getDataRange()
    .setValues(
        s.getDataRange()
        .getValues()
        .map(function (r, j) {
            return r.map(function (el, i) {
                return !el ? null : formulas[j][i] ? formulas[j][i] :
                    (typeof el !== 'string' && el) || excludedCols.indexOf(i + 1) > -1 ? el : toTitleCase(el);
            })
        })
    )
}