awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
364 stars 79 forks source link

Worksheet protection not preserved by loading/saving xlsx file #410

Closed kainhofer closed 6 years ago

kainhofer commented 6 years ago

I have a workbook where the sheets are protected, so users can only edit explicitly unlocked cells. That worksheet protection is stored in the worksheet xml files using the XML element:

<worksheet [...]>
[...]
<sheetData>[...]</sheetData>
<sheetProtection selectUnlockedCells="1" selectLockedCells="1" scenarios="1" objects="1" sheet="1"/>
[...]
</worksheet>

Expected Behavior

Loading a file with worksheet protection with loadWorkbook and saving it again using saveWorkbook should preserve the protection of the worksheet.

Actual Behavior

Loading a file with worksheet protection with loadWorkbook and saving it again using saveWorkbook removes the protection of the worksheet.

Steps to Reproduce the Problem

2018-08-16_WorksheetProtection.xlsx

library(openxlsx)
wb = loadWorkbook("2018-08-16_WorksheetProtection.xlsx")
saveWorkbook(wb, "2018-08-16_WorksheetProtection.saved.xlsx")

sessionInfo()

This bug report is about the worksheet protection. The fact that the protection flag of individual cells is also lost, is already reported as a different bug #409 (since it concerns different settings and needs to be fixed differently).

kainhofer commented 6 years ago

Fixed by PR #413 (commit 3fc002555cc4338c3e48164168326b0382ca3377)