我们正在尝试查询一个 Google 电子表格,其中包含一些带有 #N/A 的字段。
Google 电子表格中的 #N/A 错误表明缺少信息和信号函数以停止计算。
我们只想将这些 #N/A 值视为 NULL。
使用 Google 电子表格的 CData 连接器执行此操作的最佳方法是什么?
我们正在尝试查询一个 Google 电子表格,其中包含一些带有 #N/A 的字段。
Google 电子表格中的 #N/A 错误表明缺少信息和信号函数以停止计算。
我们只想将这些 #N/A 值视为 NULL。
使用 Google 电子表格的 CData 连接器执行此操作的最佳方法是什么?
I presume setting your formulas to ifError isn't an option in your spreadsheet? That seems like the most sensible. Example, =iferror(vlookup(foo),)
returns null
instead of #N/A
.
Assuming not, here's an app script that could review your data and replace values, or create a new sheet in your spreadsheet with updated values.
function fixErrorsInSheet(_sh) {
const errorValues = ["#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"];
if (_sh === undefined) {
_sh = SpreadsheetApp.getActiveSheet();
}
const ss = _sh.getParent();
var dataRange = _sh.getDataRange();
var allValues = dataRange.getValues();
for (var i = 0; i < allValues.length; i++) {
for (var j = 0; j < allValues[i].length; j++) {
var oneValue = allValues[i][j];
if (errorValues.includes(oneValue)) {
allValues[i].splice(j, 1, null);
}
}
}
//optional to update sheet, or you could query this array directly with cData;
dataRange.setValues(allValues);
//create new sheet with updated values...
//ss.setActiveSheet(_sh);
//var newSheet = ss.duplicateActiveSheet();
//newSheet.getRange(1,1,dataRange.getLastRow(),dataRange.getLastColumn()).setValues(allValues);
}
//use this to run on all sheets
function runFixOnAllWorkbooks() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.getSheets().forEach(fixErrorsInSheet);
}