打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Type Conversion trouble, when assigning a cel...
 am trying to assign the value2 from a cell in a worksheet to a int variable.

The following code gets compiled, but when in debug, a type conversion problem ocurs.

I don't understand, what happens.

 

Cheers

Heinz

 

this is the code in workbook.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Microsoft.Office.Tools.Excel;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;

namespace TypenTest
{
    public partial class ThisWorkbook
    {
        public int NumberOfPeople;
        NamedRange nPeopleCell;

        private void ThisWorkbook_Startup(object sender, System.EventArgs e)
        {
            nPeopleCell = Globals.Tabelle1.nPeople; // nPeople ist the name of a cell in Worksheet "Tabelle1"

            nPeopleCell.Change += new Excel.DocEvents_ChangeEventHandler(nPeopleCell_Change);
        }




        void nPeopleCell_Change(Excel.Range Target)
        {
            NumberOfPeople = (int) Globals.Tabelle1.nPeople.Value2 ; ERROR Message "invalid type conversion" in this line
            Excel.Range tmpCell = Globals.Tabelle1.get_Range("D12", missing);
            tmpCell.Value2 = "nPeople: " + NumberOfPeople.ToString();

        }

        private void ThisWorkbook_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region Vom VSTO-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für Designerunterstützung -
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisWorkbook_Startup);
            this.Shutdown += new System.EventHandler(ThisWorkbook_Shutdown);
        }

        #endregion

    }
}

Answers

  • Sunday, September 19, 2010 5:47 PM
    lilalaser
     

    I found a solution

     

    NumberOfPeople = System.Convert.ToInt32(Globals.Tabelle1.nPeople.Value2)

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
哈哈哈哈....笑死我了......哈哈哈哈.....向高手致敬[图]
2012年中考总复习攻略资料大全
请你喝杯热咖啡
【Excel VBA】怎样使用工作簿的相对路径
细品RibbonX(50):如何共享Ribbon定制之Excel部署技术
如何让SAP S/4HANA的Material Fiori应用配置到Fiori Launchpad里
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服