Cut the Clutter: Test Ignore Files Feature - sign up to become a beta tester here.
Forum Discussion
jbrede
Dropbox Staff
3 years agoOverwriting gSheet Files Unsuccessfully
I have an issue where I'm uploading and trying to overwrite gsheet files to a dropbox app folder with the files.upload method. It runs successfully but I can't open the .gSheet file from my Dropbox folder. When I select 'Open in' > 'Google Sheets', I get taken to a screen stating ".gsheet files can't currently be previewed".
Code below:
def excel_overwrite_data_sheet(wb1Path,wb2Path😞
try:
output = io.BytesIO()
wb1 = openpyxl.load_workbook(io.BytesIO(dropbox_load_file('/Data/Book1.xlsx')))
ws1 = wb1.worksheets[0]
wb2 = openpyxl.load_workbook(io.BytesIO(dropbox_load_gsheet('/GSheetMetrics.gsheet')))
wb2.remove(wb2['Ticket Data'])
ws2 = wb2.create_sheet(ws1.title)
for row in ws1:
for cell in row:
ws2[cell.coordinate].value = cell.value
writer = pd.ExcelWriter(output, engine='openpyxl')
writer.book = wb2
writer.save()
output.seek(0)
dbx.files_upload(output.getvalue(),wb2Path,mode=dropbox.files.WriteMode.overwrite)
except Exception as e:
print('Error writing file to Dropbox: ' + str(e))
2 Replies
- Здравко3 years agoLegendary | Level 20
Hi jbrede,
As far as I can follow the logic of your code (in spite incompletely represented), you are trying to store Excel data as Google sheets. 🤔 Am I correct? If so, why?
Hope this gives direction.
PS: Just changing file extension doesn't change the file type! 😉 In your case you have Excel file content labeled with Google sheet extension. ".gsheet" files are JSON objects that refer to the actual file content (through "url" field inside); they don't contain the actual data (".xlsx" files contain the data)! Dropbox API (or any of the supported SDKs) doesn't provide a way to manage ".gsheet" content directly if it's what you want.
jbrede wrote:..., I get taken to a screen stating ".gsheet files can't currently be previewed".
...
Did you try just change extension back to ".xlsx"? 🧐😀 Take in mind that Dropbox is NOT so smart to detect the content type automatically, but relies on extension only! 🤦 And in the particular case falls in confusion because of this. 🤷 It might be a future improvement; lot of free libraries deal with this.
- Greg-DB3 years ago
Dropbox Community Moderator
jbrede As Здравко mentioned, unfortunately the Dropbox API doesn't offer the ability to create .gsheet docs like this, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.
About Discuss Dropbox Developer & API
Make connections with other developers815 PostsLatest Activity: 2 days ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!