简体   繁体   English

谷歌 Web 应用脚本每日更新

[英]Google Web App Script Daily Update for Cell

Hello in my below link i have a user form were i can add, edit and delete a user.您好,在下面的链接中,我有一个用户表单,我可以添加、编辑和删除用户。

Spreadsheet Link https://docs.google.com/spreadsheets/d/1tyz_3WeEkmY4WX8Xvx38nkLow8hcbCjPMLS1-NiPFgo/edit?usp=sharing电子表格链接https://docs.google.com/spreadsheets/d/1tyz_3WeEkmY4WX8Xvx38nkLow8hcbCjPMLS1-NiPFgo/edit?usp=sharing

Dev Link https://script.google.com/macros/s/AKfycbxIT4fJPNyD5U2CKFzWCSho0tR2uuczq1hevzHawtg/dev开发链接https://script.google.com/macros/s/AKfycbxIT4fJPNyD5U2CKFzWCSho0tR2uuczq1hevzHawtg/dev

So now all the above fields like name, email, date of birth will be saved and can be re-edited.所以现在上面的所有字段,如姓名,email,出生日期都将被保存并可以重新编辑。

I added 2 more column below Phone Number & Country Daily Updates and Daily Logs我在电话号码和国家/地区Daily UpdatesDaily Logs下方添加了 2 列

Now when i edit a user and update today's activity in Daily Updates like Something added on - 1-jan-2021 Now it should clear field in Daily Updates and should be updated in Daily Logs field .现在,当我编辑用户并在Daily Updates中更新今天的活动时,例如Something added on - 1-jan-2021现在它应该清除Daily Updates中的字段,并且应该在Daily Logs field中更新。 If i update Something added on 2-jan-2021 in Daily Updates again it should be cleared and appear in Daily Logs field as previous and current如果我在Daily Updates中再次更新Something added on 2-jan-2021 ,则应将其清除并在Daily Logs字段中显示为先前和当前

Something added on - 1-jan-2021

Something added on 2-jan-2021

So my goal is display all changes done to Daily Updates field should be appear in Daily Logs field as read only this can't be edited.所以我的目标是显示对Daily Updates字段所做的所有更改都应显示在Daily Logs字段中,因为只读,无法编辑。

I believe your goal is as follows.我相信你的目标如下。

  • When the value is loaded by editing data from "Contact Details Database" and inputting the value to "Daily Updates" and clicking "Submit" button, you want to save the value to "Daily Logs" and want to clear "Daily Updates".当通过编辑“联系人详细信息数据库”中的数据并将值输入到“每日更新”并单击“提交”按钮加载值时,您希望将值保存到“每日日志”并希望清除“每日更新”。

In this case, how about the following modification?在这种情况下,如何进行以下修改?

Modified script:修改后的脚本:

In this case, please modify the function updateData in Google Apps Script side as follows.在这种情况下,请在 Google Apps Script 端修改 function updateData如下。

From:从:

function updateData(values, spreadsheetId, range) {
  var valueRange = Sheets.newValueRange();
  valueRange.values = values;
  var result = Sheets.Spreadsheets.Values.update(valueRange, spreadsheetId, range, { valueInputOption: "RAW" });}

To:至:

function updateData(values, spreadsheetId, range) {
  var len = values[0].length;
  values[0][len - 1] = values[0][len - 1] ? `${values[0][len - 1]}\n${values[0][len - 2]}` : values[0][len - 2];
  values[0][len - 2] = "";

  var valueRange = Sheets.newValueRange();
  valueRange.values = values;
  var result = Sheets.Spreadsheets.Values.update(valueRange, spreadsheetId, range, { valueInputOption: "RAW" });
}
  • By this modification, when the data is updated, the value of "Daily Updates" is saved to "Daily Logs" as the additional value and "Daily Updates" is cleared.通过这种修改,当数据更新时,“每日更新”的值作为附加值被保存到“每日日志”中,并且“每日更新”被清除。

Note:笔记:

  • From Daily Logs field as read only this can't be edited.Daily Logs field as read only this can't be edited. , in this case, please put readonly="readonly" to the textarea tag of "Daily Logs". ,在这种情况下,请将readonly="readonly"放在“Daily Logs”的 textarea 标签中。

Added:添加:

From the following reply,从下面的回复中,

IF i add more fields like Last name, job field, etc,,, i keep adding extra columns in spreadsheet.如果我添加更多字段,例如姓氏、工作字段等,我会继续在电子表格中添加额外的列。

In this case, how aobut using the column number as follows?在这种情况下,如何使用列号如下?

To:至:

function updateData(values, spreadsheetId, range) {
  var colDailyChanges = 8; // Column "H"
  var colDailyLogs = 9; // Column "I"
  values[0][colDailyLogs - 1] = values[0][colDailyLogs - 1] ? `${values[0][colDailyLogs - 1]}\n${values[0][colDailyChanges - 1]}` : values[0][colDailyChanges - 1];
  values[0][colDailyChanges - 1] = "";

  var valueRange = Sheets.newValueRange();
  valueRange.values = values;
  var result = Sheets.Spreadsheets.Values.update(valueRange, spreadsheetId, range, { valueInputOption: "RAW" });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM