Export to Google sheet

Export to Google sheet

pmconsultingpmconsulting Posts: 34Questions: 10Answers: 0

There must be a way to get the CSV or EXCEL export buttons to open the download in a Google sheet on an iPad. I hope that’s just something I’m missing. Would be really bad news if this couldn’t be arranged. If Apple blocks that, we need a website and letter writing campaign to ask Tim Cook to fix that.


  • allanallan Posts: 58,894Questions: 1Answers: 9,479 Site admin

    I'm certain there will be a way to do it - but its not something I've investigated yet I'm afraid. There is a Google Sheets API which includes the ability to create sheets, so I think that would be the way to go about it.


  • hAtul89hAtul89 Posts: 12Questions: 7Answers: 0

    Did you find a solution to this? I'm trying to convert to google sheets too.

  • nkcnkc Posts: 1Questions: 0Answers: 0

    agreed - export to google sheet function would be super useful.

  • colincolin Posts: 14,801Questions: 1Answers: 2,524

    Hi all,

    Sorry, there's been no movement on this, and unlikely to be in the near-future due to other priorities.



  • allanallan Posts: 58,894Questions: 1Answers: 9,479 Site admin

    This is an area we'd very much welcome community input. You can get the data from DataTables using our API methods and then import it into Google Sheets using the API I linked to above. If anyone does this, please post it here and we'll flag it up for others to also be able to use.


  • tanguypamtanguypam Posts: 5Questions: 2Answers: 0

    Hi guys :smile: Good news !

    I succeeded to make an export button to google sheets via the GDrive API and the GSheets API. Those APIs have to be activated on your Google account, if you don't know how to do it, just take a look at the Google Help.
    Drive : https://developers.google.com/drive/api/v3/quickstart/php
    Sheets : https://developers.google.com/sheets/api/quickstart/php

    So, first, you have to create a new button in your Datatable.

    buttons: [
            text: 'Export to GSheets',
            action: function ( e, dt, button, config ) {
                        var data = dt.buttons.exportData();

    I associated a function to it :

    function exportToSheets(data){
        type: "POST",
        url: "ajax/exporttosheets.php",

    And my exporttosheets.php look like that :

      // var_dump($body);
      //Create GSheets
      $client = new \Google_Client();
      $client->setApplicationName('Create Sheet');
      $service = new Google_Service_Sheets($client);
      $spreadsheet = new Google_Service_Sheets_Spreadsheet([
          'properties' => [
              'title' => 'New Spreadsheet'
      $spreadsheet = $service->spreadsheets->create($spreadsheet, [
          'fields' => 'spreadsheetId'
      // echo $fileId;
      //Give permissions
      $client2 = new \Google_Client();
      $client2->setApplicationName('Give permissions');
      $client2->setPrompt('select_account consent');
      $service2 = new Google_Service_Drive($client2);
      $newPermission = new Google_Service_Drive_Permission();
      $service2->permissions->create($fileId, $newPermission);
      // echo "https://docs.google.com/spreadsheets/d/$fileId";
      //Add data from the dataTables
      $client3 = new \Google_Client();
      $client3->setApplicationName('Add data from datatables');
      $service3 = new Google_Service_Sheets($client3);
      $spreadsheetId = $fileId;
      $range = 'Sheet1';
      $body = new Google_Service_Sheets_ValueRange([
        'values' => $values
      $params = [
        'valueInputOption' => 'RAW'
      $insert = [
        "insertDataOption" => "INSERT_ROWS"
      $result = $service3->spreadsheets_values->append(
      echo "https://docs.google.com/spreadsheets/d/$fileId";

    As you see, i return the complete URL of the sheet, and in the jQuery function and I open a new tab to this Sheets. :smile:

    I have one issue here, I don't know how to add the header to the body. Here I only get the data ($body) w/o the names of the columns at the top of the GSheets. If you can help me that would be great :smiley:

    Thank you very much,


  • colincolin Posts: 14,801Questions: 1Answers: 2,524

    Nice, thanks for sharing. I don't know the answer regarding the header, but hopefully somebody else in the community does.


  • tanguypamtanguypam Posts: 5Questions: 2Answers: 0

    Thanks Colin,

    Oh, I forgot to change the console.log(data) , so, to open in a new tab :

    window.open(data, '_blank');

This discussion has been closed.