What object type are multiple selected sheets in Excel?

て烟熏妆下的殇ゞ 提交于 2019-12-24 06:42:12

问题


Contrary to what I would think, multiple selected sheets are not a Worksheets object type.

After multi-selecting 2 or more sheets. The way I get the selection is as so:

var selection = ExcelApp.Selection; //Returns object type

I've tried getting the "Name" property to try and give me a hint by using late binding with:

string name = selection.GetType().InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, selection, null).ToString();

But this throws errors for the given selection type.

Any ideas?


回答1:


In VBA, ActiveWindow.SelectedSheets returns a Sheets collection, so I imagine it will be similar in C#

Yep: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.window.selectedsheets(v=office.11).aspx



来源:https://stackoverflow.com/questions/10591443/what-object-type-are-multiple-selected-sheets-in-excel

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