0

Is it possible to change Wrap Strategy programmatically? I've already tried with

batch_update_spreadsheet documentation

service.batch_update_spreadsheet

and stackoverflow question

batch_update

but neither worked.

It always return Invalid Request. My request, as I understand from here, is just

service.batch_update_spreadsheet([{ 'wrapStrategy': 'WRAP' }])

What am I doing wrong? I want to change all cells from my sheet.

Thanks

  • Can you share the complete sample? You need to include a minimal example that reproduces the issue. You can also include the expected behavior, the actual behavior, and how they differ, that would be helpful as well. Please visit [How to Ask](https://stackoverflow.com/help/how-to-ask) have some tips on how to write a question, so the community will be able to help you out in a better way. – Lorena Gomez Nov 30 '22 at 22:52
  • First, I apologize that my answer was not useful for your situation. About your question, although I'm not sure whether I could correctly understand your goal, I proposed a sample script as an answer. Could you please confirm it? If I misunderstood your goal, I apologize. – Tanaike Dec 01 '22 at 01:58

1 Answers1

0

From service.batch_update_spreadsheet([{ 'wrapStrategy': 'WRAP' }]) and I want to change all cells from my sheet., I guessed that your goal is as follows.

  • You want to reflect 'wrapStrategy': 'WRAP' to a sheet in a Google Spreadsheet using googleapis for ruby.
  • You have already been able to get and put values to Google Spreadsheet with Sheets API.

In this case, how about the following sample script?

Sample script:

spreadsheet_id = '###' # Please set your Spreadsheet ID.
sheet_id = '###' # Please set your sheet ID.

request_body = {
  requests: [{repeat_cell: {
    range: {
      sheet_id: sheet_id,
    },
    cell: {
      user_entered_format: {
        wrap_strategy: 'WRAP'
      }
    },
    fields: 'userEnteredFormat.wrapStrategy'
  }}]
}
service.batch_update_spreadsheet(spreadsheet_id, request_body, {})
  • When this script is run, the wrapStrategy of sheet_id is set as WRAP.

  • In this case, please use the snake case for the keys instead of the camel case. Please be careful about this.

Note:

  • In this sample script, it supposes that your client of service can be used for updating the spreadsheet. Please be careful about this.

References:

Tanaike
  • 181,128
  • 11
  • 97
  • 165