Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing to locked cell results in cell being unlocked and workbook structure protection being lost #738

Closed
jrivers1 opened this issue Jan 31, 2022 · 2 comments · Fixed by #1125
Assignees
Labels
bug file_error file format generation/writing issue xlsx
Milestone

Comments

@jrivers1
Copy link

I am using NPOI version 2.5.5 and have run into an issue while attempting to write a value to a locked cell. I am using a simple test project with a workbook that contains Sheet1 and Sheet2. Sheet1 is protected, hidden and contains one cell which is locked and hidden. The workbook structure is password protected as well.

`IWorkbook wb = new XSSFWorkbook(file);

ISheet sheet = wb.GetSheet("Sheet1");
IRow row = sheet.GetRow(0);
ICell cell = row.GetCell(0);
bool locked = cell.CellStyle.IsLocked; // Always returns false
cell.CellStyle.IsLocked = true; // Will set style to locked
locked = cell.CellStyle.IsLocked;
bool hidden = cell.CellStyle.IsHidden;
string value = cell.StringCellValue;
cell.SetCellValue("LOCKED");`

Using the code above I have found:

  1. 'cell.CellStyle.IsLocked' always returns false, even if the cell is locked in the workbook.
  2. after setting the cell value in the last line and saving file, when opening in excel, the workbook structure protection is lost and the cell style is set to unlocked. The value is written correctly.
@tonyqus
Copy link
Member

tonyqus commented Jan 31, 2022

Can you upload a sample file?

@jrivers1
Copy link
Author

jrivers1 commented Feb 1, 2022

npoi.xlsx

password: Password1

@tonyqus tonyqus added this to the NPOI 2.5.7 milestone Feb 14, 2022
@tonyqus tonyqus modified the milestones: NPOI 2.6.1, NPOI 2.6.0 Apr 27, 2022
@tonyqus tonyqus modified the milestones: NPOI 2.6.0, NPOI 2.6.1 Nov 15, 2022
@tonyqus tonyqus modified the milestones: NPOI 2.6.1, NPOI 2.6.2 Jun 13, 2023
Bykiev added a commit to Bykiev/npoi that referenced this issue Jul 24, 2023
@tonyqus tonyqus self-assigned this Jul 24, 2023
@tonyqus tonyqus modified the milestones: NPOI 2.7.0, NPOI 2.6.2 Aug 23, 2023
tonyqus pushed a commit that referenced this issue Aug 23, 2023
@tonyqus tonyqus added file_error file format generation/writing issue xlsx labels Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug file_error file format generation/writing issue xlsx
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants