代码如下:请过目!
private Excel.Application objApp;
private Excel.Sheets objSheets;
private Excel._Worksheet objSheet;
private Excel.Range range;
objApp = new Excel.Application();
objSheet = (Excel._Worksheet)objSheets.get_Item(1);
/// <summary>
/// 设置单元格的背景色---多个连接的单元格
/// </summary>
/// <param name="sRow">开始行</param>
/// <param name="sCol">开始列</param>
/// <param name="eRow">结束行</param>
/// <param name="eCol">结束列</param>
/// <param name="colorIndex">颜色的索引</param>
public void SetRangeBackground(int sRow,int sCol,int eRow,int eCol,int colorIndex)
{
range=objSheet.get_Range(objSheet.Cells[sRow,sCol],objSheet.Cells[eRow,eCol]);
range.Interior.ColorIndex=colorIndex;
}
/// <summary>
/// 设置单元格的线
/// </summary>
public void SetBorderLine(int sRow,int sCol,int eRow,int eCol)
{
range=objSheet.get_Range(objSheet.Cells[sRow,sCol],objSheet.Cells[eRow,eCol]);
range.Cells.Borders.LineStyle=1;
}