简体   繁体   English

如何使Excel单元格内容不可见

[英]How do I make a Excel cell contents invisible

I have an excel file(VSTO), which will be uploaded with data. 我有一个Excel文件(VSTO),它将与数据一起上传。 However I want to make one cell invisible, as it contains one of the ID's which should not be revealed to the user. 但是,我想使一个单元格不可见,因为它包含不应向用户显示的ID之一。

I use Excel.Range.Value2 property to set the value. 我使用Excel.Range.Value2属性设置值。 Now I want to make the value inside it invisible 现在我想使其中的值不可见

I am using C#, how do I accomplish the above. 我正在使用C#,如何完成以上任务。

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 . 但是,您只需将值复制并保存到内存中的变量中,然后将其替换为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. 声明插件应用程序对象中的变量,以使其在打开Excel时一直有效。

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. 如果即使在关闭Excel应用程序时也要保留它,则可以在对其进行编码后将其写入磁盘或保存在Excel工作簿的属性中(该位置在工作簿的“属性”页面中可见)。

I have worked on the VSTO Excel applications. 我已经在VSTO Excel应用程序上工作。 In my project i have used specials Ids to identify each column uniquely.. 在我的项目中,我使用特殊ID来唯一标识每一列。

So, i would suggest rather than getting into coding you can do following 2 actions to make it invisible. 因此,我建议您可以执行以下2个操作以使其不可见,而不是开始编码。 Go to ur visual studio, open design mode of the workbook. 转到ur visual studio,打开工作簿的设计模式。 Enter ur ids in columns or rows , wherever u want to (lets assume in column C and Row 5,6) 在您想要的任何位置的列或行中输入您的ID(假设在C列和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 1,您可以在excel的顶部和左侧看到水平/垂直条,我们使用它们来调整n行的列大小..以使其隐藏特定列的方式对其进行调整

在此处输入图片说明

as u can see the image, i adjusted columns to Hide Column "C" and Rows to hide row no 5 and 6. 如您所见,我将列调整为隐藏列“ C”,将行调整为隐藏第5和第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. 2.现在打开excel(不是来自Visual stodio,不是来自Windows资源管理器),按Alt + T + P + P并使用垂直密码保护工作表,操作就完成了。

Now user can not make any changes in columns or rows and date remains invisible. 现在,用户无法对列或行进行任何更改,并且日期仍然不可见。

Regards, 问候,

Sangram Nandkhile 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 密码保护工作簿的VBA项目免于编辑

The security of this approach is not 100% because Excel protection is not exceedingly difficult to break. 这种方法的安全性不是100%,因为Excel保护并不是很难破解的。 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. 但是,模糊性(因为用户甚至看不到工作表选项卡)和保护VBA项目免受编辑的结合(因此,即使有人知道隐藏的工作表存在,编写取消隐藏的代码也不会那么容易)方法)和工作表结构的密码保护(这样就不容易取消隐藏受保护的列)应该阻止除了最坚决的偷窥者之外的所有人看到您隐藏的内容。

I have not worked with VSTO, so I can't code this for you. 我没有使用VSTO,因此无法为您编写代码。 The approach is valid though, and all API hooks to achieve it are probably available. 该方法虽然有效,但实现它的所有API挂钩都可能可用。

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. 我只是将字体颜色设置为与背景相同,并锁定单元格以防止编辑(当然,您可以从代码中处理该单元格,同时写入/更改值),然后锁定excel工作表,但明确标记为已打开的单元格/区域除外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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