4

I already found something, that comes close to my question.
I am using the append-method because that´s exactly what I need and it works very well. I am not sure if I´m missing something here or the "append" does not support any kind of DataValidation.

Google shows in the example:

$response = $service->spreadsheets_values->append($spreadsheetId, $range, $requestBody);

the $requestBody is just a simple array:

$values = [
            [
                0  => $str,
                1  => $str,
                2  => $str,
                3  => $str,
                4  => $str,
                5  => $str,
                6  => $str,
                7  => $str,
                8  => $str
            ],
            // Additional rows ...
        ];

$body = new Google_Service_Sheets_ValueRange(['values' => $values]);

I don´t see any way to integrate this code:

$dv = new Google_Service_Sheets_DataValidationRule();
$b = new Google_Service_Sheets_BooleanCondition();
$b->setType('BOOLEAN');
$dv->setCondition($b);

I tested to add this as a value like:

$values = [
            [
                0  => $str,
                1  => $str,
                2  => $str,
                3  => $str,
                4  => $str,
                5  => $str,
                6  => $str,
                7  => $str,
                8  => $dv, /* <====== TRY TO ADD A CHECKBOX */
            ],
            // Additional rows ...
        ];

but this only leads to errors telling me, the values have a wrong structure.

At this point, I have no idea if "appending" supports any kind of "data validation" or not.

Thanks for any help.

michabbb
  • 880
  • 2
  • 7
  • 27
  • In order to put the checkbox using Sheets API, the method of batchUpdate is required to be used. In your situation, can you use the method of batchUpdate? Before I proposed a sample script, I would like to confirm this. – Tanaike Jul 17 '19 at 00:18
  • @tanaike thanks for your comment. That's my problem. The sheet is mainly changed by human, I don't know what's in each row. My script is only "appending" data, not "updating" data. I want to avoid appending and after that, updating again :-( – michabbb Jul 18 '19 at 09:07
  • Thank you for replying. You want to put a checkbox to a cell, when user edits the cell on the Spreadsheet. Is my understanding correct? – Tanaike Jul 18 '19 at 11:57
  • no, i only want to "append" data, which is working totally fine, but instead of using RAW text as a value or a something like '=TRUE()' i would like to use the data validation rules the php sdk offers me, but i believe, this is not possible, when ussing the "append" method. i don´t want to modify anything, to be clear, just adding rows to my sheet, which is working. but it would be nice, if i could add more complex values here. – michabbb Jul 18 '19 at 14:18
  • Thank you for replying. I apologize for my poor English skill. You want to put a checkbox as the append method. But the append method cannot be achieved it. So you are looking for the workaround of about this. Is my understanding correct? – Tanaike Jul 18 '19 at 22:45
  • @Tanaike no problem. if the "append" does not support complex values (like datavalidation rules, used for checkboxes) - bad luck. i know it´s working with different api calls, but that´s what i wanted to avoid, as the "append" is 100% thatt, what i need and working in general. i want to avoid adding something AND then modify it, after i have added something. so if the answer is: "append" does not support this, i have to live with that, no problem. – michabbb Jul 19 '19 at 12:32
  • Thank you for replying. I could understand about your question. Unfortunately, in the current stage, the checkbox cannot be put using the method of `append`. This is the current answer as you say. – Tanaike Jul 19 '19 at 23:20
  • @Tanaike thanks for the clarification! So feel free to answer this question :) – michabbb Jul 21 '19 at 07:15
  • Thank you for replying. I posted it as an answer. Could you please confirm it? – Tanaike Jul 21 '19 at 22:09

1 Answers1

0

In order to put the checkbox using Sheets API, the method of batchUpdate is required to be used.

Unfortunately, in the current stage, the checkbox cannot be put by the method of values.append.

This is the current answer for your question.

References:

Tanaike
  • 181,128
  • 11
  • 97
  • 165