這是已經公知很長時間了一個錯誤:失敗用於百分比格式化的單元格的setValue(S):
Issue 472。
參觀和明星它,也許它會得到更多的關注。
如果您正在讀取百分比格式的單元格中的值,並且必須重新計算百分比值。
此功能使用的格式值範圍應用上,這是一個百分比的任意單元格的*= 100
操作:
/**
* Adjusts the values for elements in values array if the
* corresponding format element is a percentage.
* Value array is changed in place, as well as returned.
*/
function percentAdjust(values,formats) {
for (var row = 0; row < values.length; row++) {
for (var col = 0; col < values[0].length; col++) {
if (formats[row][col].indexOf('%') !== -1) {
// Adjust any percent formatted values
values[row][col] *= 100;
}
}
}
return(values);
};
function test() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var values = rows.getValues();
var formats = rows.getNumberFormats();
rows.setValues(percentAdjust(values,formats));
}
感謝 - 出演吧。我只是測試一下,如果列是一個數字,然後我乘以100,但我喜歡你的方法來檢查格式是否是百分比。 – brl8 2013-05-06 16:30:58