Closed GoogleCodeExporter closed 8 years ago
FYI, I have developed my own solution for a client that has numerous DateTime
fields
in a couple Excel spreadsheets. Rather than bog you down with the details of
that
work, I decided to see if the same issue could be found in your example.
Because it
is, I decided to use that to get an answer. Thanks.
Original comment by nosnibor...@gmail.com
on 1 Mar 2010 at 10:54
If you need the fix in a hurry you can use the following statement.
var allUsers = (from x in excel.Worksheet(Of User)()
select x).ToList();
var seventyEightUsers = from x in allUsers
Where x.Birthday.Year = 1978
select x;
This fix first selects all the users from the spreadsheet and adds them to an
in-
memory list. Then it queries the in-memory list for users born in the year
1978.
Original comment by paulyo...@gmail.com
on 1 Mar 2010 at 11:00
That works like a charm! Thanks! This now give me the ability to order the
results
instead of having to do that after I select from the speadsheet. The only
drawback I
suppose is having these large lists in memory (some are 5K rows). However, this
application is only a POC used by a handful of users, so I think I can get away
with
it for now.
Just curious, is this issue a bug? Do you plan to fix it? I realize you have
limited time and resources so it may fall on the back burner. Thanks for a
great
piece of code! It saved me from having to write some pretty nasty parsing code.
Original comment by nosnibor...@gmail.com
on 1 Mar 2010 at 11:33
The issue is caused by using the "Year" property on the BirthDay DateTime
object.
LinqToExcel isn't designed to use sub properties of objects (e.g.
Birthday.Year) and
it is too big of an enhancement to add.
Now with that being said, I have figured out a better solution that will meet
your
needs and only bring back users with birthdays in the year 1978.
var seventyEithUsers = from x in excel.Worksheet(Of User)()
where x.Birthday >= new DateTime(1978, 1, 1) &&
x.Birthday <= new DateTime(1978, 12, 31)
select x;
This solution will keep you from having an in memory list of 5K rows.
Let me know if this solution works for you.
Original comment by paulyo...@gmail.com
on 2 Mar 2010 at 1:24
Thanks Paul, your reworked solution works great. This way I can limit the
number of
records on the query rather than having to bring everything into memory. Yeah,
I too
think that is a big enhancement to add, especially when there is a
workaround... one
just has to think differently about querying dates ranges. Thank you for all
your help.
Original comment by nosnibor...@gmail.com
on 2 Mar 2010 at 2:26
Original comment by paulyo...@gmail.com
on 2 Mar 2010 at 3:28
Original issue reported on code.google.com by
nosnibor...@gmail.com
on 1 Mar 2010 at 10:47