我在 protected Excel 工作表上使用 VB.Net 中的 Microsoft.Office.Interop.Excel 库。所有 protected 设置都工作正常,除了我无法设置选择锁定单元格(当您使用 Excel 保护表界面时显示),但我无法看到如何使用库将其设置为 false。我已尝试了保护方法中的所有不同值,但都没有切换该值。
Excel protected 工作表菜单
下面是我用来获取工作表、填充一些值,然后保护工作表的代码片段。 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/