【转】.NET NPOI操作Excel常用函数
最近因项目接触了NPOI,感觉还是蛮不错的,网络上的教程普遍版本较老,本篇记录所常用操作,采用NPOI 2.0版本。
新建Excel
合并单元格
sheet1.AddMergedRegion(newCellRangeAddress(2,3,0,1));//合并A3-B4
//CellRangeAddress(起始行,终止行,起始列,终止列);
添加边框
ICellStyle style2 = hssfworkbook.CreateCellStyle(); style2.BorderBottom= NPOI.SS.UserModel.BorderStyle.THIN; style2.BorderLeft= NPOI.SS.UserModel.BorderStyle.THIN;style2.BorderRight= NPOI.SS.UserModel.BorderStyle.THIN; style2.BorderTop= NPOI.SS.UserModel.BorderStyle.THIN;
//添加斜线
style2.BorderDiagonal = BorderDiagonal.BACKWARD; style2.BorderDiagonalLineStyle= NPOI.SS.UserModel.BorderStyle.THIN;
cell2.CellStyle= style2;
添加边框要对上下左右边框都进行描述。
设置对齐相关设置
ICellStyle style3 = hssfworkbook.CreateCellStyle(); style3.Alignment= NPOI.SS.UserModel.HorizontalAlignment.CENTER;//居中style3.VerticalAlignment=VerticalAlignment.CENTER;//垂直居中 style3.WrapText=true;//自动换行
sheet1.GetRow(0).GetCell(2).CellStyle= style3;
转载自:http://anchises.blog.163.com/blog/static/6432108220129211423620/
最新文章
- python——django的post请求
- Rubinius 2.0 发布,Ruby 虚拟机
- JQuery Object vs. DOM element
- js获取gridview模板列中textbox行列的值
- 由于 add 运算符中“Chinese_PRC_CI_AS”和“Chinese_PRC_CS_AS_WS”之间的排序规则冲突
- 【转发】CentOS 7 巨大变动之 systemd 取代 SysV的Init
- Python 手册——解释器及其环境
- Linux内核实现多路镜像流量聚合和复制
- python cmd 模块
- XMLHttpRequest API 使用指南
- JDBC 数据库连接操作——实习第三天
- 统计每日单量MySQL语句
- JVM高手之路七(tomcat调优以及tomcat7、8性能对比)
- tornado项目注意点
- C#模拟PrtScn实现截屏
- js弹出window.open窗口
- Linux远程连接Windows桌面
- hibernate、mybatis、spring data 的对比
- 兼容获取元素当前样式 currentStyle || getComputedStyle
- P4592 [TJOI2018]异或 (可持久化Trie)
热门文章
- 如何获取 docker 容器(container)的 ip 地址
- 拟物设计和Angular的实现 - Material Design
- Asp.Net MVC记住用户登录信息 下次登录无需输入密码
- 【转】PowerDesigner删除外键关系,而不删除外键列
- 【BZOJ3555】 [Ctsc2014]企鹅QQ
- 【问题解决方案】Keras手写数字识别-ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接
- 【Spark基础】:RDD
- VS2013 编辑器
- flask框架--cookie,session
- MYSQL基础语法的使用