Java Google Sheets API example with autoResizeDimensionsRequest -
i'm wondering how use autoresizedimensions in order set columns auto resize. following
list<request> requests = new arraylist<>(); autoresizedimensionsrequest autoresizedimensions = new autoresizedimensionsrequest(); requests.add(new request() .setautoresizedimensions(autoresizedimensions)); batchupdatespreadsheetrequest batchupdaterequest = new batchupdatespreadsheetrequest() .setrequests(requests); sheets.spreadsheets().batchupdate(spreadsheetid, batchupdaterequest) .execute();
returns following error message
com.google.api.client.googleapis.json.googlejsonresponseexception: 400 bad request { "code" : 400, "errors" : [ { "domain" : "global", "message" : "invalid requests[1].autoresizedimensions: columns dimension supported", "reason" : "badrequest" } ], "message" : "invalid requests[1].autoresizedimensions: columns dimension supported", "status" : "invalid_argument"
i'm interested in setting specific width column. haven't found examples using java. if has come across 1 or know how love no it.
additionally i've added setdimensions code
dimensionrange dimensions = new dimensionrange().setdimension("a1:c6");
with setautoresizedimensions
requests.add(new request() .setautoresizedimensions(autoresizedimensions .setdimensions(dimensions)));
but i'm getting following error
com.google.api.client.googleapis.json.googlejsonresponseexception: 400 bad request { "code" : 400, "errors" : [ { "domain" : "global", "message" : "invalid value @ 'requests[3].auto_resize_dimensions.dimensions.dimension' (type_enum), \"a1:c6\"", "reason" : "badrequest" } ], "message" : "invalid value @ 'requests[3].auto_resize_dimensions.dimensions.dimension' (type_enum), \"a1:c6\"", "status" : "invalid_argument"
thanks conteh
the failures stem same reason: autoresizedimensionrequest
not setup properly.
you need supply valid dimensionrange
request's dimensions
field in order request know dimensions resize. documentation dimensionrange describes it's purpose: a range along single dimension on sheet. indexes zero-based. indexes half open: start index inclusive , end index exclusive. missing indexes indicate range unbounded on side.
the first error ("invalid requests[1].autoresizedimensions: columns dimension supported"
) because request using default dimensionrange
, means dimensionrange.dimension
field using default value of dimension_unspecified
. field enum of type dimension
default value dimension_unspecified
. error message saying, "only columns supported" , implicitly saying, "... supplied dimension_unspecified or rows".
the second error ("invalid value @ 'requests[3].auto_resize_dimensions.dimensions.dimension' (type_enum), \"a1:c6\""
) because wrote a1 range dimension
field. error message saying: "you gave me invalid value. enum, gave me a1:c6, , isn't valid enum."
the valid values dimension
rows
or columns
(and autoresizedimensionrequest
requires specify columns
). in addition, you'll want specify sheetid
(the id of sheet columns want resize) , startindex
, endindex
of columns want resize.
for example, if wanted automatically resize rows 0 , 1, use: autoresizedimensionsrequest autoresizedimensions = new autoresizedimensionsrequest(); dimensionrange dimensions = new dimensionrange().setdimension("columns").setstartindex(0).setendindex(2); autoresizedimensions.setdimensions(dimensions);
(endindex
2
because end indexes exclusive, whereas start indexes inclusive.)
Comments
Post a Comment