对象中的C#.NET Excel问题 [英] C#.NET Excel Issue in object

查看:74
本文介绍了对象中的C#.NET Excel问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在c#.net中遇到了有关Excel的问题.我的应用程序是简单地从excel读取数据并放入sql dbase.我用vb.net开发的.没有问题.但是当我更改为c#.net时,我遇到了有关对象变量的问题.我的vb.net代码在这里:

Hi all,

I got an issue about Excel in c#.net. my application is simple read data from excel and put into the sql dbase. i developed with vb.net. there is no issue. but when i change to c#.net i faced an issue about object variable. my vb.net code is here:

Dim obj as Object

For intInc as integer=2 to xlRange.Rows.Count
       obj = xlRange.Cells(i,1)
       Dim strValue as string = obj.value       
       SaveInDbase(strValue)
Next



但是当我更改为c#.net时.该对象没有.value.所以我应该如何从对象变量中获取值.我的C#代码在这里:



but when i change to c#.net. the object don''t have .value. so how should i take value from object variable.my c# code is here:

Object obj=null;
for (int i=1;i<xlrange.rows.count;i++){>
        obj = xlRange.Cells[i,1];                
        String strValue = obj.value;
        SaveInDbase(strValue);
}



我还把obj.ToString(),obj作为字符串,(string)obj.但仍然无法正常工作.我只有"System .__ comobject" :(

请帮助我,并给我建议,在此先谢谢您.



i also put obj.ToString(),obj as string,(string)obj. but still cannot work. i got "System.__comobject" only :(

please help me and give me suggestion , thanks in advance.

推荐答案

我怀疑您的问题是VB确实是巫毒教.对象没有value属性,但是如果将其强制转换为该对象实际是其实例的对象,它将具有此属性.使用调试器找出对象的类型(如果需要),然后相应地更改对象的类型.
I susoect that your issue is that VB does voodoo. Object does NOT have a value property, but if you cast it to what the object actually is an instance of, it will. Use the debugger to find out what the type of your object is, if you need to, then change the type of the object accordingly.


这篇关于对象中的C#.NET Excel问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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