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