C# 操作 Excel 单元格格式设置

C# 操作 Excel 单元格自动填充,居中对齐,字体颜色设置

  1.   
  2.  
  3. //设置标题 
  4. Excel.Range titleRange = worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, columnCount]);//选取单元格,选取一行或多行 
  5. titleRange.Merge(true);//合并单元格 
  6. titleRange.Value2 = strTitle; //设置单元格内文本 
  7. titleRange.Font.Name = "宋体";//设置字体 
  8. titleRange.Font.Size = 18;//字体大小 
  9. titleRange.Font.Bold = true;//加粗显示 
  10. titleRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;//水平居中 
  11. titleRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;//垂直居中 
  12. titleRange.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;//设置边框 
  13. titleRange.Borders.Weight = Excel.XlBorderWeight.xlMedium;//边框常规粗细 
 

//设置标题
Excel.Range titleRange = worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, columnCount]);//选取单元格,选取一行或多行
titleRange.Merge(true);//合并单元格
titleRange.Value2 = strTitle; //设置单元格内文本
titleRange.Font.Name = "宋体";//设置字体
titleRange.Font.Size = 18;//字体大小
titleRange.Font.Bold = true;//加粗显示
titleRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;//水平居中
titleRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;//垂直居中
titleRange.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;//设置边框
titleRange.Borders.Weight = Excel.XlBorderWeight.xlMedium;//边框常规粗细

参考:http://blog.csdn.net/zhaobisha/article/details/3862568

阅读更多
换一批

没有更多推荐了,返回首页