VSTO迁移错误-无法将带有[]的索引应用于类型为Microsoft.Office.Tools.Excel.ControlCollection的表达式 [英] VSTO Migration Error - Cannot apply indexing with [] to an expression of type Microsoft.Office.Tools.Excel.ControlCollection

查看:128
本文介绍了VSTO迁移错误-无法将带有[]的索引应用于类型为Microsoft.Office.Tools.Excel.ControlCollection的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码段与"Visual Studio 2005 Office Runtime工具"和VS 2008配合良好.Office 2003正是为此目的的.


The following piece of code was working fine with "Visual Studio 2005 Tools For Office Runtime" and VS 2008.. Office 2003 was targeted for this.


static public void ResizeAllNamedRanges(
                           Tools.WorksheetBase wksht,
                           int iResizeRows,
                           int iResizeCols,
                           bool bFillDown )
                     {
                           Debug.Assert( wksht != null );
 
 
                           for ( int i = 0; i < wksht.Controls.Count; i++ )
                           {
 
                                  if ( ( ( object )( wksht.Controls[ i ] ) ).GetType( ) ==
                                         typeof( Tools.NamedRange ) )
                                  {
                                         ResizeNamedRange(
                                                ( Tools.NamedRange )wksht.Controls[ i ],
                                                iResizeRows, iResizeCols
                                         );
 
                                         if ( bFillDown )
                                         {
                                                ( ( Tools.NamedRange )wksht.Controls[ i ] ).FillDown( );
                                         }
                                  }
                           }
                     }



但是现在,当我迁移到以Office 2010为目标的VS 2010时,此代码不起作用.它构建良好..但是问题是,尽管在工作表中有命名范围,但以下条件仍未得到满足.迁移之前此条件已得到满足.

if((((object)(wksht.Controls [i])).GetType()== typeof(Tools.NamedRange))



另外,当我尝试对wksht.Controls [i]进行快速监视时.我收到以下错误:
无法将带有[]的索引应用于类型为Microsoft.Office.Tools.Excel.ControlCollection的表达式".

谁能帮忙吗?这是迁移问题吗?我错过了什么吗?

谢谢.



But now, when I have migrated to VS 2010 targeting Office 2010, this code does not work. It Builds fine.. but the issue is that the following condition is not getting satisfied,although there are named ranges in worksheet. This condition was getting satisfied before migration.

if ( ( ( object )( wksht.Controls[ i ] ) ).GetType( ) == typeof( Tools.NamedRange ) )



Also when I try a quick watch on wksht.Controls[i]. I get the following error:
"Cannot apply indexing with [] to an expression of type Microsoft.Office.Tools.Excel.ControlCollection".

Can anyone please help? Is it a migration issue? Am I missing out on something?

Thanks.

推荐答案

您是否要在上面的代码中强制转换工作表控件以键入object?

导致(简化)if (System.object == Tools.NamedRange)


应该不写吗?

if ( wksht.Controls[ i ].GetType( ) == typeof( Tools.NamedRange ) )
Are you not casting the worksheet control to type object in the code above?

resulting in (simplified) if (System.object == Tools.NamedRange)


Should this not be written;

if ( wksht.Controls[ i ].GetType( ) == typeof( Tools.NamedRange ) )


这篇关于VSTO迁移错误-无法将带有[]的索引应用于类型为Microsoft.Office.Tools.Excel.ControlCollection的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆