question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WorkbookProtection corrupts Spreadsheet for Excel 2019

See original GitHub issue

Spreadsheets saved with Excel 2019 get corrupted as soon as you add a WorkbookProtection.

Information

  • .NET Target: .NET 3.5
  • DocumentFormat.OpenXml Version: 2.9.1, 2.10.0-beta0001

Repro

Create an empty spreadsheet in Excel 2019. Perform the following operation:

using (var document = SpreadsheetDocument.Open("...", true) {
  document.WorkbookPart.Workbook.WorkbookProtection = new WorkbookProtection();
}

Open the spreadsheet in Excel 2019.

Observed

Excel fails to open and repair the file.

Exception

The resulting workbook.xml contains the newly added x:workbookProtection followed by the x:revisionPtr.

<x:workbookProtection />
<xr:revisionPtr revIDLastSave="0" documentId="13_ncr:1_{4BF1E7C4-2F1B-4756-81DA-B102ED8D212D}" xr6:coauthVersionLast="36" xr6:coauthVersionMax="36" xr10:uidLastSave="{00000000-0000-0000-0000-000000000000}" />

Manually changing the order (unzip/edit/zip) repairs the file.

<xr:revisionPtr revIDLastSave="0" documentId="13_ncr:1_{4BF1E7C4-2F1B-4756-81DA-B102ED8D212D}" xr6:coauthVersionLast="36" xr6:coauthVersionMax="36" xr10:uidLastSave="{00000000-0000-0000-0000-000000000000}" />
<x:workbookProtection />

Expected

File should not get corrupted.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
github-actions[bot]commented, May 14, 2020

Stale issue message

0reactions
DizTortioncommented, May 14, 2020

Any progress on this one? I’d be happy to provide more information if required.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WorkbookProtection corrupts Spreadsheet for Excel 2019
Spreadsheets saved with Excel 2019 get corrupted as soon as you add a WorkbookProtection. ... Open the spreadsheet in Excel 2019. ... Excel...
Read more >
Repairing a corrupted workbook
When you open a workbook that has been corrupted, Excel automatically ... In the Open dialog box, select the corrupted workbook that you...
Read more >
Can no longer refresh data in a Protected Workbook since ...
We have a protected workbook with some data connections to pull in data from SQL. Since updating to version 1803 the message 'Workbook...
Read more >
Solved: File contains corrupted data
I have tried to remove workbook protection "Restrict access (Highly confidential)" in my case and now it works. I'm able to connect from...
Read more >
How to protect worksheets and unprotect Excel sheet ...
To remove the workbook protection, do the following: Click the Protect Workbook button again (in a locked workbook, it is highlighted in green ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found