博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Npoi操作excel
阅读量:4595 次
发布时间:2019-06-09

本文共 2950 字,大约阅读时间需要 9 分钟。

 http://www.cnblogs.com/knowledgesea/archive/2012/11/16/2772547.html

设置背景颜色,边框

//设置样式                 HSSFCellStyle ShenPiStyle = (HSSFCellStyle)workbook.CreateCellStyle();                 ShenPiStyle.Alignment = (HorizontalAlignment)HorizontalAlign.Left;                 ShenPiStyle.VerticalAlignment = VerticalAlignment.CENTER;                 ShenPiStyle.WrapText = true; //自动换行                 HSSFFont ShenPiStylefonts = (HSSFFont)workbook.CreateFont();                 ShenPiStylefonts.FontHeightInPoints = 11;                 ShenPiStylefonts.FontName = "宋体";                 ShenPiStyle.SetFont(ShenPiStylefonts);                 ShenPiStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;                 ShenPiStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;                 ShenPiStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;                 ShenPiStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;                 ShenPiStyle.FillForegroundColor = HSSFColor.LIGHT_CORNFLOWER_BLUE.index;                 ShenPiStyle.FillPattern = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;                 //ShenPiStyle.FillBackgroundColor = HSSFColor.BLUE.index;                                  BeiZhu.GetCell(0).CellStyle = ShenPiStyle;

合并单元格设置单元格的边框:

HSSFRow BeiZhu = (HSSFRow)sheet.CreateRow(rowIndex); //第 3 行                 BeiZhu.Height = 80 * 20;                 CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex, 0, 6);                 sheet.AddMergedRegion(region);                 ((HSSFSheet)sheet).SetEnclosedBorderOfRegion(region, NPOI.SS.UserModel.BorderStyle.THIN, HSSFColor.BLACK.index);

NPOI单元格颜色设置及对照表

 http://www.docin.com/p-665268648.html

 

设置合并单元格文字竖行显示:

//竖行显示的文字样式                 HSSFCreationHelper createHelper = (HSSFCreationHelper)workbook.GetCreationHelper();                 HSSFCellStyle shu = (HSSFCellStyle)workbook.CreateCellStyle();                 shu.VerticalAlignment = VerticalAlignment.CENTER;                 shu.Alignment = (HorizontalAlignment)HorizontalAlign.Center;                 //多行显示                 shu.WrapText = true;                 HSSFFont shufonts = (HSSFFont)workbook.CreateFont();                 shufonts.FontHeightInPoints = 11;                 shufonts.FontName = "宋体";                 shufonts.Boldweight = 600;                 shu.SetFont(shufonts);                 //shu.Rotation = (short)-90;                 shu.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;                 shu.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;                 shu.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;                 HSSFRow row3 = (HSSFRow)sheet.CreateRow(3); //第 3 行                 row3.Height = 30 * 20;                 row3.CreateCell(0, CellType.STRING).SetCellValue(createHelper.CreateRichTextString("本\r\n周\r\n工\r\n作\r\n总\r\n结\r\n"));                  row3.GetCell(0).CellStyle = shu;

 

转载于:https://www.cnblogs.com/kennyliu/p/4114983.html

你可能感兴趣的文章
unshift()与shift()
查看>>
使用 NPOI 、aspose实现execl模板公式计算
查看>>
行为型模式:中介者模式
查看>>
How to Notify Command to evaluate in mvvmlight
查看>>
33. Search in Rotated Sorted Array
查看>>
461. Hamming Distance
查看>>
Python垃圾回收机制详解
查看>>
{面试题1: 赋值运算符函数}
查看>>
Node中没搞明白require和import,你会被坑的很惨
查看>>
Python 标识符
查看>>
Python mysql 创建连接
查看>>
企业化的性能测试简述---如何设计性能测试方案
查看>>
centos7 安装中文编码
查看>>
POJ - 3683 Priest John's Busiest Day
查看>>
正则表达式start(),end(),group()方法
查看>>
vuejs 学习旅程一
查看>>
javascript Date
查看>>
linux常用命令2
查看>>
狼图腾
查看>>
13、对象与类
查看>>