Pascal Gineste
GFI Informatique
04 76 61 30 29
Envoyé : jeudi 31 octobre 2013 11:03
À : Gineste Pascal
Objet : Re: Try to compile v2.1 (82323) or v2.01 (27264) failed [ExcelDataReader:464093]
From: Ian1971
I quite happily use 4.0
From: Ian1971
BTW, I backed up to v 2.0.1 and get past the CreateBinaryReader problem. This works both with the MemoryStream or if I use my HttpPostedFile's InputStream directly.
So, a little mess-up in v 2.1 I guess?
Anyway, I think this will be enough to allow me to press on trying to use the DataReader.
Yes, 2.1 added support for more variants of xls (following the spec), but some of these require being able to jump around in the file. This should be revisited to see if it can retain support and not break non-seekable streams
Hi,
I believe I have the same issue. When I try to run the following with the attached XLS file:
```
using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
IExcelDataReader excelReader = null;
if (importExportDefinition.ImportExportFormat == ImportExportFormat.XLSX)
{
excelReader = ExcelReaderFactory.CreateOpenXmlReader(fileStream);
}
else if (importExportDefinition.ImportExportFormat == ImportExportFormat.XLS)
{
excelReader = ExcelReaderFactory.CreateBinaryReader(fileStream);
}
```
I get this error:
```
System.ArgumentOutOfRangeException occurred
HResult=-2146233086
Message=Non-negative number required.
Parameter name: count
Source=mscorlib
ParamName=count
StackTrace:
at System.Text.EncodingNLS.GetString(Byte[] bytes, Int32 index, Int32 count)
at Excel.Core.BinaryFormat.XlsBiffSST.ReadStrings()
at Excel.ExcelBinaryReader.readWorkBookGlobals()
at Excel.ExcelBinaryReader.Initialize(Stream fileStream)
at Excel.ExcelReaderFactory.CreateBinaryReader(Stream fileStream)
at Readysell.Module.BusinessLogic.ImportExport.ImportExportHelper.ImportFile(UnitOfWork unitOfWork, ImportExportDefinition importExportDefinition, String fileName) in c:\Users\Adam\Documents\Visual Studio 2013\Projects\Readysell.beta\Readysell.Module\BusinessLogic\ImportExport\ImportExportHelper.cs:line 249
InnerException:
```
var dt = DateTime.Parse("9/8/2013");
Double d = dt.ToOADate();
Console.WriteLine(d);
Console.WriteLine(DateTime.FromOADate(d));
// output from exceldata reader
Console.WriteLine(DateTime.FromOADate(40056));
}I'm not sure it's quite that simple. I don't think Excel dates have the same base as most everyone else. You might want to take a look at this:
http://www.cpearson.com/excel/datetime.htm
Wow .. thanks for that, i was wondering what is going wrong here. So is there any way to detect in data reader whether we should use the 1904 date mode or the 1900 date mode to recalculate the date?
As if we just use the default way we are always going to have a 4 year difference with these files.
I don't have to do anything with the dates. I get date strings out of the following snippet:
using (FileStream streamIn = File.Open(_PathFilename, FileMode.Open, FileAccess.Read))
using (IExcelDataReader execlReader = (Path.GetExtension(_PathFilename) == ".xlsx" ? ExcelReaderFactory.CreateOpenXmlReader(streamIn): ExcelReaderFactory.CreateBinaryReader(streamIn)))
{
DataSet ds = new DataSet();
ds = execlReader.AsDataSet();
foreach (DataTable sheet in ds.Tables)
{
foreach (DataRow Row in sheet.Rows)
{
var x = Row.ItemArray
.
.
.
Any developers taken a look at this?
This is a completely legit excel file that is not being read properly. I have about 5% of excel files in my product throwing this error. It will be great if this bug can be fixed!