我目前有一个项目可以测量冲压力,我正在使用Arduino、ESP32和Google Sheets来记录数据,但我仍然想知道如何将数据发送到Google Sheets中的两个不同的表。让我们在这里举一个例子,Sheet1将接收到的数据是“forceData1”、“forceData2”、“orceData3”,Sheet2将接收到“forceData4”和“forceData5”。
我在这里有我的期望图片:
My expectation of Sheet2
这是我的代码
*代码来自我的另一个问题
function doGet(e) {
Logger.log(JSON.stringify(e));
var result = 'Ok';
if (e.parameter == 'undefined') {
result = 'No Parameters';
} else {
// ref: https://stackoverflow.com/a/44563639 (This is the user who written this, I still put this here just in case)
Object.prototype.get1stNonEmptyRowFromBottom = function (columnNumber, offsetRow = 1) {
const search = this.getRange(offsetRow, columnNumber, this.getMaxRows()).createTextFinder(".").useRegularExpression(true).findPrevious();
return search ? search.getRow() : offsetRow;
};
var Curr_Date = new Date();
var values = [
Curr_Date,
Utilities.formatDate(Curr_Date, "Asia/Bangkok", 'HH:mm:ss'),
...['forceData', 'forceData2', 'forceData3'].map(k => e.parameter[k] ? stripQuotes(e.parameter[k]) : null)
];
var ssID = SpreadsheetApp.openById('SHEET_ID');
var sheet = ssID.getSheetByName('Sheet1');
sheet.getRange(sheet.get1stNonEmptyRowFromBottom(2) + 1, 2, 1, values.length).setValues([values]);
}
return ContentService.createTextOutput(result);
}
function stripQuotes(value) {
return value.replace(/^["']|['"]$/g, "");
哦,我还有两个小问题:
第一个问题是如何将日期从mm/dd/yyyy更改为dd/mm/yyyy?(如果默认为mm/dd/yyyy,则我们可以通过此问题)
第二个是我忘了添加“年龄”单元格。我试着添加它,结果发生了:值
var Curr_Date = new Date()
,
var Curr_Time = Utilities.formatDate(Curr_Date, "Asia/Bangkok", 'HH:mm:ss')
,
e.parameter.forceData
,
e.parameter.forceData2
和
e.parameter.forceData3
跳到B6,即“年龄”列,换句话说,它没有将这些数据放在“C”到“F”列中。
下面是这个问题的图片和我的期望!
The problem with the "Age" cell
/
My expectation of this "Age" cell problem
我希望你们能帮我,干杯!