Quantcast
Channel: Excel Data Reader - Read Excel files in .NET
Viewing all 448 articles
Browse latest View live

New Post: Default name for columns with no name

$
0
0
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.

New Post: How to import Image from Excel sheet

$
0
0

I don't think that is supported but you might be able extend the code if you get the source.

Commented Unassigned: Default name for columns with no name [12857]

$
0
0
I have a .xlsx file where only some of the columns in row 1 has names. The columns with no name is automatically named 'Column?' (This is both Caption and ColumnName).
I have previously used Excel by opening as a database via oledb and where these columns were automatically named 'F?'. No I have a backward compatibility problem because of this.
This is giving me problems as I do not feel I can just rename Column? to F? because I cannot seem to differentiate between a column actually named Column2 and one which was internally named Column2 because no name is specified in the spreadsheet.

So basically I have two questions;
1. Is is possible to change the default behavior of this auto naming of columns with no name? Basically exchange 'Column' with 'F'
2. Or is possible to tell if column didn't actually have a name (was blank). Then I can write the logic myself.

Thanks in advance :)

Ok, after reading the documentation I created a patch with the id; 16126. Hopefully it will accepted as my issue is now resolved by it.

REVIEW patch and apply if appropriate
Comments: ** Comment from web user: bleze **

It turns out that this patch is not enough to get the correct behavior.

The column index starts at 0 and I need it to start at 1.

I've found 3 places in the code where the column name is handled;

Helpers.AddColumnHandleDuplicate(table, string.Concat(COLUMN, i));

I've added a backward compatible bool setting for changing this index behavior. Attached is rev. 2 of the patch.

New Post: Read column values with Excel Data Reader not working (MVC)

$
0
0
My Excelsheet looks like this:

http://cdn.imghack.se/images/cdc24215d3d5079628a58878520c3028.png


Here is the part of my method that matters:
[HttpPost]
    public ActionResult ShowExcelFile(GetExcel model)
    {
        DataSet result = null;
            var file = model.Files[0];
            if (file != null && file.ContentLength > 0)
            {
                // .xlsx
                IExcelDataReader reader = ExcelReaderFactory.CreateOpenXmlReader(file.InputStream);

                // .xls
                //IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(file.InputStream);

                reader.IsFirstRowAsColumnNames = true; // if your first row contains column names
                result = reader.AsDataSet();
                reader.Close();
            }

            for (int i = 1; i < result.Tables[0].Rows.Count; i++)
            {
                DataRow data = result.Tables[0].Rows[i];
                System.Diagnostics.Debug.Write(data.Table.Rows[i]["Amortization"]);
            }
        return View("ShowExcelFile");
        }
System.Diagnostics.Debug.Write gives me no output, like "Amortization" doesn't exist.

My model:
public class GetExcel
    {
        public List<HttpPostedFileBase> Files { get; set; }

        public GetExcel()
        {
            Files = new List<HttpPostedFileBase>();
        }
    }
My HTML:
@using (Html.BeginForm("ShowExcelFile", "ShowExcel", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            @Html.TextBoxFor(m => m.Files, new { type = "file", name = "Files" })<br />
            <input type="submit" value="Upload file" />
        }
But when I use this Excelsheet:

http://cdn.imghack.se/images/1fd5dab2a891c3adda8cd33114ef07c1.png

It works fine and I get all values from column "Amortization" in output. Both files are .xlsx

Can anyone help me with this?

Created Unassigned: No data is available for encoding [12874]

$
0
0
Hi All,

this is one of the most useful libs i ever found and use. I have a problem with one Excel doc. I get Exception:

No data is available for encoding 5951.

What is wrong. No other problems so far.

I'm sending you the file in attachment

Commented Unassigned: No data is available for encoding [12874]

$
0
0
Hi All,

this is one of the most useful libs i ever found and use. I have a problem with one Excel doc. I get Exception:

No data is available for encoding 5951.

What is wrong. No other problems so far.

I'm sending you the file in attachment
Comments: ** Comment from web user: bvolkan **

I figured out what was the problem. The file was Workbook protected. Is there any chance to have something like:
ExcelReaderFactory.CreateBinaryReader(stream, "password");

in the future?

Thanks

Commented Issue: Reading Protected Excel file throws exception [2040]

$
0
0
Hi,
Our users will upload a protected excel (workbook and sheet) which we convert into stream and pass it to excel data reader.
I've got the below exception from ExcelDataReader.cs (Line : 139)
"No data is available for encoding 6236."
 
Pls let me know if there is any fix for reading protected excel.
 
Thanks
Kathiravan
Comments: ** Comment from web user: bvolkan **

This is the feature im looking also. Please add thos one.

Created Unassigned: unable to read an excel file [12876]

$
0
0
dear sir

i have an asp.net application that use the excel.dll to read the excel spread-sheet it works fine. however, today i encounter a file that looks fine but when the code read it, it cause exception.

the asp.net code looks like the following:

Dim iFileNameLeng As Integer = 0
Dim sFileNamePath As String
'Dim sFileNameONly As String
If (Not FileUpload1 Is Nothing) AndAlso (FileUpload1.HasFile) Then
sFileNamePath = FileUpload1.PostedFile.FileName
iFileNameLeng = InStr(1, StrReverse(sFileNamePath), "\")
'If iFileNameLeng > 0 Then
'FileUpload1.PostedFile.SaveAs("C:\yyyy.txt")
Dim bytes As Byte() = FileUpload1.FileBytes
Dim stream As MemoryStream = New MemoryStream(bytes)
Dim excelReader As IExcelDataReader
'If (sFileNamePath.IndexOf(".xlsx") > -1) OrElse (sFileNamePath.IndexOf(".xlsm") > -1) Then
If (sFileNamePath.IndexOf(".xlsx") > -1) Then
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream)
Else
excelReader = ExcelReaderFactory.CreateBinaryReader(stream)
End If
excelReader.IsFirstRowAsColumnNames = True
Dim ds As DataSet = excelReader.AsDataSet

While (excelReader.Read)
End While
excelReader.Close()

The exception happened in the ExcelReaderFactory.CreateBinaryReader,

The exception message text:

NotSupportedException was unhandled by user code
No data is available for encoding 24128

Commented Unassigned: unable to read an excel file [12876]

$
0
0
dear sir

i have an asp.net application that use the excel.dll to read the excel spread-sheet it works fine. however, today i encounter a file that looks fine but when the code read it, it cause exception.

the asp.net code looks like the following:

Dim iFileNameLeng As Integer = 0
Dim sFileNamePath As String
'Dim sFileNameONly As String
If (Not FileUpload1 Is Nothing) AndAlso (FileUpload1.HasFile) Then
sFileNamePath = FileUpload1.PostedFile.FileName
iFileNameLeng = InStr(1, StrReverse(sFileNamePath), "\")
'If iFileNameLeng > 0 Then
'FileUpload1.PostedFile.SaveAs("C:\yyyy.txt")
Dim bytes As Byte() = FileUpload1.FileBytes
Dim stream As MemoryStream = New MemoryStream(bytes)
Dim excelReader As IExcelDataReader
'If (sFileNamePath.IndexOf(".xlsx") > -1) OrElse (sFileNamePath.IndexOf(".xlsm") > -1) Then
If (sFileNamePath.IndexOf(".xlsx") > -1) Then
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream)
Else
excelReader = ExcelReaderFactory.CreateBinaryReader(stream)
End If
excelReader.IsFirstRowAsColumnNames = True
Dim ds As DataSet = excelReader.AsDataSet

While (excelReader.Read)
End While
excelReader.Close()

The exception happened in the ExcelReaderFactory.CreateBinaryReader,

The exception message text:

NotSupportedException was unhandled by user code
No data is available for encoding 24128
Comments: ** Comment from web user: bvolkan **

The file is protected. I have the same problem. There is no Unprotect method in this library.

New Post: Read column values with Excel Data Reader not working (MVC)

$
0
0
If you download the latest code. There is a test app, which will open any excel sheet you give it. Try both sheets with this and see if they work the same.

If they don't then either you could try stepping through the code to see where the difference is, or perhaps unzip the xlsx's and inspect the contents.
or you can upload copies of the files here in an issue, and I may be able to take a look at them at some point. However, I am extremely busy so I wouldn't be able to look at anything soon.

Commented Issue: Reading Protected Excel file throws exception [2040]

$
0
0
Hi,
Our users will upload a protected excel (workbook and sheet) which we convert into stream and pass it to excel data reader.
I've got the below exception from ExcelDataReader.cs (Line : 139)
"No data is available for encoding 6236."
 
Pls let me know if there is any fix for reading protected excel.
 
Thanks
Kathiravan
Comments: ** Comment from web user: Ian1971 **

There is no support currently for unprotect in this library. In our application we use other third-party libraries to unprotect spreadsheets before opening them with ExcelDataReader, such as SecureBlackBox (not cheap though).

Closed Issue: Reading Protected Excel file throws exception [2040]

$
0
0
Hi,
Our users will upload a protected excel (workbook and sheet) which we convert into stream and pass it to excel data reader.
I've got the below exception from ExcelDataReader.cs (Line : 139)
"No data is available for encoding 6236."
 
Pls let me know if there is any fix for reading protected excel.
 
Thanks
Kathiravan

Closed Unassigned: unable to read an excel file [12876]

$
0
0
dear sir

i have an asp.net application that use the excel.dll to read the excel spread-sheet it works fine. however, today i encounter a file that looks fine but when the code read it, it cause exception.

the asp.net code looks like the following:

Dim iFileNameLeng As Integer = 0
Dim sFileNamePath As String
'Dim sFileNameONly As String
If (Not FileUpload1 Is Nothing) AndAlso (FileUpload1.HasFile) Then
sFileNamePath = FileUpload1.PostedFile.FileName
iFileNameLeng = InStr(1, StrReverse(sFileNamePath), "\")
'If iFileNameLeng > 0 Then
'FileUpload1.PostedFile.SaveAs("C:\yyyy.txt")
Dim bytes As Byte() = FileUpload1.FileBytes
Dim stream As MemoryStream = New MemoryStream(bytes)
Dim excelReader As IExcelDataReader
'If (sFileNamePath.IndexOf(".xlsx") > -1) OrElse (sFileNamePath.IndexOf(".xlsm") > -1) Then
If (sFileNamePath.IndexOf(".xlsx") > -1) Then
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream)
Else
excelReader = ExcelReaderFactory.CreateBinaryReader(stream)
End If
excelReader.IsFirstRowAsColumnNames = True
Dim ds As DataSet = excelReader.AsDataSet

While (excelReader.Read)
End While
excelReader.Close()

The exception happened in the ExcelReaderFactory.CreateBinaryReader,

The exception message text:

NotSupportedException was unhandled by user code
No data is available for encoding 24128
Comments: There is no support currently for unprotect in this library. In our application we use other third-party libraries to unprotect spreadsheets before opening them with ExcelDataReader, such as SecureBlackBox (not cheap though).

Closed Unassigned: No data is available for encoding [12874]

$
0
0
Hi All,

this is one of the most useful libs i ever found and use. I have a problem with one Excel doc. I get Exception:

No data is available for encoding 5951.

What is wrong. No other problems so far.

I'm sending you the file in attachment
Comments: There is no support currently for unprotect in this library. In our application we use other third-party libraries to unprotect spreadsheets before opening them with ExcelDataReader, such as SecureBlackBox (not cheap though).

Commented Unassigned: Default name for columns with no name [12857]

$
0
0
I have a .xlsx file where only some of the columns in row 1 has names. The columns with no name is automatically named 'Column?' (This is both Caption and ColumnName).
I have previously used Excel by opening as a database via oledb and where these columns were automatically named 'F?'. No I have a backward compatibility problem because of this.
This is giving me problems as I do not feel I can just rename Column? to F? because I cannot seem to differentiate between a column actually named Column2 and one which was internally named Column2 because no name is specified in the spreadsheet.

So basically I have two questions;
1. Is is possible to change the default behavior of this auto naming of columns with no name? Basically exchange 'Column' with 'F'
2. Or is possible to tell if column didn't actually have a name (was blank). Then I can write the logic myself.

Thanks in advance :)

Ok, after reading the documentation I created a patch with the id; 16126. Hopefully it will accepted as my issue is now resolved by it.

REVIEW patch and apply if appropriate
Comments: ** Comment from web user: Ian1971 **

Thanks for this. I'll take a look at in in due course. Funnily enough I have a need for this coming up in next few months so timing is good.


Created Unassigned: OpenOffice Table Rows Count problem [12909]

$
0
0
Hi,

I have .xsl file created in Excel 2010. When loading the file with CreateBinaryReader i get all DataTables and rows within them. But when open that file in OpenOffice and Save it without any modifications and then load it again with CreateBinaryReader all DataTables created have one row less then the file created with Excel 2010.

What could be the problem?

Commented Unassigned: OpenOffice Table Rows Count problem [12909]

$
0
0
Hi,

I have .xsl file created in Excel 2010. When loading the file with CreateBinaryReader i get all DataTables and rows within them. But when open that file in OpenOffice and Save it without any modifications and then load it again with CreateBinaryReader all DataTables created have one row less then the file created with Excel 2010.

What could be the problem?
Comments: ** Comment from web user: bvolkan **

My mistake. The file are xlsx and OpenXmlReader was used. All the other conditions are the same.

Created Unassigned: XlsBiffRecord.ReadStrings does not handle all cases correctly [12931]

$
0
0
When a continuation breaks comes just before (or in?) the tail/postfix part of the XlsFormattedUnicodeString the ReadStrings method doesn't handle this case correctly.

You have to check if there are still chars to read.
int charsLeft = (int)(len - (last - prefix - offset) / (str.IsMultiByte ? 2 : 1));

If charsLeft >0 then the available code handles the case correctly.

If charsLeft == 0 then the available code still reads the current string but fails when reading the next string because the new offset is wrong.

When charsLeft == 0 the new offset should be
offset = contoffset + 4 + size - last + offset;
And the temp buffer
Buffer.BlockCopy(m_bytes, (int)contoffset + 4, buff, (int)(last - offset), (int)(size - last + offset));
There is no encoding byte?

This code addition worked in my case (xls file was too big to send as attachment).
After the changes all the strings were read correctly.

No errors are thrown when reading the SST.
No errors are thrown when getting strings out of the SST when the index exceeds the bounds of the array (empty string is returned).
So I only detected this issue when running queries on the migrated data (Excel to SQL).

I didn't test other cases, e.g. continuation breaks in the head/prefix part, because I don't know if this is even possible.

Created Unassigned: Multithreaded Read [12936]

$
0
0
There seems to be an issue in Excel/Log/LogManager.cs if you concurrently read from multiple different xlsx files.

I fixed the issue by moving the sync-lock to cover up ContainsKey-Check too

From

```
public static ILog Log(string objectName)
{
ILog result = null;

if (_dictionary.ContainsKey(objectName))
result = _dictionary[objectName];

if (result == null)
{
lock (_sync)
{
result = Excel.Log.Log.GetLoggerFor(objectName);
_dictionary.Add(objectName, result);
}
}

return result;
}
```

to

```
public static ILog Log(string objectName)
{
ILog result = null;

lock (_sync)
{
if (_dictionary.ContainsKey(objectName))
result = _dictionary[objectName];

if (result == null)
{
result = Excel.Log.Log.GetLoggerFor(objectName);
_dictionary.Add(objectName, result);
}
}

return result;
}
```

Reviewed: 2.1.2.0 (abr 16, 2014)

$
0
0
Rated 5 Stars (out of 5) - Very good, gread job brother! Thank you.
Viewing all 448 articles
Browse latest View live