简体   繁体   中英

How do I make a Excel cell contents invisible

I have an excel file(VSTO), which will be uploaded with data. However I want to make one cell invisible, as it contains one of the ID's which should not be revealed to the user.

I use Excel.Range.Value2 property to set the value. Now I want to make the value inside it invisible

I am using C#, how do I accomplish the above.

This will make cell content invisible, untill you click on them then you can change the data. Here

Microsoft.Office.Interop.Excel.Range descriptionRange31 = xlApp.get_Range("A18,A25,B18,B25");
descriptionRange31.NumberFormat = ";;;";

I am not sure how to make it invisible. However, you can just copy and save the value in a variable in memory and replace it by string.Empty .

Declare the variable in your plug-ins application object in such a way that it stays alive as long as Excel is open.

If you want to persist it even when Excel application is closed, then either write it to disk or save it in the properties of the Excel workbook (the same place that is visible in Properties page of the workbook) after encoding it.

I have worked on the VSTO Excel applications. In my project i have used specials Ids to identify each column uniquely..

So, i would suggest rather than getting into coding you can do following 2 actions to make it invisible. Go to ur visual studio, open design mode of the workbook. Enter ur ids in columns or rows , wherever u want to (lets assume in column C and Row 5,6)

1.You can see the horizontal / vertical strips at the top and left side of excel which we use to resize the columns n rows ..just adjust it in a such a way that that particular column will be hidden

在此处输入图片说明

as u can see the image, i adjusted columns to Hide Column "C" and Rows to hide row no 5 and 6.

2.Now open excel (not from Visual stodio, from windows explorer) pres Alt+T+P+P and protect the sheet using a perticular password and your are done.

Now user can not make any changes in columns or rows and date remains invisible.

Regards,

Sangram Nandkhile

I'm not sure you can make the contents of a cell "invisible." However, you could go a long way toward that goal by:

  1. Placing the hidden information within a hidden column in a separate worksheet
  2. Password protecting the worksheet structure to prevent unhiding of that hidden column
  3. Hiding the protected worksheet
  4. Password protecting the workbook's VBA project from editing

The security of this approach is not 100% because Excel protection is not exceedingly difficult to break. However, the combination of obscurity (since the worksheet tab is not even visible to the user) and protection of the VBA Project from editing (so even if someone knows the hidden sheet is there, it won't be as easy to code the unhide method) and password protection of the worksheet structure (so it won't be easy to unhide the protected column) should prevent all but the most determined peekers from seeing what you're hiding.

I have not worked with VSTO, so I can't code this for you. The approach is valid though, and all API hooks to achieve it are probably available.

I'm not sure if this answer match your level of question, but this if I would into your problem description. I would just make the font color same as the background and lock the cell from editing (which you of course handle from code, while write/change the value) and go for locking the excel sheet except the cells/regions that explicitly marked as opened.

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