New Google Spreadsheets publish limitation

后端 未结 10 787
忘了有多久
忘了有多久 2020-11-29 18:47

I am testing the new Google Spreadsheets as there is a new feature I really need: the 200 sheets limit has been lifted (more info here: https://support.google.com/drive/answ

相关标签:
10条回答
  • 2020-11-29 19:07

    It's not going to help everyone, but I've made a PHP script to read the HTML into an array.

    I've added converting back to a CSV at the end. Hopefully this will help some people who have access to PHP.

    $html_link  = "https://docs.google.com/spreadsheets/d/XXXXXXXXXX/pubhtml";
    $local_html = "sheets.html";
    
    $file_contents = file_get_contents($html_link);
    file_put_contents($local_html,$file_contents);
    
    $dom        = new DOMDocument();  
    $html       = @$dom->loadHTMLFile($local_html);  //Added a @ to hide warnings - you might remove this when testing
    $dom->preserveWhiteSpace = false;   
    
    
    $tables     = $dom->getElementsByTagName('table');   
    $rows       = $tables->item(0)->getElementsByTagName('tr'); 
    $cols       = $rows->item(0)->getElementsByTagName('td');  //You'll need to edit the (0) to reflect the row that your headers are in.
    
    $row_headers = array();
    foreach ($cols as $i => $node) {
        if($i > 0 ) $row_headers[] = $node->textContent;
    }  
    
    foreach ($rows as $i => $row){   
        if($i == 0 ) continue;
        $cols = $row->getElementsByTagName('td');   
        $row = array();
        foreach ($cols as $j => $node) {
            $row[$row_headers[$j]] = $node->textContent;
        }   
        $table[] = $row;
    } 
    
    //Convert to csv
    $csv = "";
    foreach($table as $row_index => $row_details){
        $comma      = false;
        foreach($row_details as $value){
            $value_quotes = str_replace('"', '""', $value);
            $csv .= ($comma ? "," : "") . ( strpos($value,",")===false ? $value_quotes : '"'.$value_quotes.'"'  );
            $comma = true;
        }
        $csv .= "\r\n";
    }
    
    //Save to a file and/or output 
    file_put_contents("result.csv",$csv);
    print $csv;
    
    0 讨论(0)
  • 2020-11-29 19:08

    I found a fix! So I discovered that old spreadsheets before this change were still allowing only publishing certain sheets. So I made a copy of an old spreadsheet, cleared the data out, copy and pasted my current info into it and now I'm happily publishing just a single sheet of my large spreadsheet. Yay

    0 讨论(0)
  • 2020-11-29 19:15

    If you enable "Anyone with the link sharing" for spreadsheet, here is a simple method to get range of cells or columns (or whatever your feel like) export in format of HTML, CSV, XML, JSON via the query:

    https://docs.google.com/spreadsheet/tq?key=YOUR-KEY&gid=1&tq=select%20A,%20B&tqx=reqId:1;out:html;%20responseHandler:webQuery

    • For tq variable read query language reference.
    • For tqx variable read request format reference.

    Downside to this is that your doc is still availble in full via the public link, but if you want to export/import data to say Excel this is a perfect way.

    0 讨论(0)
  • 2020-11-29 19:16

    Here is the solution, just write it like this:

    https://docs.google.com/spreadsheets/d/<KEY>/export?format=csv&id=<KEY>

    I know it's weird to write the KEY twice, but it works perfectly. A teammate from work discovered this by opening the excel file in Google Docs, then File -> Download as -> Comma separated values. Then, in the downloads section of the browser appears a link to the CSV file, like this: https://docs.google.com/spreadsheets/d/<KEY>/export?format=csv&id=<KEY>&gid=<SOME NUMBER> But it doesn't work in this format, what my friend did was remove "&gid=<SOME NUMBER>" and it worked! Hope it helps everyone.

    0 讨论(0)
  • 2020-11-29 19:17

    That new feature appears to have disappeared. I don't see any option to publish a csv/tsv version. I can download tsv/csv with the export, but that's not available to other people with merely the link (it redirects them to a google docs sign-in form).

    0 讨论(0)
  • 2020-11-29 19:20

    The current answers do not work anylonger. The following has worked for me:

    • Do File -> "Publish to the web" and select 'start publishing' and the format. I choose text (which is TSV)
    • Now just copy the URL there which will be similar to https://docs.google.com/spreadsheet/pub?key=YOUR_KEY&single=true&gid=0&output=txt
    0 讨论(0)
提交回复
热议问题