0

I currently have a 34x22 .xlsx spreadsheet. I am downloading it via pydrive, filling in some of the blank values, and uploading the file back via pydrive. When I upload the file back, all cells with formulas are blank (any cell that starts with =). I have a local copy of the file I want to upload, and it looks fine so I'm pretty sure the issue must be with pydrive.

My code:

def upload_r1masterfile(filename='temp.xlsx'):
        """
        Upload a given file to drive as our master file
        :param filename: name of local file to upload
        :return:
        """
        # Get the file we want
        master_file = find_r1masterfile()
        try:
            master_file.SetContentFile(filename)
            master_file.Upload()
            print 'Master file updated. ' + str(datetime.datetime.now())
        except Exception, e:
            print "Warning: Something wrong with file R1 Master File."
            print str(e)
            return e

The only hint I have is that if I add the param={'convert': True} tag to Upload, then there is no loss. However, that means I am now working in google sheets format, and I would rather not do that. Not only because it's not the performed format to work with here, but also because if I try to master_file.GetContentFile(filename) I get the error: No downloadLink/exportLinks for mimetype found in metadata

Any hints? Is there another attribute on upload that I am not aware of?

Thanks!

Robin Nabel
  • 2,170
  • 1
  • 21
  • 26

1 Answers1

1

Robin was able to help me answer this question at the github repository. Both suggested solutions worked:

1) When you upload the file, did you close Excel first? IIRC MS Office writes a lot of the content to a temporary file, so that may explain why some parts are missing. If you tried the non converting upload first, the full file may have been saved to disk between the two tries, and thus the second converting upload attempt worked.

2) GetContentFile takes a second argument called mimetype, which should allow you to download the file. Could you try .GetContentFile(filename, mimetype="application/vnd.ms-excel")? If that mimetype doesn't work as anticipated, there is a great StackOverflow post here which lists a bunch of different types you can try.

Thanks again Robin!

Community
  • 1
  • 1