将Google电子表格文档转换为CSV文件
项目描述
Google电子表格到CSV
一个下载Google电子表格到CSV文件的实用工具。
安装
作为常见的Python库,您可以使用pip获取最新稳定版本
pip install google-sheets-to-csv
用法
最准确的信息将使用gs-to-csv --help
提供:
gs-to-csv --help
usage: gs-to-csv [-h] [--service-account-credential-file SERVICE_ACCOUNT] [-f]
[-b BUFFER_LINES] [--logging-file LOGGING_FILE]
[--logging-level LOGGING_LEVEL]
[--logging-format LOGGING_FORMAT]
spreadsheet selector directory
Convert google spreadsheet sheets to csv
optional arguments:
-h, --help show this help message and exit
Converter options:
--service-account-credential-file SERVICE_ACCOUNT
If you want to use this command in a script without
user interractions, you can create a service account
from google console:
https://developers.google.com/workspace/guides/create-
credentials#create_a_service_account and share read
access sheets you want to export. (default: None)
-f, --force Tell this app tp overwrite existing files if present.
(default: False)
-b BUFFER_LINES, --buffer-lines BUFFER_LINES
Maximum number of lines to retreive by http calls.
(default: 500)
spreadsheet Id of the spreadsheet you want to export to csv.
Spreadsheet id is the weird data present in the uri
just after `d/`:
https://docs.google.com/spreadsheets/d/<the
spreadsheet id is here>/
selector Sheet selector is a regex expression to match sheets
titles. Some examples: - `.*`: would export all sheets
- `(abcd)|(efgh)`: would export abcd and efgh sheets
directory Output directory with write access where csv files
will bewritten.
Logging params:
--logging-file LOGGING_FILE
Logging configuration file, (logging-level and
logging-format are ignored if provide) (default: None)
--logging-level LOGGING_LEVEL
--logging-format LOGGING_FORMAT
This will create a .csv file per sheet with title match with the regex
expression.
身份验证
有两种方式让此程序访问您的Google电子表格
-
您可以使用
--service-account-credential-file
选项提供Google服务账户凭证。 -
默认情况下,脚本将打开您的浏览器,允许您授权(或不授权)只读访问运行在您电脑上的此应用程序的所有Google电子表格文档。授权令牌将保存在您的家目录中:
.gs-to-csv-token.json
(您可以使用GS_TO_CSV_TOKEN_FILE_PATH
环境变量来控制该路径)。您可以在YouTube上观看以下教程
行为(限制)
-
Google电子表格API提供了一个
columnCount
值,这个值有点没有用,因为我们得到了额外的单元格。所以为了方便,这个返回值,对于每一行,与第一行(预期的标题行!)相同的单元格数,这可能会导致空白行或截断数据。 -
没有任何值的行不会在电子表格中间返回空白行。
-
使用用户账户(通过身份验证流程)有HTTP调用速率限制,使用最高的
--buffer-lines
选项可以部分缓解这个限制。
其他解决方案
使用wget
- 使用“任何人都可以通过链接查看”共享电子表格。
- 然后使用下载URL运行wget(或curl),您将在浏览器中的URL中找到
document_id
和sheet_id
$ wget --output-file="logs.csv" "https://docs.google.com/spreadsheets/d/<document_id>/export?format=csv&gid=<sheet_id>" -O "downloaded_content.csv"
数据将在以下文件中:downloaded_content.csv
-
优点:
- 无需安装任何特殊的东西
-
缺点:
- 在电子表格上启用共享链接访问
- 获取您想要下载的任何工作表的
sheet_id
- 每个工作表使用一个命令进行导出
致谢
Logo 来自 CSV 文件,由 Milinda Courey 从 Noun Project 提供
变更日志
- 主版本引入 API 变更
- 次版本更改行为
- 补丁版本涉及发布的文档或重构或热修复,这些修复不打算更改以前的版本号
版本 0.2
.gs-to-csv-token.json
令牌文件仅对当前用户创建为只读。
版本 0.1
- 初始实现
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分发
google-sheets-to-csv-0.2.0.tar.gz (8.0 kB 查看哈希值)
构建分发
关闭
google-sheets-to-csv-0.2.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d1000f425873f26d84b5d2ff4fdbf829d0df51d1649442130a089f3a985c8d84 |
|
MD5 | e30e366bc736443b85cab57e79bc00d0 |
|
BLAKE2b-256 | cc764514c4f76c321efe848d9119ee7d28cddacd691edae4faebb98464cf9568 |
关闭
google_sheets_to_csv-0.2.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | dfdc79f3b1e4a7bccbd5cf54fd0e8fa7341bae10432502ee25c5a8f32826ebd7 |
|
MD5 | ec1322949585a3f5756f285e8fe22380 |
|
BLAKE2b-256 | 687173c4012ceaa8c07647b8a93ad62abc931cedeac518b7ff9592a45a9d7ae8 |