Google app-script .setValues()方法未写入工作表

时间:2019-07-24 15:41:20

标签: google-apps-script google-sheets

我想做的是更新Google工作表中的数据,然后将数据写回到工作表中。 1.我从电子表格中读取数据 2.如果需要,请遍历数据,然后添加一行并添加列,即更改现有数据。 3.现在我需要将数据写回到电子表格中

我唯一能想到的是范围大于列和行的旧范围,这可能会导致问题

//Reading the data initially:

var workingSheet = SpreadsheetApp.getActive().getSheetByName(storeSheetName);
var existingData = workingSheet.getDataRange().getValues(); //row 0 is column names
//do some manipulations on the data (add rows and columns)
// Writing the values : 
SpreadsheetApp.getActiveSpreadsheet().getSheetByName(storeSheetName).getRange(1,1,existingData.length,storeColumns.length).setValue(existingData);

当我尝试在调试模式下运行脚本时,它会不断卡在.setValues()行上,并且不会继续执行

1 个答案:

答案 0 :(得分:0)

尝试一下:

SELECT custodian_id, manager_id, username,
CASE username
    WHEN custodian_id AND manager_id THEN 'Custodian and manager'
    WHEN manager_id THEN 'Manager'
    WHEN custodian_id THEN 'Custodian'
    ELSE ''
END AS person_role
FROM Install
ORDER BY person_role

您可以尝试以下方法:

var workingSheet = SpreadsheetApp.getActive().getSheetByName(storeSheetName);
var existingData = workingSheet.getDataRange().getValues(); //row 0 is column names
SpreadsheetApp.getActiveSpreadsheet().getSheetByName(storeSheetName).getRange(1,1,existingData.length,existingData[0].length).setValue(existingData);