Пример #1
0
        /*
         * public static String Get_Data(String TestCase, String ColumnHeader)
         * {
         *
         *
         * LinkedHashMap<String, String> TC = (LinkedHashMap<String, String>)TestData.get(TestCase);
         *
         *  try
         *  {
         *
         *      return TC.get(ColumnHeader);
         *  }
         *  catch (Exception e)
         *  {
         *      return "null";
         *  }
         *
         * }*/

        /// <summary>
        /// Reading all the datas from Excelsheet
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static DataTable ExcelToDataTable(string fileName)
        {
            using (var stream = File.Open(fileName, FileMode.Open, FileAccess.Read))
            {
                using (var reader = ExcelReaderFactory.CreateReader(stream))
                {
                    var result = reader.AsDataSet(new ExcelDataSetConfiguration()
                    {
                        ConfigureDataTable = (data) => new ExcelDataTableConfiguration()
                        {
                            UseHeaderRow = true
                        }
                    });

                    //Get all the Tables
                    DataTableCollection table = result.Tables;


                    System.Diagnostics.Debug.WriteLine("table : " + table.ToString());
                    //Store it in DataTable
                    DataTable resultTable = table["Sheet1"];

                    //return
                    return(resultTable);
                }
            }
        }
Пример #2
0
        public void ToStringTest()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add("Table1");
            tbcol.Add("Table2");
            tbcol.Add("Table3");
            Assert.Equal("System.Data.DataTableCollection", tbcol.ToString());
        }