简体   繁体   English

如何使用 google_sheets4 板条箱构建正确的 values_update 调用?

[英]How to construct a proper values_update call using the google_sheets4 crate?

Currently, in an attempt to just get a basic example working, I have this with which I'm trying to update cells A1:A4 with the value "1".目前,为了让一个基本的例子工作,我有这个,我试图用值“1”更新单元格 A1:A4。

let mut req = ValueRange::default();
req.values = Some(vec![ vec![ String::from("1"), String::from("1"), String::from("1"), String::from("1") ] ]);
req.range = Some(String::from("A1:A4"));

let result = hub.spreadsheets().values_update(req, SPREADSHEET_ID, "A1:A4")
         .value_input_option("USER_ENTERED")
         .doit();

This responds with a bad request.这以错误的请求响应。 I've verified that my auth works and that I am able to edit the spreadsheet like so我已经确认我的身份验证有效并且我能够像这样编辑电子表格

let mut req = sheets4::ClearValuesRequest::default();
let result = hub.spreadsheets().values_clear(req, SPREADSHEET_ID, "A1:B2").doit();

This clears A1:B2 as expected.这会按预期清除 A1:B2。

Ideally, I'd like to have a function like this理想情况下,我想要这样的功能

batch_update(&[1,2,3,4, (etc)], &["A1", "B2", "F3", "G42", (etc)]);

which would set cells A1, B2, F3 .. to 1, 2, 3.. .这会将单元格 A1、B2、F3 .. 设置为 1、2、3.. 。 I am totally unfamiliar with google spreadsheets and spreadsheets in general outside of basic usage.除了基本用法之外,我对谷歌电子表格和电子表格完全不熟悉。

I was supposed to read the official google sheets api documentation and not the crate documentation.我应该阅读官方的 google sheet api 文档,而不是 crate 文档。 On the official documentation, I found this https://developers.google.com/sheets/api/samples/writing which helped me get a basic example working like so:在官方文档中,我发现这个https://developers.google.com/sheets/api/samples/writing帮助我得到了一个基本的例子,如下所示:

let mut req = sheets4::ValueRange::default();
req.range = Some(String::from("A1:D6"));
req.major_dimension = Some(String::from("ROWS"));
req.values = Some(vec![
    vec!["Item".to_owned(), "Cost".to_owned(), "Stocked".to_owned(), "Ship Date".to_owned()],
    vec!["Wheel".to_owned(), "$20.50".to_owned(), "4".to_owned(), "3/1/2016".to_owned()],
    vec!["Wheel".to_owned(), "$20.50".to_owned(), "4".to_owned(), "3/1/2016".to_owned()],
    vec!["Wheel".to_owned(), "$20.50".to_owned(), "4".to_owned(), "3/1/2016".to_owned()],
    vec!["Wheel".to_owned(), "$20.50".to_owned(), "4".to_owned(), "3/1/2016".to_owned()],
    vec!["Wheel".to_owned(), "$20.50".to_owned(), "=SUM(C2:C5)".to_owned(), "3/1/2016".to_owned()],
]);

let result = hub.spreadsheets().values_update(req, SPREADSHEET_ID, "A1:D6")
    .value_input_option("USER_ENTERED")
    .doit();

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

相关问题 如何使用 Google Apps 脚本更新 google 表格中的单元格 - How to update a cell in google sheets using Google Apps Script 如何使用谷歌表格中的查询显示与多个值匹配的值 - How to shows values that matched with multiples values using query in google sheets 如何使用 API 更新谷歌表格中的多个遥远的行 - How to update multiple distant rows in google sheets using API 如何使用 python 用谷歌 api 更新谷歌表格? - How to update google sheets with google api using python? 如何使用 Google 应用脚本将值从工作表复制到幻灯片 - How to copy Values from sheets to slides using Google app scripts Google 表格:使用脚本自动更新 - 不起作用 - Google Sheets: Auto update using script - not working 如何使用 Google 表格从 JS 调用 ISOWEEKNUM - How to call ISOWEEKNUM from JS using Google Sheets 在Google表格中,使用脚本,如何仅更新从API调用获得的新记录? - In Google Sheets, with scripts, how do I only update new records that I get from an API call? 如何使用Google表格API + Javascript更新电子表格 - How to update spreadsheet using Google Sheets API + Javascript 如何使用Zapier更新Google表格中的多行? - How to update multiple rows in Google sheets using Zapier?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM