cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Overwriting gSheet Files Unsuccessfully

Overwriting gSheet Files Unsuccessfully

jbrede
Dropbox Staff

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 2

Здравко
Legendary | 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-DB
Dropbox Staff

@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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?