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

New Post: Import subset of Data from Excel

$
0
0
Hi,

I am new to this but I have been using the ExcelDataReader to upload an Excel Spreadsheet to a Database,

this has worked great for a spreadsheet with just one set of data in it but I have been asked to extend this to allow the import of data from a range within the spreadsheet, for example A3:K? Where the data could continue for any number of records.

Is this possible? or is there anything that you can suggest?

Thanks

Darren

Source code checked in, #87450

Closed Unassigned: Not work with ICSharpCode.SharpZipLib 0.86 [12561]

$
0
0
Subj, but in nuget discription writed that need SharpZipLib 0.86 or more. But by fact work only with 0.85.5 That cause many problem when use other assemblies, that work with 0.86
Comments: Resolved with changeset 87450: use sharpsziplib 0.86

Commented Unassigned: Not work with ICSharpCode.SharpZipLib 0.86 [12561]

$
0
0
Subj, but in nuget discription writed that need SharpZipLib 0.86 or more. But by fact work only with 0.85.5 That cause many problem when use other assemblies, that work with 0.86
Comments: ** Comment from web user: Ian1971 **

Nuget package has been update. Let me know if it works ok.

Commented Unassigned: Not work with ICSharpCode.SharpZipLib 0.86 [12561]

$
0
0
Subj, but in nuget discription writed that need SharpZipLib 0.86 or more. But by fact work only with 0.85.5 That cause many problem when use other assemblies, that work with 0.86
Comments: ** Comment from web user: vertigo093i **

@jabacrack, ExcelDataReader will use whatever version specified by redirects. It ever won't know about SharpZipLib being redirected.

@Ian, thanks, this is the only proper solution. ;-)

Commented Unassigned: Not work with ICSharpCode.SharpZipLib 0.86 [12561]

$
0
0
Subj, but in nuget discription writed that need SharpZipLib 0.86 or more. But by fact work only with 0.85.5 That cause many problem when use other assemblies, that work with 0.86
Comments: ** Comment from web user: jabacrack **

I do not remember exactly what the problem was, but there was some annoying libraries versions mismatching.
Thank you for your work.

Created Unassigned: XLS file issue: Object reference not set to an instance of an object [12820]

$
0
0
I am getting error "Object reference not set to an instance of an object" while try to read attached file.
Everything works fine after I open in excel and save. Just in case, I am getting this file in email attachment.

FileStream stream = File.Open(@"C:\1.xls", FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
excelReader.Close();

Commented Unassigned: System.Security.SecurityException in Windows Shared hosting [12540]

$
0
0
I have hosted my web application which uses Excel Data Reader in Hostgator shared hosting server. I am getting the foll. error. What needs to be done to fix it?

Locally in my dev box, everything works sweet.

Error details:

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.IO.Path.GetTempPath()
at Excel.Core.ZipWorker..ctor() in exceldatareader-82970\Excel\Core\ZipWorker.cs:line 69
at Excel.ExcelOpenXmlReader.Initialize(Stream fileStream) in exceldatareader-82970\Excel\ExcelOpenXmlReader.cs:line 313
at Excel.ExcelReaderFactory.CreateOpenXmlReader(Stream fileStream) in exceldatareader-82970\Excel\ExcelReaderFactory.cs:line 74
Comments: ** Comment from web user: ozomatzin84 **

I have the same problem, I try to read an Excel (xlsx) file but I get this error, just with the new version of the excel files (xlsx) with the old version (xls) I don't have any problem. how did you fix this error?


New Post: Getting null value against .xlsx file

$
0
0
I found the same issue, and it was solved for me by changing the Page's Culture and UICulture to 'en-US'; I was using a different culture (bn-BD), that seems to be cause of the issue.

New Post: Default name for columns with no name

$
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 :)

Reviewed: 2.1.2.0 (Mar 21, 2014)

$
0
0
Rated 5 Stars (out of 5) - Works perfectly. I created a little C# app for searching multiple excel files. At first I was using Excel's com to do this. It was very very slow. Switched over to using these DLLs and it's lightning fast now. THANKS! If anyone is looking to search multiple excel files at once, you can download my app from here: http://www.recipebookshare.com/PeteBuilds/index.htm

Created Unassigned: binary reader not returning all rows [12834]

$
0
0
Empty rows (with no cell) can lead to erroneous end of sheet detection.
Patch : ExcelBinaryReader.cs
Method : moveToNextRecordNoIndex()

Old code :
```
if (record.IsCell)
{
var candidateCell = record as XlsBiffBlankCell;
if (candidateCell != null)
{
if (candidateCell.RowIndex == m_currentRowRecord.RowIndex)
cell = candidateCell;
}
}

```

Patched code :

```
if (record.IsCell)
{
var candidateCell = record as XlsBiffBlankCell;
if (candidateCell != null)
{
// if (candidateCell.RowIndex == m_currentRowRecord.RowIndex) // [jerome.raffalli]
// in case of empty row no cell exists for this row, so we have to exit [jerome.raffalli]
if (candidateCell.RowIndex __>=__ m_currentRowRecord.RowIndex)
cell = candidateCell;
}
}

```

Jérôme

New Post: object reference not set to an instance of an object

$
0
0
Hi, I am facing issue with reading .xls and .xlsx file. It does work in my local machine. But, when published to QA box it throws the below error. Did anyone came across this issue ? I have pasted below the error stack trace for the reference.

My code :

FileOperation.FileStream stream = FileOperation.File.Open(path, FileOperation.FileMode.Open, FileOperation.FileAccess.ReadWrite);
        IExcelDataReader excelReader = null;

        if (fileType.FileExtension == "xls" && new List<string>() { "application/excel", "application/vnd.ms-excel", "application/x-excel", "application/x-msexcel" }.Contains(fileType.FileMimeType))
        {
            excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
        }
        else if (fileType.FileExtension == "xlsx" && fileType.FileMimeType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
        {
            excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
        }

        excelReader.IsFirstRowAsColumnNames = false;

        List<FeeScheduleLine> feeScheduleLines = new List<FeeScheduleLine>();

        while (excelReader.Read())
        {

        }
Thanks in advance.


<b>Stack Trace:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
           <tr>
              <td>
                  <code><pre>
[NullReferenceException: Object reference not set to an instance of an object.]
Emds.UI.Razor.Areas.Bill.Controllers.FeeScheduleController.ReadExcelFile(String path, FileType fileType) in e:\workspace\CreateDailyCode_PM_NavTest\MiddleTier\Razor\Emds.UI.Razor\Areas\Bill\Controllers\FeeScheduleController.cs:616
Emds.UI.Razor.Areas.Bill.Controllers.FeeScheduleController.UploadFile() in e:\workspace\CreateDailyCode_PM_NavTest\MiddleTier\Razor\Emds.UI.Razor\Areas\Bill\Controllers\FeeScheduleController.cs:470
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +214
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +253
System.Web.Mvc.&lt;&gt;c__DisplayClass17.&lt;InvokeActionMethodWithFilters&gt;b__14() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1 continuation) +253
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
System.Web.Mvc.Controller.ExecuteCore() +106
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
System.Web.Mvc.Async.<>c__DisplayClass81.&lt;BeginSynchronous&gt;b__7(IAsyncResult _) +10

System.Web.Mvc.Async.WrappedAsyncResult
1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9

System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514928

System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
</pre></code>
</td>
           </tr>
        </table>

        <br>

        <hr width=100% size=1 color=silver>

        <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446

        </font>

</body>
</html>
<!-- [NullReferenceException]: Object reference not set to an instance of an object. at Emds.UI.Razor.Areas.Bill.Controllers.FeeScheduleController.ReadExcelFile(String path, FileType fileType) in e:\workspace\CreateDailyCode_PM_NavTest\MiddleTier\Razor\Emds.UI.Razor\Areas\Bill\Controllers\FeeScheduleController.cs:line 616 at Emds.UI.Razor.Areas.Bill.Controllers.FeeScheduleController.UploadFile() in e:\workspace\CreateDailyCode_PM_NavTest\MiddleTier\Razor\Emds.UI.Razor\Areas\Bill\Controllers\FeeScheduleController.cs:line 470 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) at System.Web.Mvc.Controller.ExecuteCore() at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d() at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) --><!-- This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using &lt;customErrors mode="Off"/&gt;. Consider using &lt;customErrors mode="On"/&gt; or &lt;customErrors mode="RemoteOnly"/&gt; in production environments.-->

Commented Issue: IsFirstRowAsColumnNames not working correctly [8796]

$
0
0
I have the following code in my ASP.NET application:
 
using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(stream))
{
reader.IsFirstRowAsColumnNames = true;
 
while (reader.Read())
{
// Do stuff
}
}
}
but when I do the first read, it is attempting to read from the first row (which contains the column names), rather than taking the second row as the first row of actual data. Obviously, I can work around the issue by adding an extra reader.Read() before reading the actual data, but it would be much better if the IExcelDataReader would do it internally if IsFirstRowAsColumnNames is set.
Comments: ** Comment from web user: ravik **

For me, even .XLSX also fails. Also I am making use of "ICSharpCode.SharpZipLib.dll" with the latest version 0.86. Actually I re-compiled the Excel.dll with this version of sharpziplib.dll. As said earlier, this works in my local machine for both .xls and .xlsx but gets fails in QA box.

New Post: Reading numeric data with same rounding as displayed in Excel.

$
0
0
My users typically have data containing more than 2 decimal points, that is formatted in Excel to show just two decimal places. Ideally, when I import this data, I would get the values as displayed in Excel, rather than the actual value in the cell. So for instance, cell contains 1.019, but is formatted for 2 decimals, so 1.02 is displayed in the worksheet. When I import the data, I get the actual underlying value of 1.019 rather than 1.02. I was planning to use SqlBulkCopy to load this data into a SQL database table, which doesn't give me the option of doing any rounding prior to inserting into the database, so my table with a column type of decimal(10,2) ends up with a value of 1.01, i.e. truncates beyond 2 decimal places, rather than rounding and inserting 1.02 into the table.

Is there any support within the Excel Data Reader to use the same rounding that is achieved via the numeric format applied in the Excel worksheet?

Thanks

New Post: How to import Image from Excel sheet

$
0
0
I have an excel sheet that contain images and I want to import. I am using Excel data reader. How can I implement that using C# ?

Patch Uploaded: #16126

$
0
0

bleze has uploaded a patch.

Description:
Made default/empty column name public so the user can control names of columns with no header name.

See https://exceldatareader.codeplex.com/discussions/539575 for more info on the issue resolved by this patch.

New Post: Default name for columns with no name

$
0
0
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.

New Post: Default name for columns with no name

Created 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
Viewing all 448 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>