1.获取单元格数据:string temp=((Range)worksheet.Cells[1,2]).Text; 2.获取选中区域数据//Get a range of data. range = objSheet.get_Range("A1", "E5"); //换成选定的区域 .select//Retrieve the data from the range. Object[,] saRet; saRet = (System.Object[,])range.get_Value( Missing.Value );//Determine the dimensions of the array. long iRows; long iCols; iRows = saRet.GetUpperBound(0); iCols = saRet.GetUpperBound(1);//Build a string that contains the data of the array. String valueString; valueString = "Array Data\n"; for (long rowCounter = 1; rowCounter <= iRows; rowCounter++) { for (long colCounter = 1; colCounter <= iCols; colCounter++) { //Write the next value into the string. valueString = String.Concat(valueString, saRet[rowCounter, colCounter].ToString() + ", "); } //Write in a new line. valueString = String.Concat(valueString, "\n"); }//Report the value of the array. MessageBox.Show(valueString, "Array Values");详细可参考:获取某区域中的数据
2.获取选中区域数据//Get a range of data.
range = objSheet.get_Range("A1", "E5"); //换成选定的区域 .select//Retrieve the data from the range.
Object[,] saRet;
saRet = (System.Object[,])range.get_Value( Missing.Value );//Determine the dimensions of the array.
long iRows;
long iCols;
iRows = saRet.GetUpperBound(0);
iCols = saRet.GetUpperBound(1);//Build a string that contains the data of the array.
String valueString;
valueString = "Array Data\n"; for (long rowCounter = 1; rowCounter <= iRows; rowCounter++)
{
for (long colCounter = 1; colCounter <= iCols; colCounter++)
{ //Write the next value into the string.
valueString = String.Concat(valueString,
saRet[rowCounter, colCounter].ToString() + ", ");
} //Write in a new line.
valueString = String.Concat(valueString, "\n");
}//Report the value of the array.
MessageBox.Show(valueString, "Array Values");详细可参考:获取某区域中的数据
2楼:range = objSheet.get_Range("A1", "E5"); 这里也是硬编码选范围.知道题目中"随机"的含义吗?
3楼:只是一个值,读取不了一个范围.强调:动态选择范围的值
7楼:能不能讲详细点啊?