public class Customer { public string FirstName { get; set; } public string LastName { get; set; } public Count Count { get; set; } private int monCompte; public int MonCompte { set { monCompte = value; Count = new Count { Number = monCompte, Property1 = "test" }; } get { return monCompte; } } public static Customer[] LireFichier(string Filename) { ExcelQueryFactory excelFile = new ExcelQueryFactory(Filename); excelFile.AddMapping<Customer>(x => x.MonCompte, "Number"); return (from x in excelFile.Worksheet<Customer>("Feuil1") select x).ToArray(); } }
/// <summary> /// Transforms a cell value in the spreadsheet to the desired property value /// </summary> /// <typeparam name="TSheetData">Class type to return row data as</typeparam> /// <param name="property">Class property value to transform</param> /// <param name="transformation">Lambda expression that transforms the original string value to the desired property value</param> /// <example> /// AddTransformation{Person}(p => p.IsActive, x => x == "Y"); /// AddTransformation{Person}(p => p.IsYoung, x => DateTime.Parse(x) > new DateTime(2000, 1, 1)); /// </example>
public string FirstName { get; set; } public string LastName { get; set; } public Count Count { get; set; } public static Customer[] LireFichier(string Filename) { ExcelQueryFactory excelFile = new ExcelQueryFactory(Filename); excelFile.AddMapping<Customer>(x => x.Count, "Number",y => new Count { Number = Convert.ToInt32(y) }); return (from x in excelFile.Worksheet<Customer>("Feuil1") select x).ToArray(); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionexcelFile.AddMapping<Customer>(x => x.Count, "Number",y => new Count { Number = Convert.ToInt32(y) }); excelFile.AddMapping<Customer>(x => x.Count.Property1, "Property1");
public class Customer { public string FirstName { get; set; } public string LastName { get; set; } public Count Count { get; set; } public static Customer[] LireFichier(string Filename) { ExcelQueryFactory excelFile = new ExcelQueryFactory(Filename); excelFile.AddMapping<Customer>(x => x.Count, "Number",y => new Count { Number = Convert.ToInt32(y) }); return (from x in excelFile.Worksheet<ImportCustomer>("Feuil1") select x.SetProperty1()).ToArray(); } } class ImportCustomer:Customer { private string property1; public string Property1 { get { return property1; } set { property1 = value; } } public Customer SetProperty1() { this.Count.Property1 = this.Property1; return (Customer)this; } }