How to keep the share properties of an excel with python openpyxl?

Viewed 295

I have trouble trying to keep the sharing properties of an excel. I tried this :Python and openpyxl is saving my shared workbook as unshared but the part of vout just cancels all the modification I made with the script

To explain the problem :

  • There's an excel file that is shared in which people can do some modification
  • Python reads and writes on it
  • When I save the workbook in the excel file, it automatically either drops the sharing property or when I try to keep it, it just doesn't do any modification

Can someone help me please ?

1 Answers

I'll get a little more precise, as requested.

The sharing mode is the one Microsoft provides. You can see the button below:

Share button Excel

The excel is stored on a server. Several users can write on it at the same time but when I launch my script, it stops automatically the sharing property, so everyone that is writing on it just can't do modification anymore and every modif they did is lost.

First I treated my Excel normally :

DLT=openpyxl.load_workbook(myPath)
ws=DLT['DLT']
...my modifications on ws...
DLT.save()
DLT.close()

But then I tried this (Python and openpyxl is saving my shared workbook as unshared)

DLT=openpyxl.load_workbook(myPath)
ws=DLT['DLT']
zin = zipfile.ZipFile(myPath, 'r')
buffers = []
   for item in zin.infolist():
       buffers.append((item, zin.read(item.filename)))
zin.close()
...my modif on ws...
DLT.save()
zout = zipfile.ZipFile(myPath, 'w')
    for item, buffer in buffers:
        zout.writestr(item, buffer)
zout.close()
DLT.close()

The second one just doesn't save my modification on ws.

The thing I would like to do, is not to get rid of the sharing property. I would need to keep it while I write on it. Not sure if it is possible. I have one alternative solution that is to use another file, and just copy/paste by hand the new data from this file to the DLT one.

Related