我正在尝试在 VSTO 项目中使用针对 3.5 框架和 Excel2007 的 C# 的 SpecialCells 方法。

这是我的代码:

Excel.Worksheet myWs = (Excel.Worksheet)ModelWb.Worksheets[1];

Range myRange = myWs.get_Range("A7", "A800");

//Range rAccounts = myRange.SpecialCells(XlCellType.xlCellTypeConstants, XlSpecialCellsValue.xlTextValues);

Range rAccounts = myWs.Cells.SpecialCells(XlCellType.xlCellTypeConstants, XlSpecialCellsValue.xlTextValues);

当我运行这个时,它抛出异常......

System.Exception._COMPlusExceptionCode with a value of -532459699

请注意,如果我切换(取消注释一个并注释另一个)上面的 Range rAccounts 行,我会得到相同的异常。

有帮助吗?

解决方案

我想到了...工作表受到保护!

myWs.Unprotect(Properties.Settings.Default.PasswordSheet);

修复它...对于那些在家玩的人...完成后不要忘记保护床单。

myWs.Protect(Properties.Settings.Default.PasswordSheet, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top