-
Notifications
You must be signed in to change notification settings - Fork 949
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
Export only one worksheet by it's Id from all document added #1491
base: master
Are you sure you want to change the base?
Conversation
you can run these commands to check that the workflow will pass :) pip install -r lint-requirements.txt
tox -e lint
# optionally but you have not changed tests/docs
pip install -r docs/requirements.txt
pip install -r test-requirements.txt
tox -e doc # build docs
tox -e py # run tests is this a feature that you think is possible to add a test for, or not? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the list of possible formats are slightly different from the export format from the DriveAPI.
I suggest we create a new Enum list with the appropriate Names and Values.
I am not too keen on introducing this feature for one reason:
- in any error scenario we receive an HTML error page.
- the whole API is made to handle JSON response in all error scenarios, so here we fail to read the JSON error response, because its HTML format.
- This is because the URL we use is originally made for humans to use on a web browser.
@alifeee what do you think of this detail ?
format_str = "pdf" | ||
if format == ExportFormat.PDF: | ||
format_str = "pdf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 format
elif format == ExportFormat.ZIPPED_HTML: | ||
format_str = "zip" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one does not work.
as well as you don't handle the value: OPEN_OFFICE_SHEET
which results as PDF
due to default value set at the start of the if
s here.
I'm not fully sure why this feature is desired. What can Could someone provide a (pseudo)code snippet example of what is desired with this function? |
I believe it's desired when you wish to export (to PDF, to CSV, ...) a single sheet instead of a the whole spreadsheet (which creates multiple pages PDF for example).
sure, I tried it, here it is 🙃 client = gspread.service_account()
file = client.open("xxxxxxxx")
res = file.sheet1.export(gspread.utils.ExportFormat.PDF)
with open("result.pdf", "wb") as fp:
fp.write(res) My major concerns are:
|
Hi I thought about this feature and I really don't like the use of an HTML base API. that is dedicated to server content for humans on a web browser and mostly because we can't handle errors from this URL. it should not be part of gspread unfortunately until the API allows us to export a single sheet. For that matter I still want to help you and I found a way for you to download your spreadsheet and extract a single sheet using this pure python library that can handle PDFs: https://github.com/py-pdf/pypdf You can find the appropriate documentation here to read a pdf, choose page then write that page only to a new PDF file. With this solution that can solve your problem I suggest we don't merge this feature but I still want to wait for @alifeee opinion on this, so what do you think ? |
I see it being quite useful. I don't know what exists already to export a sheet (say, if you want to download PDF as a file). If you want a CSV or TSV, then you can probably just use But, perhaps if you want a PDF, you would want to customise how it looks, so you would want to use the GUI on the Google Sheets web browser anyway. As for errors: I do not know what errors exist when trying to export, apart from an incorrect format string (or if Google changes which are accepted) So, in the end: I see this adding a nice feature, but at a cost of bad errors if anything goes wrong, which is a maintenance burden cost. I say we could leave this open, or close it without merging, and if other people come requesting the same feature, then we can reconsider.? |
I'm ok with that. Let's leave it open for now. |
Added the ability to export one page from the entire document by ID