Skip to content

Instantly share code, notes, and snippets.

@saicologic
Last active August 29, 2015 14:15
Show Gist options
  • Save saicologic/4d581f6abdc0c9f9f0d3 to your computer and use it in GitHub Desktop.
Save saicologic/4d581f6abdc0c9f9f0d3 to your computer and use it in GitHub Desktop.
gss_test
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:b50aad76b3e3f59e7a881926fbb0c6b097ee2062bc20390da75569f4008d1424"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import gspread\n",
"\n",
"gc = gspread.login('example@gmail.com', 'yourpassword')\n",
"\n",
"# https://docs.google.com/spreadsheets/d/1UVHfC4ZxW60w5dk-0JgF7lqWMQw7p2qjSbn3594dsaw/edit#gid=0\n",
"sh = gc.open_by_key('1UVHfC4ZxW60w5dk-0JgF7lqWMQw7p2qjSbn3594dsaw')\n",
"sh"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 17,
"text": [
"<gspread.models.Spreadsheet at 0x10534ef50>"
]
}
],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# \u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u78ba\u8a8d\n",
"gspread.__version__"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 18,
"text": [
"'0.2.1'"
]
}
],
"prompt_number": 18
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"worksheet = sh.worksheet('demo')\n",
"worksheet"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 19,
"text": [
"<Worksheet 'demo' id:od6>"
]
}
],
"prompt_number": 19
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# \u4e00\u756a\u76ee\u306e\u30ef\u30fc\u30af\u30b7\u30fc\u30c8\u3092\u53d6\u5f97\u3059\u308b\n",
"worksheet.acell(\"A1\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 20,
"text": [
"<Cell R1C1 ''>"
]
}
],
"prompt_number": 20
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"worksheet.col_count"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 21,
"text": [
"26"
]
}
],
"prompt_number": 21
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"worksheet.add_cols(1)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 22
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"worksheet.col_count"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 24,
"text": [
"27"
]
}
],
"prompt_number": 24
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"worksheet.row_count"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 25,
"text": [
"1000"
]
}
],
"prompt_number": 25
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"worksheet.add_rows(1)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 26
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"worksheet.row_count"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 27,
"text": [
"1001"
]
}
],
"prompt_number": 27
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"worksheet.title"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 28,
"text": [
"'demo'"
]
}
],
"prompt_number": 28
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"worksheet.update_acell('A1', u'\u3042\u3044\u3046\u3048\u304a')\n",
"worksheet.update_acell('A2', u'\u304b\u304d\u304f\u3051\u3053')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 34
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"for sheet in worksheet.range('A1:A2'):\n",
" print sheet.value"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\u3042\u3044\u3046\u3048\u304a\n",
"\u304b\u304d\u304f\u3051\u3053\n"
]
}
],
"prompt_number": 35
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"worksheet.update_acell('A1', u'\u307e\u307f\u3080\u3081\u3082')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 37
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# \u6307\u5b9a\u3057\u305f\u5217\u306b\uff11\u3092\u633f\u5165\u3059\u308b\n",
"cell_list = worksheet.range('A1:G1')\n",
"for sheet in cell_list:\n",
" sheet.value = 1\n",
"worksheet.update_cells(cell_list)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 38
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment