使用Google Spreadsheet的直接下载URL将特定工作表导出到Dropbox文件夹

时间:2015-08-28 16:55:20

标签: csv google-apps-script google-sheets google-spreadsheet-api http-get

我有一个电子表格名称'电子表格',它有三张名为'a','b'和'c'的表格。我目前使用此网址格式发布此电子表格

<!-- This script uses the super simple Dropbox Drop-In API -->

<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="ex4mpl3K3y"></script>

<!-- This anchor establishes the dropbox button which determines the file to download to your dropbox folder. --> 

<a href="https://docs.google.com/a/account/spreadsheets/d/r4Nd0MSpR34d5h33t/export?format=csv&id=r4Nd0MSpR34d5h33t" data-filename="file-name.csv" class="dropbox-saver"></a>

此网址格式允许任何人下载该文件的csv版本,但下载图片a,b和c。如何修改此网址以仅下载工作表b或工作表c?

1 个答案:

答案 0 :(得分:0)

如何将Google电子表格导出到Dropbox

设置Dropbox

  1. 在www.dropbox.com
  2. 创建Dropbox帐户
  3. 使用API​​控制台创建Dropbox应用 https://www.dropbox.com/developers/apps请确保为其提供 Drop-ins权限类型
  4. 在App Console标签中,转到新应用的设置并添加以下域
  5.   

    docs.google.com ||   127.0.0.1 ||   localhost ||   googleusercontent.com

    1. 请注意应用密钥
    2. 添加此脚本以使用the Dropbox Drop-in API's Saver method<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="YOURAPPKEYRECEIVEDFROMAPICONSOLE"></script>
    3. 设置Google电子表格

      1. Set up a google account
      2. Create a spreadsheet
      3. Securely publish the sheet to the web
      4. 在电子表格工具栏上,转到Tools&gt; Script Editor。这将打开一个新窗口,您将看到一个名为code.gs
      5. 的空javascript文件
      6. 将以下其中一个脚本添加到code.js
      7. sheetId是跟随网址中/ d /的随机字符系列。通过转到gid选项并选择要发布的特定工作表,复制给定的网址,并在标识为publish sheet to the web &gid= function onOpen() { var menuItems = [ {name: 'Dropbox', functionName: 'dropbox'} ]; SpreadsheetApp.getActive().addMenu('The Make Life Easy Button', menuItems); } function dropbox(){ var dropboxKey = 'string'; var sheetid = 'string'; var gid = 'string'; var fileName = 'string'; var testResults = '<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="'+ dropboxKey +'"></script>'; testResults += '<h2>Store Content Sheet</h2><a href="https://docs.google.com/a/' + account + '/spreadsheets/d/' + sheetid + '/pub?gid=' + gid + '&single=true&output=csv" data-filename="' + fileName + '" class="dropbox-saver"></a>'; // Show a dialog with the test results. var htmlApp = HtmlService .createHtmlOutput(testResults) .setSandboxMode(HtmlService.SandboxMode.IFRAME) .setTitle('Test Results') .setWidth(600) .setHeight(400); SpreadsheetApp.getActiveSpreadsheet().show(htmlApp); } >

        功能宏魔术

        您将看到的代码是一个非常简单的脚本,可以在电子表格中添加菜单选项

        from contextlib import contextmanager
        
        def my_generator():
            for i in range(10):
                if i > 5:
                    break
                yield i
        
        @contextmanager
        def generator_context():
            yield my_generator()
            print("cleaning up")
        
        with generator_context() as generator:
            for value in generator:
                print(value)
        

        未来读者注意事项

        您需要同时授予Google脚本和保管箱权限。

        请确保对需要进一步说明的任何步骤留下评论,我将确保填补空白。如果内容已过时,则非常感谢对更新材料发表评论。