range.NumberFormatLocal = "@"; //设置单元格格式为文本- range = (Range)worksheet.get_Range("A1", "E1"); //获取Excel多个单元格区域:本例做为Excel表头
- range.Merge(0); //单元格合并动作
- worksheet.Cells[1, 1] = "Excel单元格赋值"; //Excel单元格赋值
- range.Font.Size = 15; //设置字体大小
- range.Font.Underline=true; //设置字体是否有下划线
- range.Font.Name="黑体"; 设置字体的种类
- range.HorizontalAlignment=XlHAlign.xlHAlignCenter; //设置字体在单元格内的对其方式
- range.ColumnWidth=15; //设置单元格的宽度
- range.Cells.Interior.Color=System.Drawing.Color.FromArgb(255,204,153).ToArgb(); //设置单元格的背景色
- range.Borders.LineStyle=1; //设置单元格边框的粗细
- range.BorderAround(XlLineStyle.xlContinuous,XlBorderWeight.xlThick,XlColorIndex.xlColorIndexAutomatic,System.Drawing.Color.Black.ToArgb()); //给单元格加边框
- range.Borders.get_Item(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeTop).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone; //设置单元格上边框为无边框
- range.EntireColumn.AutoFit(); //自动调整列宽
- Range.HorizontalAlignment= xlCenter; // 文本水平居中方式
- Range.VerticalAlignment= xlCenter //文本垂直居中方式
- Range.WrapText=true; //文本自动换行
- Range.Interior.ColorIndex=39; //填充颜色为淡紫色
- Range.Font.Color=clBlue; //字体颜色
- xlsApp.DisplayAlerts=false;