You can get datatable from Excel using OpenXML SDK, this is fastest way, then you have to get data from table and pull it in your entities (attributes) Found it on 'stackoverflow: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.IO; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Spreadsheet; // borrowed from this page: // http://stackoverflow.com/questions/3321082/from-excel-to-datatable-in-c-sharp-with-open-xml namespace OpenXMLConsoleCS { class Program { // use OpenXML SDK 2.0 or higher // Requires references: // DocumentFormat.OpenXml // WindowsBase //__________________________________________________________// /// /// Return System.Data.DataTable /// ///full path of Excel file ///sheet number zero based /// public static System.Data.DataTable GetDataTableFromSheet(string xlFilePath, int sheetnum) { System.Data.DataTable dt = new System.Data.DataTable(); using (SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(xlFilePath, false)) { WorkbookPart workbookPart = spreadSheetDocument.WorkbookPart; IEnumerable sheets = spreadSheetDocument.WorkbookPart.Workbook.GetFirstChild().Elements(); string relationshipId = sheets.ElementAt(sheetnum).Id.Value; WorksheetPart worksheetPart = (WorksheetPart)spreadSheetDocument.WorkbookPart.GetPartById(relationshipId); Worksheet workSheet = worksheetPart.Worksheet; SheetData sheetData = workSheet.GetFirstChild(); IEnumerable rows = sheetData.Descendants(); foreach (Cell cell in rows.ElementAt(0)) { dt.Columns.Add(GetCellValue(spreadSheetDocument, cell)); } foreach (Row row in rows) { System.Data.DataRow tempRow = dt.NewRow(); for (int i = 0; i < row.Descendants().Count(); i++) { tempRow[i] = GetCellValue(spreadSheetDocument, row.Descendants().ElementAt(i)); } dt.Rows.Add(tempRow); } } return dt; } public static string GetCellValue(SpreadsheetDocument document, Cell cell) { SharedStringTablePart stringTablePart = document.WorkbookPart.SharedStringTablePart; string value = cell.CellValue.InnerXml; if (cell.DataType != null && cell.DataType.Value == CellValues.SharedString) { return stringTablePart.SharedStringTable.ChildElements[Int32.Parse(value)].InnerText; } else { return value; } } //______________________________________________________________________________________// static void Main(string[] args) { string filename = @"C:\Test\XlPoints.xlsx";// filename int num = 0;// Sheet1 if (!File.Exists(filename)) { Console.WriteLine("\nFile:\t{0} does not exists, Exit.", filename); Console.Read(); return; } System.Data.DataTable dt = GetDataTableFromSheet(filename, num); int c = 0; foreach (System.Data.DataRow dr in dt.Rows) { object[] line = dr.ItemArray; c++; for (int r = 0; r < line.Length; r++) Console.WriteLine(line[r].ToString()); } Console.WriteLine("\tLast Row:\t{0}", c.ToString()); Console.Read(); } } }
_____________________________________
C6309D9E0751D165D0934D0621DFF27919