Is it possible to enable “Sharing” on excel documents through OpenXML or ClosedXML? Or any other library if it can help… I believe this is usually performed when you save the document (at least that’s how it works in VBA), but I can’t find how to specify saving arguments in C#.
I’d like to avoid using InterOp since I might batch this process on multiple files through a network.
EDIT: According to some old pages from 2009, there are limitations where OpenXML cannot operate protected files. However, would that apply to sharing too?
Sharing Excel documents using OpenXML SDK is not well documented.
I did some tests and found that it is possible to enable sharing on Excel documents
using OpenXML SDK. The following steps are necessary to enable sharing:
Add a
WorkbookUserDataPartto your Excel document. Add an emptyUserscollectionto the part. In this collection Excel stores all users who currently have
this shared workbook open.
Add a
WorkbookRevisionHeaderPartto your Excel document. Add aHeaderscollectionto the part. In this collection Excel will store references to history, version and revision
information. Add a first element (
Header) to the collection which contains theSheetIdMap(used for tracking revision records). In the code sample belowI’ve added all worksheets included in the document.
Furthermore add a
WorkbookRevisionLogPartto the workbook’s revision header part.In the log part a list of revision made to the document is stored.
The code sample below shows how to enable sharing on an Excel document.
The code also checks whether sharing is already enabled on a document.
Before you enable sharing you should create a backup of your original documents.