HI i made the followin class to get dates from an excel file.
file:
col:a col:b col:c
1. X-mas 2015-19-12 2016-03-01
2. carnaval 2016-20-02 2016-28-02
- using System;
- using OfficeOpenXml;
- using System.IO;
-
-
- namespace CalviVsTribessCheck.Cmd
- {
- public static class ExcelFileDataAccess
- {
- public static void ReadExcelFile(DateTime start)
- {
- var filePath = @"c:\code\Tools\Development\RtcMonitoring\RatingTribessCheck.Cmd\Vacations.xlsx";
- var sheetName = "vacations";
- using (var excelPkg = new ExcelPackage())
- using (var stream = new FileStream(filePath, FileMode.Open))
- {
- excelPkg.Load(stream);
- ExcelWorksheet oSheet = excelPkg.Workbook.Worksheets[sheetName];
-
- var totalRows = oSheet.Dimension.End.Row;
-
- for (var i = 1; i <= totalRows; i++)
- {
-
- var vacationbegindate = DateTime.Parse((oSheet.Cells[i, 1]).Value.ToString());
- var vacationenddate = DateTime.Parse((oSheet.Cells[i, 2]).Value.ToString());
-
- BusinessLogic.CheckVacation(start, vacationbegindate, vacationenddate);
-
- }
- }
- }
-
-
-
-
-
-
-
-
- }
- }
however i get the following error when converting a cell value to a dateTime:
The string is not recognized as a valid DateTime. Index 0 begins with an unknown word
How can i fix this ???? please provide me with your answer