I am using spreadsheetgear to read an existing Excel file and import the data into a SQL Server database. Everything works fine until I need to import a cell that is formatted as a date - "*3/14/2001". I am trying to import this field into a DateTime field in the database. Not sure how to go about doing this?
This is the import routine -
fileInformation.DateReleased = worksheet.Cells["B20"].Text;
fileInformation.DateRequired = worksheet.Cells["B21"].Text;
public DateTime DateReleased { get; set; }
public DateTime DateRequired { get; set; }
答案 0 :(得分:3)
Dates/times are stored in SpreadsheetGear (and Excel) as a double representing a date/time serial number. You can read more about these serial dates here if you want. The fact that they show up as a "date" in the cell is simply a function of the IRange.NumberFormat applied to the cell ("m/d/yyyy" etc). Your use of IRange.Text is returning the "formatted" value of the cell--as a string. To get an actual .NET DateTime value from a cell, you can use the IWorkbook.NumberToDateTime(...) helper method. Example:
for idx, item in enumerate(split_text):
if item == word:
split_text[idx] = ("*" * length)