NPOI 用法
2021/6/1 18:30:34
本文主要是介绍NPOI 用法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
HSSFWorkbook workbook = new HSSFWorkbook(); string sheetName = "整改对比"; HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet(sheetName); HSSFRow row1 = (HSSFRow)sheet.CreateRow(0); row1.Height = 1060; HSSFCellStyle cellStyle = (HSSFCellStyle)workbook.CreateCellStyle(); cellStyle.BorderBottom = BorderStyle.Thin;//下边框 cellStyle.BorderTop = BorderStyle.Thin;//上边框 cellStyle.BorderLeft = BorderStyle.Thin;//左边框 cellStyle.BorderRight = BorderStyle.Thin; //右边框 cellStyle.Alignment = HorizontalAlignment.Center;//居中 cellStyle.VerticalAlignment = VerticalAlignment.Center; HSSFFont hSSFFontHeader = (HSSFFont)workbook.CreateFont(); hSSFFontHeader.FontName = "宋体"; hSSFFontHeader.FontHeightInPoints = 11; cellStyle.SetFont(hSSFFontHeader); ICellStyle cellStyleFill = workbook.CreateCellStyle();//创建样式 cellStyleFill.FillPattern = FillPattern.SolidForeground;//填充模式 cellStyleFill.FillBackgroundColor = HSSFColor.Black.Index; //设置填充颜色 HSSFCellStyle cellStyleHeader = (HSSFCellStyle)workbook.CreateCellStyle(); cellStyleHeader.BorderBottom = BorderStyle.Thin;//下边框 cellStyleHeader.BorderTop = BorderStyle.Thin;//上边框 cellStyleHeader.BorderLeft = BorderStyle.Thin;//左边框 cellStyleHeader.BorderRight = BorderStyle.Thin; //右边框 cellStyleHeader.Alignment = HorizontalAlignment.Center;//水平居中 cellStyleHeader.VerticalAlignment = VerticalAlignment.Center; //垂直居中 hSSFFontHeader = (HSSFFont)workbook.CreateFont(); //创建字体 hSSFFontHeader.FontName = "仿宋"; hSSFFontHeader.FontHeightInPoints = 22; hSSFFontHeader.IsBold = true; //加粗 cellStyleHeader.SetFont(hSSFFontHeader); //样式设置字体 cellStyleHeader.FillForegroundColor = HSSFColor.Black.Index; HSSFCell cellHeader = (HSSFCell)row1.CreateCell(0); CellRangeAddress region = new CellRangeAddress(0, 0, 0, 4); //设置合并单元格范围 sheet.AddMergedRegion(region); //合并单元格 sheet.SetEnclosedBorderOfRegion(region, BorderStyle.Thin, NPOI.HSSF.Util.HSSFColor.Black.Index);//合并单元格设置样式 cellHeader.CellStyle = cellStyleHeader; //单元格设定样式 cellHeader.SetCellValue("33333");//单元格设置值 #region 插入图片 byte[] bytes = File.ReadAllBytes(files[i]); int pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG); HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch(); HSSFClientAnchor anchor = new HSSFClientAnchor(23, 5, 1000, 250, 0, i / 4 * 6 + 3, 0, i / 4 * 6 + 5); patriarch.CreatePicture(anchor, pictureIdx); #endregion
这篇关于NPOI 用法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-28MQ底层原理资料详解:新手入门教程
- 2024-11-28MQ项目开发资料详解:新手入门教程
- 2024-11-28MQ项目开发资料详解:入门与初级用户指南
- 2024-11-28MQ消息队列资料入门教程
- 2024-11-28MQ消息队列资料:新手入门详解
- 2024-11-28MQ消息中间件资料详解与应用教程
- 2024-11-28MQ消息中间件资料入门教程
- 2024-11-28MQ源码资料详解与入门教程
- 2024-11-28MQ源码资料入门教程
- 2024-11-28RocketMQ底层原理资料详解