C# 设置 Excel 单元格的方法
例如设置单元格颜色、添加或者删除sheet、重命名、行的添加删除等
[C#]代码
using Microsoft.Office.Core; using Microsoft.Office.Interop.Excel; using System.IO; using System.Reflection; Application app = new Application(); Workbooks wbks = app.Workbooks; _Workbook _wbk = wbks.Add(xxx); //Open an exist Excel file, please replace “xxx” with the excel file path. //Create a new Excel file, please replace “xxx” with “true”. //Note: there is only one worksheet in the excel file. Sheets shs = _wbk.Sheets; //Left side boder line _wsh.get_Range( _wsh.Cells[2, 1], _wsh.Cells[2, 2]) .Borders[XlBordersIndex.xlEdgeLeft].Weight = XlBorderWeight.xlThick;// //Right side border line _wsh.get_Range( _wsh.Cells[2, 1], _wsh.Cells[2, 2]) .Borders[XlBordersIndex.xlEdgeRight].Weight = XlBorderWeight.xlThick;// //Upside border line _wsh.get_Range( _wsh.Cells[2, 1], _wsh.Cells[2, 2]) .Borders[XlBordersIndex.xlEdgeTop].Weight = XlBorderWeight.xlThick;//下 //Downside border line _wsh.get_Range( _wsh.Cells[2, 1], _wsh.Cells[2, 2]) .Borders[XlBordersIndex.xlEdgeBottom].Weight = XlBorderWeight.xlThick;