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

fishthunder1104 2004-10-08 08:42:30
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
为什么??

...全文
1389 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lostinet 2004-10-08
  • 打赏
  • 举报
回复
无论是Range属性,Cells,Rows,Columns这些属性,其类型都是Excel.Range,都有Value2这个属性

一般是取得某个区域(某行,某列,某个选择的区域,或某个单元格) , 然后用Value得到它的值. Value2则是针对数字的.

请到http://www.lostinet.com/files/exceldocs.rar下载chm文档
孟子E章 2004-10-08
  • 打赏
  • 举报
回复
参考资料
http://msdn.microsoft.com/library/en-us/dnanchor/html/odc_ancoffsol.asp

110,546

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧