Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8805555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:53:50+00:00 2026-06-14T01:53:50+00:00

Is it possible to enable Sharing on excel documents through OpenXML or ClosedXML ?

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:53:52+00:00Added an answer on June 14, 2026 at 1:53 am

    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:

    1. Add a WorkbookUserDataPart to your Excel document. Add an empty Users collection
      to the part. In this collection Excel stores all users who currently have
      this shared workbook open.

    2. Add a WorkbookRevisionHeaderPart to your Excel document. Add a Headers collection
      to 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 the
      SheetIdMap (used for tracking revision records). In the code sample below
      I’ve added all worksheets included in the document.
      Furthermore add a WorkbookRevisionLogPart to 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.

    using (SpreadsheetDocument sd = SpreadsheetDocument.Open("c:\\temp\\enable_sharing.xlsx", true))
    {
      WorkbookPart workbookPart = sd.WorkbookPart;
    
      if (workbookPart.GetPartsCountOfType<WorkbookRevisionHeaderPart>() != 0)
      {
        Console.Out.WriteLine("Excel document already shared!");
        return;
      }
    
      // Create user data part if it does not exist.
      if (workbookPart.GetPartsCountOfType<WorkbookUserDataPart>() == 0)
      {
        Console.Out.WriteLine("Adding user data part");
        WorkbookUserDataPart workbookUserDataPart = workbookPart.AddNewPart<WorkbookUserDataPart>();
    
        Users users = new Users() { Count = (UInt32Value)0U };
        users.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
    
        workbookUserDataPart.Users = users;
      }
    
      // Create revision header part and revision log part.
      WorkbookRevisionHeaderPart workbookRevisonHeaderPart = workbookPart.AddNewPart<WorkbookRevisionHeaderPart>();
    
      WorkbookRevisionLogPart workbookRevisionLogPart = workbookRevisonHeaderPart.AddNewPart<WorkbookRevisionLogPart>();
    
      // Create empty collection of revisions.
      Revisions revisions = new Revisions();
      revisions.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
    
      workbookRevisionLogPart.Revisions = revisions;
    
      string lastSetOfRevisionsGuid = Guid.NewGuid().ToString("B");
    
      // Create headers collection (references to history, revisions)
      Headers headers = new Headers() { Guid = lastSetOfRevisionsGuid };
      headers.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
    
      int worksheetPartsCount = workbookPart.GetPartsCountOfType<WorksheetPart>();                        
    
      // Create first element in headers collection
      // which contains the SheetIdMap.
      Header header = new Header() { Guid = lastSetOfRevisionsGuid, DateTime = DateTime.Now, 
                                     MaxSheetId = (UInt32Value)(uint)worksheetPartsCount+1, UserName = "hans", Id = "rId1" };
    
      // Create the list of sheet IDs that are used for tracking
      // revision records. For every worksheet in the document
      // create one SheetId.
      SheetIdMap sheetIdMap = new SheetIdMap() { Count = (UInt32Value)(uint)worksheetPartsCount };
    
      for (uint i = 1; i <= worksheetPartsCount; i++)
      {
        SheetId sheetId = new SheetId() { Val = (UInt32Value)i };
    
        sheetIdMap.Append(sheetId);
      }        
    
      header.Append(sheetIdMap);
      headers.Append(header);
    
      workbookRevisonHeaderPart.Headers = headers;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In bash, I believe it is possible to enable tab completion on the terminal
Possible Duplicate: How can I disable/enable UISearchBar keyboard's Search button? Can we disable the
It's possible to implement INotifyCollectionChanged or other interface like IObservable to enable to bind
Is it possible to enable per-pixel lighting (so that I can have nice specular
Does anyone know if it is possible to enable any kind of logging on
Anyone know if its possible to enable horizontal scrolling ONLY in a windows forms
Is it possible to programmatically enable Desktop Sync for a folder via the Box.com
Possible Duplicate: How to use enable_if to enable member functions based on template parameter
Is it possible to disable or enable subgrid based on the selected value when
Searching for possible ways to get cookie with httpOnly enabled, I cannot find any.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.