获取类型的形状下拉列表
本文关键字:下拉列表 取类型 获取 | 更新日期: 2023-09-27 18:29:43
这是我想改进的一些可怕的代码:
Excel.Shapes theShapes = excelSheet.Shapes;
foreach (Excel.Shape aShape in theShapes)
{
foreach (var groupItem in aShape.GroupItems)
{
//Console.WriteLine(Microsoft.VisualBasic.Information.TypeName(groupItem));
var s = (Excel.Shape) groupItem;
if (s is Excel.OLEObject) continue;
try
{
if (s.FormControlType == Excel.XlFormControl.xlDropDown)
{
Console.WriteLine("### " + s.Name);
}
}
catch (Exception e)
{
}
}
}
有没有一种方法可以更容易地获得下拉列表?当我尝试获取FormControlType时,如何避免上述异常?
只需将try...cath
替换为确认其为FormControl
的条件。
Excel.Shapes theShapes = excelSheet.Shapes;
foreach (Excel.Shape aShape in theShapes)
{
foreach (var groupItem in aShape.GroupItems)
{
var s = (Excel.Shape) groupItem;
if (s is Excel.OLEObject) continue;
if (s.Type == Microsoft.Office.Core.MsoShapeType.msoFormControl)
{
if (s.FormControlType == Excel.XlFormControl.xlDropDown)
{
Console.WriteLine("### " + s.Name);
}
}
}
}