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

  • 相关阅读:
    初识Django-前后端不分离(一)
    虚拟环境的搭建
    python+request+Excel做接口自动化测试(二)
    使用postman+newman+python做接口自动化测试
    如何处理接口响应结果分析
    request使用的封装
    python中unittest的使用
    使用python的接口测试环境搭建及使用
    关于测试流程的指导心得
    Redis 学习
  • 原文地址:https://www.cnblogs.com/ahua1188/p/5364040.html
Copyright © 2011-2022 走看看