代码:

ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderBottom = BorderStyle.Thin;
cellStyle.BorderLeft = BorderStyle.Thin;
cellStyle.BorderRight = BorderStyle.Thin;
cellStyle.BorderTop = BorderStyle.Thin;
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; ICellStyle cellStyleTitle = workbook.CreateCellStyle();
cellStyleTitle.BorderBottom = BorderStyle.Thin;
cellStyleTitle.BorderLeft = BorderStyle.Thin;
cellStyleTitle.BorderRight = BorderStyle.Thin;
cellStyleTitle.BorderTop = BorderStyle.Thin;
cellStyleTitle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyleTitle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
IFont font = workbook.CreateFont();
font.IsBold = false;
font.FontHeightInPoints = ;
cellStyleTitle.SetFont(font);
HSSFPalette palette = ((HSSFWorkbook)workbook).GetCustomPalette();
palette.SetColorAtIndex((short), , , );
var color = palette.FindColor(, , );
//下面两行设置单元格背景色
cellStyleTitle.FillPattern = FillPattern.SolidForeground;
cellStyleTitle.FillForegroundColor = color.Indexed; ICellStyle cellStyleTitle2 = workbook.CreateCellStyle();
cellStyleTitle2.CloneStyleFrom(cellStyleTitle);
font = workbook.CreateFont();
font.IsBold = false;
font.FontHeightInPoints = ;
cellStyleTitle2.SetFont(font);

NPOI设置Excel单元格字体、边框、对齐、背景色的更多相关文章

  1. NPOI2.2.0.0实例详解(十)—设置EXCEL单元格【文本格式】 NPOI 单元格 格式设为文本 HSSFDataFormat

    NPOI2.2.0.0实例详解(十)—设置EXCEL单元格[文本格式] 2015年12月10日 09:55:17 阅读数:3150 using System; using System.Collect ...

  2. C#导出Excel,并且设置Excel单元格格式,合并单元格.

    注:要添加COM组件 Microsoft Excel 11.0 Object Library  引用. 具体代码如下: using System; using System.Collections.G ...

  3. POI中设置Excel单元格格式

    引用:http://apps.hi.baidu.com/share/detail/17249059 POI中可能会用到一些需要设置EXCEL单元格格式的操作小结: 先获取工作薄对象: HSSFWork ...

  4. POI HSSFCellStyle 设置 Excel 单元格样式

    POI中可能会用到一些需要设置EXCEL单元格格式的操作小结: 先获取工作薄对象: HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb ...

  5. C#中的Excel操作【1】——设置Excel单元格的内容,打开Excel文件的一种方式

    前言 作为项目管理大队中的一员,在公司里面接触最多的就是Excel文件了,所以一开始就想从Excel入手,学习简单的二次开发,开始自己的编程之路! 程序界面 功能说明 打开文件按钮,可以由使用者指定要 ...

  6. 设置DataGridView单元格的文本对齐方式

    实现效果: 知识运用: DataGridViewCellStyle类的Alignment属性     //获取或设置DataGridView单元格内的单元格内容的位置 public DataGridV ...

  7. NPOI2.2.0.0实例详解(九)—设置EXCEL单元格【时间格式】

    原文:http://blog.csdn.net/xxs77ch/article/details/50245391 using System; using System.Collections.Gene ...

  8. NPOI2.2.0.0实例详解(八)—设置EXCEL单元格【数字格式】

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. POI 设置Excel单元格背景色(setFillForegroundColor)

    背景介绍:使用Java开发信息系统项目,项目中往往会涉及到报表管理部分,而Excel表格首当其冲称为最合适的选择,但是对单元格操作时对于设置单元格的背景颜色却很少提及,本文旨在方便单元格背景颜色设计. ...

随机推荐

  1. 7_bootstap之综合案例

    13.综合案例 13.1.案例需求 要求:页面顶部的三部分在PC屏幕上显示为一行,在移动设备屏幕上显示为一部分一行: 导航条在大屏幕展示全部内容,在移动设备上需要将内容能够折叠/展开: 用户名/密码/ ...

  2. uva-10785-模拟水题

    模拟题: 1• The name has a predefined length N.名字长度N2• The vowel value and consonant value of the name m ...

  3. sqlplus rlwrap readline

  4. Django的学习之路

    Django基础 Django框架基础 http协议及web框架 Django-2的路由层(URLconf) Django的视图层 Django框架之第三篇模板语法(重要!!!) Django框架之模 ...

  5. MySQL函数及用法示例

    (一) 1.字符串函数ascii(str)    返回字符串str的第一个字符的ascii值(str是空串时返回0)   mysql> select ascii('2');   -> 50 ...

  6. 关于document.cookie的使用

    设置cookie每个cookie都是一个名/值对,可以把下面这样一个字符串赋值给document.cookie:document.cookie="userId=828";如果要一次 ...

  7. 【HTTP请求】、详解

    一.协议介绍 HTTP(HyperText Transfer Protocol,超文本传输协议)是一套计算机通过网络进行通信的规则,使HTTP客户端能够从HTTP服务器端请求到信息和服务,目前的版本号 ...

  8. unity3d 移动与旋转 1

    移动与旋转 1 player角色随asdw按键左右上下移动并旋转 public void Update() { // Reset player rotation to look in the same ...

  9. jQuery的基础dom和css操作

    1.元素以及内容操作 $(function () { // alert($("a").html()); // 获取元素中间的html内容,包括标签和文本内容 // alert($( ...

  10. 在PowerDesigner中设计物理模型1——表和主外键(转)

    出处:http://www.cnblogs.com/studyzy/archive/2009/12/15/1624899.html 在PD中建立物理模型由以下几种办法: 直接新建物理模型. 设计好概念 ...