Reputation: 7766
I am importing an excel sheet through a mvc website using linq statement as below
var members = (from memRec in excelFile.Worksheet(sheetName)
where memRec["FIRST_NAME"] != null
select memRec).ToList();
foreach (var member in members)
{
//save data
}
The problem here is let say a particular column "Date Of Birth" for first 2 columns the cell format is "DATE" and display as dd/MM/yyyy
and 3rd column the cell format is "Text" and display as dd/MM/yyyy
the excel will consider it as no value there for 3rd column because of format mismatch.
Is there any way to solve this.
Upvotes: 0
Views: 655
Reputation: 7766
I found a solution.
In our server it is Office 2010.
Change the registry entry as below
Now the excel wont guess the row datatype since we changed the value from 8 to 0.
Upvotes: 0
Reputation: 2774
Try declare object and use predefined data types, Like:
var q = from memRec in excelFile.Worksheet(sheetName)
where memRec["FIRST_NAME"] != null
select new Person()
{
Date = (DateTime)memRec [“Date”],
FirstName= (string)memRec [“FirstName”],
Age= (int)memRec [“Age”],
};
Upvotes: 0