gpt4 book ai didi

Java Google 表格 API。将数据附加到特定工作表

转载 作者:行者123 更新时间:2023-12-02 11:07:39 24 4
gpt4 key购买 nike

我想将数据附加到 3 个不同的工作表(使用 Java 和 Google Sheet API)。

例如,“我喜欢海龟”到第一个工作表,sheetId 为 1,“123”到第二个工作表,sheetId 为 2,任何范围到第二个工作表,sheetId 为 3。如何附加该数据?更重要的是,如何从工作表中获取工作表 ID 并设置 Activity 工作表?或者任何其他方式来做到这一点。有什么建议或者例子吗?

谢谢。

最佳答案

您可以引用这个link关于如何将数据附加到特定工作表。

If you simply want to write on a sheet, follow the Basic Writing Sheets guide. You can write on a sheet by using a PUT method:

PUT https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId/values/Sheet1!A1:D5?valueInputOption=USER_ENTERED

and specify the name of sheet and cell range in like:

{
"range": "Sheet1!A1:D5",
"majorDimension": "ROWS",
"values": [
["Item", "Cost", "Stocked", "Ship Date"],
["Wheel", "$20.50", "4", "3/1/2016"],
["Door", "$15", "2", "3/15/2016"],
["Engine", "$100", "1", "30/20/2016"],
["Totals", "=SUM(B2:B4)", "=SUM(C2:C4)", "=MAX(D2:D4)"]
],
}

With regard to your spreadsheets.values.append question, I'm sure you've already read what the docs had to say:

Appends values to a spreadsheet. The input range is used to search for existing data and find a "table" within that range. Values will be appended to the next row of the table, starting with the first column of the table.

这仅适用于在表格的最后一行添加。

也来自这个page :

Try out the below script and see if that works for you:

 var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// This represents ALL the data
var range = sheet.getDataRange();
var values = range.getValues();

// This logs the spreadsheet in CSV format with a trailing comma
for (var i = 0; i < values.length; i++) {
var row = "";
for (var j = 0; j < values[i].length; j++) {
if (values[i][j]) {
row = row + values[i][j];
}
row = row + ",";
}
Logger.log(row);
}

This apps script will help you get data from one spreadsheet to another. Refer to the article getDataRange() for more information on this.

希望这有帮助!

关于Java Google 表格 API。将数据附加到特定工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50835380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com