Last post Mar 15, 2010 07:12 AM by firstname.lastname@example.org
Nov 12, 2009 11:40 PM|john.lam|LINK
I'm using C# to write functions to export some data into excel file and to import a processed excel file back to the database afterward. My probem is, there is a cell with data in the format of date string (e.g. 12/01/2009) where when I import the processed
excel file to the system, which returns with the error message Unable to cast object of type 'System.Double' to type 'System.String'.
How can I convert the format of the cell to text in C#?
Mar 12, 2010 10:30 AM|an0nimo|LINK
I'm having the same problem, have you figured this out already? In my case it doesn't have to be a date string, any number will throw an exception
Unable to cast object of type 'System.Double' to type 'System.String'. :(
Mar 12, 2010 11:34 AM|exuviae|LINK
You need to set IMEX=1 in your extended properties for the connection string if you are using oledb. I wrote a demo for a blog that does part of what you are talking about. It takes data from excel and maps it to entity framework objects and inserts/updates
the data. You can see my blog at http://techblog.chrisdupuy.com.
Mar 15, 2010 07:12 AMemail@example.com|LINK
Even I had same problem where I need to export date field into excel and date cell was formatted into number. I have converted the date field into number in C# and then exported to excel.
xlRange = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[1, 11];
string date=Convert.ToString(xlRange.text) //will convert the date cell to string