//设置单元格样式:
wSheet.get_Range(wSheet.Cells[5, i + 3], wSheet.Cells[6, i + 3]).Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.Yellow); //设置底色
wSheet.get_Range(wSheet.Cells[5, i + 3], wSheet.Cells[6, i + 3]).Interior.Pattern = Excel.XlPattern.xlPatternLightUp; //设置斜线样式
//打开Excel模板
Excel.Application excel = new Excel.Application();
excel.Workbooks.Add(System.Windows.Forms.Application.StartupPath + @"\Report\Template.xls");
//不使用现有的模板:excel.Workbooks.Add(true);
//向Excel插入一列
excel.get_Range("J:J", "J:J").Insert(Excel.XlInsertShiftDirection.xlShiftToRight, Excel.XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
//使用公式
excel.get_Range(excel.Cells[rowIndex, columnIndex], excel.Cells[rowIndex, columnIndex]).FormulaR1C1 = "=RC[-2]*2";
//设置边框线
Excel.Borders borders = excel.get_Range(excel.Cells[rowIndex, columnIndex], excel.Cells[rowIndex, columnIndex]).Borders;
borders[Excel.XlBordersIndex.xlEdgeBottom].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeLeft].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeRight].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeTop].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlInsideHorizontal].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlInsideVertical].Weight = Excel.XlBorderWeight.xlThin;
//合并单元格
Excel.Range rangeTotal = excel.get_Range(excel.Cells[rowIndex, columnIndex], excel.Cells[rowIndex, columnIndex+1]);
rangeTotal.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
rangeTotal.MergeCells = true;
excel.Cells[rowIndex, 1] = "合計:";
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/BachelorLrz/archive/2008/02/28/2128333.aspx