Beispiel #1
0
 public void ToDataTableShouldSetNamespace()
 {
     using (var package = new ExcelPackage())
     {
         var sheet = package.Workbook.Worksheets.Add("test");
         sheet.Cells["A1"].Value = "Id";
         sheet.Cells["B1"].Value = "Name";
         sheet.Cells["A2"].Value = 1;
         sheet.Cells["B2"].Value = "John Doe";
         var options = ToDataTableOptions.Create(o =>
         {
             o.DataTableNamespace = "ns1";
         });
         var dt = sheet.Cells["A1:B2"].ToDataTable(options);
         Assert.AreEqual("ns1", dt.Namespace);
     }
 }
Beispiel #2
0
 public void ToDataTableShouldHandleDateTimeWithMapping()
 {
     using (var package = new ExcelPackage())
     {
         var date  = DateTime.UtcNow;
         var sheet = package.Workbook.Worksheets.Add("test");
         sheet.Cells["A1"].Value = "Id";
         sheet.Cells["B1"].Value = "Date";
         sheet.Cells["A2"].Value = 1;
         sheet.Cells["B2"].Value = date;
         var options = ToDataTableOptions.Create(o =>
         {
             o.Mappings.Add(1, "MyDate", typeof(DateTime));
         });
         var dt = sheet.Cells["A1:B2"].ToDataTable(options);
         Assert.AreEqual(1, dt.Rows.Count);
         Assert.AreEqual(1, dt.Rows[0]["Id"]);
         Assert.AreEqual(date.ToOADate(), ((DateTime)dt.Rows[0]["MyDate"]).ToOADate());
     }
 }
Beispiel #3
0
 public void ToDataTableShouldHandleTransform()
 {
     using (var package = new ExcelPackage())
     {
         var date  = DateTime.UtcNow;
         var sheet = package.Workbook.Worksheets.Add("test");
         sheet.Cells["A1"].Value = "Id";
         sheet.Cells["B1"].Value = "Date";
         sheet.Cells["A2"].Value = 1;
         sheet.Cells["B2"].Value = date;
         var options = ToDataTableOptions.Create(o =>
         {
             o.Mappings.Add(0, "Id", typeof(string), true, c => "Id: " + c.ToString());
         });
         var dt = sheet.Cells["A1:B2"].ToDataTable(options);
         Assert.AreEqual(1, dt.Rows.Count);
         Assert.AreEqual("Id: 1", dt.Rows[0]["Id"]);
         Assert.AreEqual(date, dt.Rows[0]["Date"]);
     }
 }
Beispiel #4
0
        public DataTable ToDataTable(ToDataTableOptions options, DataTable dataTable)
        {
            var func = new ToDataTable(options, this);

            return(func.Execute(dataTable));
        }
Beispiel #5
0
 /// <summary>
 /// Exports the table to a <see cref="System.Data.DataTable"/>
 /// </summary>
 /// <returns>A <see cref="System.Data.DataTable"/> containing the data in the table range</returns>
 /// <seealso cref="ExcelRangeBase.ToDataTable(ToDataTableOptions)"/>
 public DataTable ToDataTable(ToDataTableOptions options)
 {
     return(Range.ToDataTable(options));
 }