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

  • 相关阅读:
    周记
    周记
    代码复审核查表
    两人合作的案例and周记
    第一周周记
    15 手写数字识别-小数据集(2)
    11.分类与监督学习,朴素贝叶斯分类算法
    15 手写数字识别-小数据集
    14 深度学习-卷积
    十二次作业
  • 原文地址:https://www.cnblogs.com/ahua1188/p/5364040.html
Copyright © 2011-2022 走看看