打开或创建文件

            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);

  

最新文章

  1. 浏览器的兼容模式下的button中文字垂直方向不居中显示
  2. 在UPDATE中更新TOP条数据以及UPDATE更新中使用ORDER BY
  3. vim 标签命令
  4. [转]CentOS下安装伪分布式Hadoop-1.2.1
  5. mongodb 最佳实践
  6. 23、获取app所占据的内存
  7. [转]“WARNING: soft rlimits too low” in MongoDB with Mac OS X
  8. js、expression表达式解析
  9. <转>详解DNS的常用记录(上):DNS系列之二
  10. 「Githug」Git 游戏通关流程
  11. C语言初学 求100到200的全部素数
  12. top 查看资源使用
  13. Java-byte[]与16进制字符串互转
  14. C# 自定义样式实现菜单和工具栏的分割线
  15. Vue项目模板--和--webpack自动化构建工具的---项目打包压缩使用
  16. UNIX环境高级编程——system V信号量
  17. Cocos Creator JS 获取当前日期与时间
  18. WebStorm Goland PyCharm 等JetBrains验证服务器
  19. 5-5 re模块 正则表达式
  20. UVa 11988 Broken Keyboard(数组模拟链表)

热门文章

  1. instanceof关键字
  2. Access denied for user 'Administrator'@'localhost' (using password: YES)
  3. leetcode-【中等题】2. Add Two Numbers
  4. Mbps、Kbps、bps、MB、KB
  5. 全站 HTTPS 来了(转载)
  6. jq封装的tab切换
  7. mysql日志开启和查看
  8. ios10 no route to host
  9. 编译FFmpeg成一个SO库<转>
  10. JCL笔记