NPOI简单应用
2024-08-25 17:34:29
打开或创建文件
fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
不同版本的workbook
if (fileName.IndexOf(".xlsx") > 0) // 2007版本 workbook = new XSSFWorkbook(); else if (fileName.IndexOf(".xls") > 0) // 2003版本 workbook = new HSSFWorkbook();
设置样式和背景色 样式很狗 需要基于workbook 背景色不是FillBackgroundColor 这个没卵用
//头部样式 ICellStyle headcellStyle = workbook.CreateCellStyle(); headcellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; headcellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; headcellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; headcellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; headcellStyle.FillBackgroundColor = HSSFColor.Black.Index; headcellStyle.FillPattern = FillPattern.SolidForeground; headcellStyle.FillForegroundColor = HSSFColor.Orange.Index;
创建sheet
sheet = workbook.CreateSheet(sheetName);
创建row
IRow row = sheet.CreateRow();
创建cell
ICell icell1top = row.CreateCell(j);
cell赋值设置样式
icell1top.CellStyle = headcellStyle; icell1top.SetCellValue(data.Columns[j].ColumnName);
最新文章
- 浏览器的兼容模式下的button中文字垂直方向不居中显示
- 在UPDATE中更新TOP条数据以及UPDATE更新中使用ORDER BY
- vim 标签命令
- [转]CentOS下安装伪分布式Hadoop-1.2.1
- mongodb 最佳实践
- 23、获取app所占据的内存
- [转]“WARNING: soft rlimits too low” in MongoDB with Mac OS X
- js、expression表达式解析
- <;转>;详解DNS的常用记录(上):DNS系列之二
- 「Githug」Git 游戏通关流程
- C语言初学 求100到200的全部素数
- top 查看资源使用
- Java-byte[]与16进制字符串互转
- C# 自定义样式实现菜单和工具栏的分割线
- Vue项目模板--和--webpack自动化构建工具的---项目打包压缩使用
- UNIX环境高级编程——system V信号量
- Cocos Creator JS 获取当前日期与时间
- WebStorm Goland PyCharm 等JetBrains验证服务器
- 5-5 re模块 正则表达式
- UVa 11988 Broken Keyboard(数组模拟链表)
热门文章
- instanceof关键字
- Access denied for user &#39;Administrator&#39;@&#39;localhost&#39; (using password: YES)
- leetcode-【中等题】2. Add Two Numbers
- Mbps、Kbps、bps、MB、KB
- 全站 HTTPS 来了(转载)
- jq封装的tab切换
- mysql日志开启和查看
- ios10 no route to host
- 编译FFmpeg成一个SO库<;转>;
- JCL笔记