从Excel单元格读取值 [英] Reading a value from Excel cell

查看:97
本文介绍了从Excel单元格读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// ws is an object variable of worksheet
// systype is a string variable

Range r = (Range)ws.Cells[2, 2];
systype = r.Value2.ToString();




如何将这两行合并为一行?

请帮忙.




How can I combine these two lines into one single line?

Please help.

推荐答案

尝试
systype = ((Range)ws.Cells[2, 2]).Value2.ToString();


一种可能是仅使用括号.像这样的东西:
One possibility could be to just simply use parenthesis. Something like:
systype = ((Range)ws.Cells[2, 2]).Value2.ToString();


这取决于要求是否是正确的方法(错误处理需求,如果变量r也用于其他东西等).


It depends on the requirements if that''s a correct approach (error handling needs, if variable r is also used for something else etc).


这篇关于从Excel单元格读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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