New Post: In source code Core/ReferenceHelper.cs and SeekErrorMemoryStream.cs are missing
Commented Unassigned: Date incorrectly read as Double [11860]
when trying to read attached file, the reader is incorrectly reading the first column's values (from row 4 down) as double. Instead it should be either string or datetime.
Any fix/workaround for this? We really like this tool but can't use without fixing this.
Thanks,
Stevo
Comments: ** Comment from web user: jaklithn **
Thanks for quick answer!
Excel file is enclosed. Second column holds dates having the value 2014-01-16 16:00:00
I use the following code:
public static void GetValues(TableItem table, string path, string sheetName, bool firstRowHoldsColumnNames = true)
{
using (var stream = File.Open(path, FileMode.Open, FileAccess.Read))
{
using (var excelReader = GetExcelDataReader(path, stream))
{
excelReader.IsFirstRowAsColumnNames = firstRowHoldsColumnNames;
var dataset = excelReader.AsDataSet();
foreach (DataRow row in dataset.Tables[sheetName].Rows)
{
var rowItem = new RowItem();
foreach (var value in row.ItemArray)
{
rowItem.Values.Add(value);
}
table.Rows.Add(rowItem);
}
}
}
}
private static IExcelDataReader GetExcelDataReader(string path, Stream stream)
{
var extension = GetExtension(path);
switch (extension)
{
case "xls":
return ExcelReaderFactory.CreateBinaryReader(stream);
case "xlsx":
return ExcelReaderFactory.CreateOpenXmlReader(stream);
default:
throw new Exception(string.Format("Extension='{0}' is not handled", extension));
}
}
private static string GetExtension(string path)
{
var extension = Path.GetExtension(path);
return extension == null ? null : extension.ToLower().Substring(1);
}
New Post: Remove formatting from file
New Post: Remove formatting from file
New Post: Remove formatting from file
Commented Unassigned: Date incorrectly read as Double [11860]
when trying to read attached file, the reader is incorrectly reading the first column's values (from row 4 down) as double. Instead it should be either string or datetime.
Any fix/workaround for this? We really like this tool but can't use without fixing this.
Thanks,
Stevo
Comments: ** Comment from web user: Ian1971 **
I tried with your spreadsheet and I got the value interpreted correctly as a date.
I hacked your code to be
```
public static void GetValues(DataSet dataset, string sheetName)
{
foreach (DataRow row in dataset.Tables[sheetName].Rows)
{
foreach (var value in row.ItemArray)
{
Console.WriteLine("{0}, {1}", value, value.GetType());
}
}
}
```
And I get the output
fbe83377-8474-4b3e-93ed-1c9ddafb5dcc, System.String
16/01/2014 16:00:00, System.DateTime
ÖvrigTjänstepension, System.String
etc
So, not sure what is going, unless it is something to with your locale.
Commented Unassigned: Date incorrectly read as Double [11860]
when trying to read attached file, the reader is incorrectly reading the first column's values (from row 4 down) as double. Instead it should be either string or datetime.
Any fix/workaround for this? We really like this tool but can't use without fixing this.
Thanks,
Stevo
Comments: ** Comment from web user: jaklithn **
Thanks for trying!
You are probably right in your assumption that the locale is the difference.
When I run the same code I get the following result:
fbe83377-8474-4b3e-93ed-1c9ddafb5dcc, System.String
1899-12-31 00:00:00, System.DateTime
ÖvrigTjänstepension, System.String
My Windows 7 is set to use Swedish Locale and Swedish Format and I use Excel 2013.
Does this mean ExcelDatareader can not be used in non-english environment?
I tried another wellknown .Net OpenSource Lib called Koogra found on http://koogra.sourceforge.net
I really wanted to use ExcelDatareader as it seems to be a more active project but on this matter I actually found Koogra to be more stable as it handles date columns without problem.
Commented Issue: Error reading binary (.xls) file [11538]
Trying to read a .xls file and I get this --> Error: Neither stream 'Workbook' nor 'Book' was found in file.
Stepping though the code while it was reading the file confirms the error message is technically right. There is a 'WORKBOOK' entry though.
At the bottom of the XlsRootDirectory.cs file, is a method FindEntry that does the finding. I just changed it to be case insensitive and it read the file ok.
From this:
if
(e.EntryName == EntryName)
To this:
if
(string.Compare(e.EntryName,
EntryName, true)
== 0)
Comments: ** Comment from web user: noodel1988 **
Could you put this fix in a new package on NuGet?
Release 17 januari 2013
Bugfix is done after this point.
Except for this bug, nice work!
New Post: Neither stream 'Workbook' nor 'Book' was found in file
@ petemunnings: the above Method does not work. I get compile error:
The type or namespace name 'ReadOption' could not be found (are you missing a using directive or an assembly reference?)
New Post: Neither stream 'Workbook' nor 'Book' was found in file
Commented Unassigned: Date incorrectly read as Double [11860]
when trying to read attached file, the reader is incorrectly reading the first column's values (from row 4 down) as double. Instead it should be either string or datetime.
Any fix/workaround for this? We really like this tool but can't use without fixing this.
Thanks,
Stevo
Comments: ** Comment from web user: Ian1971 **
ExcelDataReader should work in a non-english environment.
I tried changing my Windows to Swedish but it still worked ok.
If you have any spare time it would be great if you could download the latest source from the repository and run the test app. Then point it at your file. If it still shows the wrong date, then if you put a break point on ExcelOpenXmlReader.cs line 276 we should be able to see what is going on.
Cheers
Ian
New Post: Remove formatting from file
New Post: Examples? Direct cell access?
New Post: Examples? Direct cell access?
-
Use datasets but specify reader.IsFirstRowAsColumnNames = false so that the whole sheet is the contents of the dataset.
Then in your example for row 10 column 3 you would have ds.Tables[0].Rows[9][2] -
Use the IDataReader interface and step through until you get to row 10 then read the value for field 3
New Post: Remove formatting from file
New Post: Neither stream 'Workbook' nor 'Book' was found in file
The fix from mmleoni, however, solved the problem.
Commented Unassigned: Error loading file [11818]
xlDataSet = xlReader.AsDataSet();
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
The file appears to be valid, when I open the file in excel and save it again the same code works without a problem.
Comments: ** Comment from web user: saccoder **
I faced the same error so i included those 4 lines:
First:
```
if ((uint) m_offset >= bytes.Length)
return null;
```
Secound:
```
if ((uint)offset >= bytes.Length)
return null;
```
```
/// <summary>
/// Reads record under cursor and advances cursor position to next record
/// </summary>
/// <returns></returns>
[MethodImpl(MethodImplOptions.Synchronized)]
public XlsBiffRecord Read()
{
if ((uint) m_offset >= bytes.Length)
return null;
XlsBiffRecord rec = XlsBiffRecord.GetRecord(bytes, (uint)m_offset);
m_offset += rec.Size;
if (m_offset > m_size)
return null;
return rec;
}
/// <summary>
/// Reads record at specified offset, does not change cursor position
/// </summary>
/// <param name="offset"></param>
/// <returns></returns>
public XlsBiffRecord ReadAt(int offset)
{
if ((uint)offset >= bytes.Length)
return null;
XlsBiffRecord rec = XlsBiffRecord.GetRecord(bytes, (uint)offset);
if (m_offset + rec.Size > m_size)
return null;
return rec;
}
```
it temporaly solved the error...
New Post: wrong numbers
I formating numeric with 2 decimal and nothing
excel file:

dataset visualizer:

Commented Unassigned: Date incorrectly read as Double [11860]
when trying to read attached file, the reader is incorrectly reading the first column's values (from row 4 down) as double. Instead it should be either string or datetime.
Any fix/workaround for this? We really like this tool but can't use without fixing this.
Thanks,
Stevo
Comments: ** Comment from web user: jaklithn **
Thanks for your attention.
I tried your 2.1 source demo with Excel.4.5.dll and it parsed the Excel file OK.
I switched to Excel.dll and the demo app still parsed it OK.
I ran my application with the previously downloaded Excel.dll 2.1 and confirmed it still was wrong.
I then exchanged the Excel.dll 2.1 in my own application with the one generated by the source code and then my application also works!
My conclusion is that you have changed something related to the parsing without upgrading the version?
By the way: Why do provide different versions for Framework 2.0 and 4.5? Is there an advantage of using the Excel.4.5?