zoukankan      html  css  js  c++  java
  • 使用NPO写excel文件

    写excel文件

            /// <summary>
            /// Use NPO to write a datatable to the excel file
            /// </summary>
            /// <param name="tmpDataTable"></param>
            /// <param name="strFileName"></param>
            private static void DataTabletoExcel(DataTable dataTable, string strFileName)
            {
                XSSFWorkbook workbook = new XSSFWorkbook();
                ISheet sheet = workbook.CreateSheet("Sheet1");
                int index = 0;
                IRow titleRow = sheet.CreateRow(index++);
                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    titleRow.CreateCell(i).SetCellValue(dataTable.Columns[i].ColumnName);
                }
                foreach (DataRow dr in dataTable.Rows)
                {
                    IRow row = sheet.CreateRow(index++);
                    for (int i = 0; i < dataTable.Columns.Count; i++)
                    {
                        row.CreateCell(i).SetCellValue(dr[i].ToString());
                    }
                }

                FileStream fileStream = new FileStream(strFileName, FileMode.Create);
                workbook.Write(fileStream);
                fileStream.Close();
                workbook = null;
            }

  • 相关阅读:
    mac下编写命令脚本
    mac环境mongodb安装小坑
    JS
    设计模式:装饰器
    proxy 数据帧听
    react hook 简单实现
    报错:java.lang.NumberFormatException: null
    git回滚到指定版本
    1109. 航班预订统计 力扣(中等) 差分数组 不会但神奇
    528. 按权重随机选择 力扣(中等) 前缀和rand()
  • 原文地址:https://www.cnblogs.com/ahua1188/p/5364040.html
Copyright © 2011-2022 走看看