这样就可以了
使用: myRange myCells=new myRange(mySheet)
myCells[1,1].text="abc";
myCells[1,1].backColorIndex=5;
class myRange
{
Excel.Worksheet mysheet = null;
Excel.Range myrange = null;
public myRange(Excel.Worksheet _mysheet)
{
mysheet = _mysheet;
}
public myRange this[int row, int column]
{
get
{
if (row > 0 && column > 0)
{
myrange = (Excel.Range)mysheet.Cells[row, column];
return this;
}
else
{
return null;
}
}
}
/// <summary>
///取得和设置表格中的数据
/// </summary>
public string text
{
get { return myrange.Text.ToString(); }
set { myrange.Value2 = value; }
}
public int backColorIndex
{
get { return int.Parse(myrange.Interior.ColorIndex.ToString()); }
set{myrange.Interior.ColorIndex=value;}
}
}