I was not able to reproduce the issue using the code below and the
file that you sent me. It loops the expected number of times and
outputs the values I would expect. I'm not sure how you're telling
that it jumps to record 36 on the particular line that you're
identifying because the released hours for record 1, per num 2000067,
is the same as record 36, per num 2086571, which both have 37.5. The
reason why I was interested in how it came up in the grid is that all
ways of accessing data using the XlsReader loads the entire file into
memory, it's just a nasty fact with Excel spreadsheets. ReadRecord is
basically just a very simple current record variable incrementer, so
it would be very odd for it to suddenly jump to 36. If the data loads
correctly into the grid, to me that means that the reader does know
the correct number of records, which would have been my other concern
if it internally only loaded a couple of the records. I have a
suspicion that you're looking at what data ends up in the database
instead of what data is actually being read. Try running the code
below and see if you see what I see with no obvious issue. Then, try
debugging your code stepping it line by line and putting watches on
the reader values to see if it actually is jumping to record 36. If
you do still see the issue, let me know what assembly version you're
using and maybe I can reproduce it on a particular version, although I
tried several. I'm also using the 2.0 built assembly in 2.0.
using System;
using System.Collections.Generic;
using System.Text;
using DataStreams.Xls;
namespace XlsSkippingRecordsTest
{
class Program
{
static void Main(string[] args)
{
using (XlsReader xlsData = new XlsReader("../../
WPSPreCheck080715.XLS"))
{
string[] cHeader;
int HeadCount = 0;
int Flag = 0;
int errFlag = 0;
DateTime myDate;
xlsData.Settings.HasHeaders = true;
cHeader = xlsData.Headers;
for (int i = 0; i < cHeader.Length; i++)
{
if (cHeader[i] != "")
HeadCount += 1;
}
Console.WriteLine("header count: " + HeadCount);
if (HeadCount == 18)
{
Flag = 0;
for (int i = 0; i < cHeader.Length; i++)
{
if (cHeader[i].ToUpper() == "ORG.NUM.")
Flag += 1;
if (cHeader[i].ToUpper() == "EMPLOYEE NAME")
Flag += 1;
if (cHeader[i].ToUpper() == "E")
Flag += 1;
if (cHeader[i].ToUpper() == "PER.NUM.")
Flag += 1;
if (cHeader[i].ToUpper() == "REJECTED HS.")
Flag += 1;
if (cHeader[i].ToUpper() == "CATS ABSEN.")
Flag += 1;
if (cHeader[i].ToUpper() == "PERS.FROM")
Flag += 1;
} // end for
if (Flag != 7)
errFlag = 1;
else
errFlag = 0;
if (Flag == 7 && errFlag == 0)
{
//Process File for import
while (xlsData.ReadRecord())
{
myDate =
Convert.ToDateTime(xlsData["Pers.From"]);
Console.WriteLine("mydate: " +
myDate.ToString());
Console.WriteLine("per num: " +
Convert.ToInt32(xlsData["Per.Num."]).ToString());
Console.WriteLine("org num: " +
Convert.ToInt32(xlsData["Org.Num."]).ToString()); //(Record 1 here)
Console.WriteLine("employee name: " +
xlsData["Employee Name"]); //(Record 1 here)
Console.WriteLine("per num: " +
Convert.ToInt32(xlsData["Per.Num."]).ToString()); // (Record 1 here)
Console.WriteLine("released hs: " +
xlsData["Released Hs."]);
if (xlsData["Released Hs."] != "") //(Now
at record 36)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false");
}
} // end while (xlsData.ReadRecord())
} // end if
} // end if (HeadCount == 18)
} // end using (xlsData)
} // end Main
} // end class
} // end namespace
Bruce Dunwiddie
> > - Show quoted text -- Hide quoted text -