codeice / linqtoexcel

Automatically exported from code.google.com/p/linqtoexcel
0 stars 0 forks source link

Unable to cast object of type #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Use the attached to create a new project and click Debug. When I used your
original source and excel file, it worked perfectly. Changing the filename
(even after copying to local directory), class name and class definition
resulted in the summary error.

Original issue reported on code.google.com by mhc...@yahoo.com on 16 Feb 2010 at 7:25

Attachments:

GoogleCodeExporter commented 9 years ago
I took a look at your solution and the problem seems to be in your spreadsheet. 
The 
LinqToExcel library expects all the data in the spreadsheet to be in a table, 
but at 
the bottom of your spreadsheet you have data that's not in the table (e.g. 
SpikeChain 
= 56, Rapier = 57, etc)

There are 2 ways to solve this problem. 1) Delete the data at the bottom of the 
spreadsheet or 2) tell LinqToExcel to only retrieve the first 27 rows from the 
spreadsheet. Below is a code example of how to do so.

Dim users = (From x In book.Worksheet(Of Weapon)("Weapons") _
             Select x).Take(27)

For Each u In users
     Console.WriteLine(u.Weapon + " " + u.Cost.ToString + " " + u.Coin)
Next

I would suggest the first option.

Let me know if you have any more questions,
Paul

Original comment by paulyo...@gmail.com on 17 Feb 2010 at 2:32