NPOI 2 BorderStylesInXlsx

using System;
using NPOI.SS.UserModel;
using System.IO;
using NPOI.HSSF.Util;
using NPOI.XSSF.UserModel;

namespace XSSF
{
	public class BorderStylesInXlsx
	{
		public static void DoAction()
		{
			IWorkbook workbook = new XSSFWorkbook();
			ISheet sheet = workbook.CreateSheet("Sheet A1");
			IRow row = sheet.CreateRow(1);
			// Create a cell and put a value in it.
			ICell cell = row.CreateCell(1);
			cell.SetCellValue(4);
			
			// Style the cell with borders all around.
			ICellStyle style = workbook.CreateCellStyle();
			style.BorderBottom = BorderStyle.THIN;
			style.BottomBorderColor = HSSFColor.BLACK.index;
			style.BorderLeft = BorderStyle.DASH_DOT_DOT;
			style.LeftBorderColor = HSSFColor.GREEN.index;
			style.BorderRight = BorderStyle.HAIR;
			style.RightBorderColor = HSSFColor.BLUE.index;
			style.BorderTop = BorderStyle.MEDIUM_DASHED;
			style.TopBorderColor = HSSFColor.ORANGE.index;
			
			style.BorderDiagonalLineStyle = BorderStyle.MEDIUM; //this property must be set before BorderDiagonal and BorderDiagonalColor
			style.BorderDiagonal = BorderDiagonal.FORWARD;
			style.BorderDiagonalColor = HSSFColor.GOLD.index;
			
			cell.CellStyle = style;
			// Create a cell and put a value in it.
			ICell cell2 = row.CreateCell(2);
			cell2.SetCellValue(5);
			ICellStyle style2 = workbook.CreateCellStyle();
			style2.BorderDiagonalLineStyle = BorderStyle.MEDIUM;
			style2.BorderDiagonal = BorderDiagonal.BACKWARD;
			style2.BorderDiagonalColor = HSSFColor.RED.index;
			cell2.CellStyle = style2;
			
			FileStream sw = File.Create("BorderStylesInXlsx.xlsx");
			workbook.Write(sw);
			sw.Close();
		}
	}
}

点击查看原图

知识共享许可协议
《NPOI 2 BorderStylesInXlsx》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
相邻依据:发表时间
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

0 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     156.68ms