-
Notifications
You must be signed in to change notification settings - Fork 976
Export only one worksheet by it's Id from all document added #1491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| SPREADSHEET_VALUES_BATCH_URL, | ||
| SPREADSHEET_VALUES_CLEAR_URL, | ||
| SPREADSHEET_VALUES_URL, | ||
| SPREADSHEET_DRIVE_URL, | ||
| ) | ||
| from .utils import ExportFormat, convert_credentials, quote | ||
|
|
||
|
|
@@ -358,6 +359,57 @@ def export(self, file_id: str, format: str = ExportFormat.PDF) -> bytes: | |
| r = self.request("get", url, params=params) | ||
| return r.content | ||
|
|
||
| def export_worksheet(self, file_id, sheet_id: str, format: str = ExportFormat.PDF) -> bytes: | ||
| """Export the worksheet in the given format. | ||
|
|
||
| :param str file_id: The key of the spreadsheet to export | ||
|
|
||
| :param str sheet_id: The key of the worksheet to export | ||
|
|
||
| :param str format: The format of the resulting file. | ||
| Possible values are: | ||
|
|
||
| * ``ExportFormat.PDF`` | ||
| * ``ExportFormat.EXCEL`` | ||
| * ``ExportFormat.CSV`` | ||
| * ``ExportFormat.OPEN_OFFICE_SHEET`` | ||
| * ``ExportFormat.TSV`` | ||
| * ``ExportFormat.ZIPPED_HTML`` | ||
|
|
||
| See `ExportFormat`_ in the Drive API. | ||
|
|
||
| :type format: :class:`~gspread.utils.ExportFormat` | ||
|
|
||
| :returns bytes: The content of the exported file. | ||
|
|
||
| .. _ExportFormat: https://developers.google.com/drive/api/guides/ref-export-formats | ||
| """ | ||
|
|
||
| if format not in ExportFormat: | ||
| raise UnSupportedExportFormat | ||
|
|
||
| if format not in ExportFormat: | ||
| raise UnSupportedExportFormat | ||
|
|
||
| format_str = "pdf" | ||
| if format == ExportFormat.PDF: | ||
| format_str = "pdf" | ||
|
Comment on lines
+391
to
+393
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the default value is PDf, then you don't have to check if it's PDF in |
||
| elif format == ExportFormat.CSV: | ||
| format_str = "csv" | ||
| elif format == ExportFormat.ZIPPED_HTML: | ||
| format_str = "zip" | ||
|
Comment on lines
+396
to
+397
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one does not work. |
||
| elif format == ExportFormat.EXCEL: | ||
| format_str = "xlsx" | ||
| elif format == ExportFormat.TSV: | ||
| format_str = "tsv" | ||
|
lavigne958 marked this conversation as resolved.
|
||
|
|
||
| url = "{}/export?gid={}&format={}".format(SPREADSHEET_DRIVE_URL % file_id, sheet_id, format_str) | ||
|
lavigne958 marked this conversation as resolved.
|
||
|
|
||
| params: ParamsType = {"mimeType": format} | ||
|
|
||
| r = self.request("get", url, params=params) | ||
| return r.content | ||
|
|
||
| def insert_permission( | ||
| self, | ||
| file_id: str, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.