Search code examples
google-sheetsgoogle-sheets-api

laravel google sheets adds apostrophe in some cases


I was able to successfully append data to my Sheet using laravel google sheets. The issue is with all dates and some integers. When uploaded, an apostrophe is added in front of the values.

I ensured that all dates are in the correct format and that the integers are, actually, numbers.

I've also tried to set valueInputOption to RAW, but this didn't change anything.

        $sheetsService = Sheets::getService();
        $client = $sheetsService->getClient();
        $service = new Google_Service_Sheets($client);

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

        $params = [
            'valueInputOption' => 'RAW'
        ];

        $response = $service->spreadsheets_values->append($spreadsheetId, $sheetName, $body, $params);

This did append the data, but the dates still have ' in front of them.


Solution

  • Although I'm not sure about your values of $data, in order to avoid When uploaded, an apostrophe is added in front of the values., please modify as follows and test it again.

    From:

    $params = [
        'valueInputOption' => 'RAW'
    ];
    

    To:

    $params = [
        'valueInputOption' => 'USER_ENTERED'
    ];
    

    References: