using (table)
            {
                IWorkbook workbook = new HSSFWorkbook();
                ISheet sheet = workbook.CreateSheet();
                IRow headerRow = sheet.CreateRow(0);
                // handling header.  
                foreach (DataColumn column in table.Columns)
                    headerRow.CreateCell(column.Ordinal).SetCellValue(column.Caption);//If Caption not set, returns the ColumnName value  
                                                                                      // handling value.  
                int rowIndex = 1;
                foreach (DataRow row in table.Rows)
                {
                    IRow dataRow = sheet.CreateRow(rowIndex);
                    foreach (DataColumn column in table.Columns)
                    {
                        dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString());

                    }
                    rowIndex++;
                }

                workbook.Write(ms);
                FileStream file = new FileStream("E://原始动态.xls", FileMode.Create);
                workbook.Write(file);
                file.Close();
                workbook = null;
                ms.Flush();
                ms.Position = 0;
            }

 

相关文章:

  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2021-05-25
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-21
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案