简体   繁体   中英

How can I hide and protect the text of one Cell in an excel file using openxml with c# (not the entire row/ column)?

I'm not sure if it is possible to hide and protect the data of a specific cell in excel file using openxml(not the entire row or column). Anyone have an idea about that please?

Try using the Protection Class:

public class Protection : OpenXmlLeafElement

18.8.33 protection (Protection Properties)

Contains protection properties associated with the cell. Each cell has protection properties that can be set. The cell protection properties do not take effect unless the sheet has been protected.

hidden (Hidden Cell)

A boolean value indicating if the cell is hidden. When the cell is hidden and the sheet on which the cell resides is protected, then the cell value is displayed in the cell grid location, but the contents of the cell will not be displayed in the formula bar. This is true for all types of cell content, including formula, text, or numbers.

Therefore the cell A4 can contain a formula "=SUM(A1:A3)", but if the cell protection property of A4 is marked as hidden, and the sheet is protected, then the cell should display the calculated result [Example: "6" end example], but will not display the formula used to calculate the result.

The possible values for this attribute are defined by the W3C XML Schema boolean datatype.

locked (Cell Locked)

A boolean value indicating if the cell is locked. When cells are marked as "locked" and the sheet is protected, then the options specified in the Sheet Part's sheetProtection element (§18.3.1.85) are prohibited for these cells.

The possible values for this attribute are defined by the W3C XML Schema boolean datatype.

https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2010/cc798966%28v%3Doffice.14%29

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM