SpecialCells in VSTO

こ雲淡風輕ζ 提交于 2019-12-13 14:31:10

问题


I'm trying to use the SpecialCells method in a VSTO project using c# against the 3.5 framework and Excel2007.

Here's my code:

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);

When I run this, it throws an exception...

System.Exception._COMPlusExceptionCode with a value of -532459699

Note that I get the same exception if I switch (uncomment one and comment the other) the above Range rAccounts line.


回答1:


I figured it out... the worksheet was protected!

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

fixes it...for those playing along at home...don't forget to protect the sheet when you're done.

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);


来源:https://stackoverflow.com/questions/51754/specialcells-in-vsto

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!