vb.net - Microsoft.Office.Interop.Excel VB.NET 如何禁用工作表中的选择锁定值

标签 vb.net excel

我在 protected Excel 工作表上使用 VB.Net 中的 Microsoft.Office.Interop.Excel 库。所有 protected 设置都工作正常,除了我无法设置选择锁定单元格(当您使用 Excel 保护表界面时显示),但我无法看到如何使用库将其设置为 false。我已尝试了保护方法中的所有不同值,但都没有切换该值。

Excel protected 工作表菜单
Excel protected sheet menu

下面是我用来获取工作表、填充一些值,然后保护工作表的代码片段。 GetWorkSheet 是一个内部方法,它将返回一个 WorkSheet 对象,invoiceData 是一个数据表,其中包含要添加到电子表格中的数据。

Dim newSheet As Worksheet = getWorkSheet(newSheetName)

' Make the current Work Sheet active so that it will be accepting the data.
newSheet.Activate()
newSheet.Unprotect(sheetPassword)
For i As Integer = 1 To invoiceData.Rows(0).ItemArray.Count
    newSheet.Cells(transactionalRow, i) = invoiceData.Rows(0).ItemArray(i - 1)
Next
'work is done so protect it again
newSheet.Protect(sheetPassword, False, True, False, True, True, True, True, True, True, True, True, True, True, True, True)
excel.ActiveWorkbook.Save()

最佳答案

这非常令人困惑,因为该属性不是使用 Protect 语句设置的。

调用保护语句后,发出以下调用:

ActiveSheet.EnableSelection = xlNoRestrictions

请参阅此页面了解 EnableSelection 的其他值: http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.worksheet.enableselection(VS.80).aspx

关于vb.net - Microsoft.Office.Interop.Excel VB.NET 如何禁用工作表中的选择锁定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7235177/

相关文章:

c# - VSTO 中的 Excel 控件

vb.net - AddressOf 带参数

c# - Console.WriteLine(Enum.Value) 在 C# 和 VB.Net 中给出不同的输出

arrays - 跳过数组中的列

Excel函数在字符串中搜索多个关键字

excel - 如何创建看起来像Excel "From Other Sources"的VSTO功能区库?

excel - 在 Excel 工作表之间移动数据

vb.net - 试图删除超过 x 天 vb.net 的文件

.net - 结合枚举

asp.net - 当内容更改时如何清除现有的下拉列表项?