public static void Temp1() { Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\ImportLotTemplate.xlsx"); Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Excel.Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; List <ImportLotData> data = new List <ImportLotData>(); for (int i = 2; i <= rowCount; i++) { ImportLotData lotData = new ImportLotData(); double date = double.Parse(xlRange.Cells[i, 1].Value2().ToString()); lotData.LotDate = DateTime.FromOADate(date); lotData.ProductName = xlRange.Cells[i, 2].Value2().ToString(); lotData.LotNumber = xlRange.Cells[i, 3].Value2().ToString(); lotData.Rank = xlRange.Cells[i, 4].Value2().ToString(); lotData.Quantity = int.Parse(xlRange.Cells[i, 5].Value2().ToString()); lotData.UnitCost = double.Parse(xlRange.Cells[i, 6].Value2().ToString()); lotData.PoNumber = xlRange.Cells[i, 7].Value2().ToString(); data.Add(lotData); } Console.WriteLine("Data:"); foreach (var item in data) { Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t", item.LotDate, item.ProductName, item.ProductName, item.LotNumber, item.Rank , item.Quantity, item.UnitCost, item.PoNumber); } Console.WriteLine("Done"); Console.ReadKey(); GC.Collect(); GC.WaitForPendingFinalizers(); Marshal.ReleaseComObject(xlRange); Marshal.ReleaseComObject(xlWorksheet); xlWorkbook.Close(); Marshal.ReleaseComObject(xlWorkbook); //quit and release xlApp.Quit(); Marshal.ReleaseComObject(xlApp); }
public LotCheckinResponse(bool success, string message, ImportLotData lotData) { this.Success = success; this.Message = message; this.LotData = lotData; }