zoukankan      html  css  js  c++  java
  • NPOI 如何导出数字列

    Excel导出数字列,熬到两点半,从源码中才找到解决方案

    dynamic workbook = new HSSFWorkbook();        
    ICellStyle  cellStyle = workbook.CreateCellStyle();
    IDataFormat format = workbook.CreateDataFormat();
    cellStyle.DataFormat = format.GetFormat("0.00");
    cell.CellStyle = cellStyle;
    cell.SetCellType(CellType.Numeric);
    cell.SetCellValue(Convert.ToDouble(dt.Rows[j][cols[i]]));

      

    总结:多看看源码,看NPOI的源码,里面有实例

    注意:

      ① 这是2.1.3.1版本的用法,更高的版本命名类的命名规则不同,比如接口会带HSSF前缀,而不是I前缀

      ② cellStyle 在一个Excel中不能超过4K个,否则会报错,最好定义几个全局style,需要的时候赋值即可

          ③ 不过NPOI需要挨个单元格创建就真的有点变态了,好处是可以设置每个单元格的样式,

    NPOI源码地址:http://npoi.codeplex.com/SourceControl/latest

  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    深度学习笔记 (二) 在TensorFlow上训练一个多层卷积神经网络
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/guosier/p/5720184.html
Copyright © 2011-2022 走看看