过来看看吧:读取excel文件单元格数据,range.Cells.Value2是什么含义?有没有讲解excel类库函数的资料啊

fishthunder1104 fishthunder1104 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
excel中sheet1中a1=1,b1=2


读取excel文件
Excel.Range range = worksheet.get_Range("a1","b1");
System.Array myvalues = (System.Array)range.Cells.Value2;
string[] strArray = ConvertToStringArray(myvalues);
this.textBox1.Text=strArray[0];

string[] ConvertToStringArray(System.Array values)
{
// create a new string array
string[] theArray = new string[values.Length];
// loop through the 2-D System.Array and populate the 1-D String Array
for (int i = 1; i < values.Length; i++)
{
if (values.GetValue(1, i) == null)
theArray[i-1] = "";
else
theArray[i-1] = (string)values.GetValue(1, i).ToString();
}
return theArray;
}
结果是this.textbox1.text=1
但是如果改为this.textBox1.Text=strArray[1];结果this.textbox1.text就是空,而不是2
为什么??

...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
fishthunder1104
C# 111,129 成员 642,538 内容