获取types下拉列表的形状
这是我想要改进的一些可怕的代码:
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时,如何避免上述exception?
只要用一个确认它是FormControl
的条件来replacetry...cath
。
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); } } } }
- Excel与C#:当复制范围时,排除第一行
- ASP.NET MVC / C# – 如何转换/创buildExcel(xls)从MVC中的DataTable /列表的格式?
- 将分号文本转换为Excel
- 为Excel 2010构build的Excel加载项可以在Excel 2013中工作吗?
- 如何使一个用户表单发布系统graphics(.net)
- .NET / COMexception与IRTDUpdateEvent
- carlosAg Excel XML工作簿代码生成器和FlexCel APIMate有没有其他select?
- 使用VBA或.NET创buildExcel加载项
- 在WCF中为每个调用机制创build多less个实例上下文