Excel.Excel.Range rng = xSheet.get_Range("C2", Missing.Value);
rng.Value2 

解决方案 »

  1.   

    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.   

    excel 2007 操作
      

  3.   

    1楼:这"C2"是硬编码,我要获得我当前选择的范围啊.
    2楼:range = objSheet.get_Range("A1", "E5"); 这里也是硬编码选范围.知道题目中"随机"的含义吗?
    3楼:只是一个值,读取不了一个范围.强调:动态选择范围的值
      

  4.   

    动态选择范围的值。就要在EXCEL中获取使用宏
      

  5.   

    6楼:就是人手随机在Excel里选,再在代码中人手选的范围内容.
    7楼:能不能讲详细点啊?