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

New Post: XlsxDimension - Object ref not set to an instance of an object

$
0
0
Hey guys,

Im trying to read in a spreadsheet produced from a 3rd party vendor (Aspose) and when i try to do this i get a null exception initializing the XlsxDimension. Has anyone else seen this? is there a work around?

Created Unassigned: SeekErrormmemoryStream.cs [13835]

$
0
0
i download the last version of the sources and i coulnt compile because of lack of SeekErrorMemoryStream.cs. coul someone give me this file please ?
thank you

New Post: How to make Filtering for a DataTable?

$
0
0
Hello to all, I made it my program read the excel and only let the filled rows in a DataTable like this code:
using System;
using System.Data;
using System.IO;
using Excel;
using System.Windows.Forms;

namespace SambaNet.ConversaoPlanilhaExcel.Classes
{
    public class LerPlanilha
    {
        IExcelDataReader excelReader = null;
        FileStream stream = null;
        public string tipo { get; set; }
        public string filePath { get; set; }
        bool erro = false;
        DataSet ds = null;
        DataTable dt = null;

        //RETORNA UMA DATATABLE COM A SHEET ESCOLHIDA, NO CASO A 1 - Produtos
        public DataTable Ler()
        {
            string extension = Path.GetExtension(filePath);
            try
            {
                stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                erro = true;
            }
            if (!erro)
            {
                switch (extension)
                {
                    case ".xls":
                        excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
                        break;
                    case ".xlsx":
                        excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                        break;
                }

                excelReader.IsFirstRowAsColumnNames = true;
                ds = excelReader.AsDataSet();
                dt = ds.Tables[1];
                dt = RemoverRows(dt);
                FecharConexao();
                return dt;
            }
            else
            {
                FecharConexao();
                return null;
            }
        }

        //RETORNA A DATATABLE SEM AS ROWS VAZIAS.
        public DataTable RemoverRows(DataTable dt)
        {
            int columnCount = dt.Columns.Count;

            for (int i = dt.Rows.Count - 1; i >= 0; i--)
            {
                bool allNull = true;
                for (int j = 0; j < columnCount; j++)
                {
                    if (dt.Rows[i][j] != DBNull.Value)
                    {
                        allNull = false;
                    }
                }
                if (allNull)
                {
                    dt.Rows[i].Delete();
                }
            }
            dt.AcceptChanges();
            return dt;
        }

        public void FecharConexao()
        {
            excelReader.Close();
        }
    }
}
Now, I would like to make a filter system, for example:
  • If my id is duplicated, send a message.
  • If my description contains special characters, send a warning.
How could I develop it? Thank you, I enjoyed this reader!

New Post: Read-Only Version when Spreadsheet Locked

$
0
0
Hi

Great tool - and it works a treat!

However, when testing I could read files that were open for editing, but go the last saved version. For some reason, now I get the file as locked (Exception HResult -2147024864) whenever the user has it open.

Is there any way to open the file for "read only if locked"?

Thanks in advance

Created Unassigned: Converting a text field to datetime incorrectly [13921]

$
0
0
The spreadsheet has a TEXT value of "11:54:00" in a cell.

When populating a DataSet and reading the value from the Datatable it is returned as "31/12/1899 11:54:00"

Reviewed: 2.1.2.0 (七月 16, 2016)

$
0
0
Rated 5 Stars (out of 5) - 12345678910

Created Unassigned: Import with formula issue. [13989]

$
0
0
Hi Support,

The spreadsheet cell has a formula to extract a piece of a string and the resulting string is a FormulaField
name. I have to retrieve the actual string that is the result in Excel. (Excel shows it correctly as a string). If it happens to be 0010, the reader returns a datatable with value of 10 , it should be an actual value (0010) in my datatable.

This issue is only comes when importing xlsx file, xls works as desired.

Thanks.

Commented Unassigned: Excel Data Reader unable to read all columns data [13764]

$
0
0
I am using [Excel Data Reader](https://exceldatareader.codeplex.com/) to read my excel. my code is

```
IExcelDataReader reader = null;

FileStream stream = System.IO.File.Open(file.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

if (file.FileName.EndsWith(".xls"))
{
reader = ExcelReaderFactory.CreateBinaryReader(stream);
}
else if (file.FileName.EndsWith(".xlsx"))
{
reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
}
else
{
reader = null;
}

reader.IsFirstRowAsColumnNames = true;

var exceldata = reader.AsDataSet().Tables[0];
```

I have more than 400 rows and 10 columns in excel But exceldata is returning only first column data. All 400 rows with only first column data.

What i am missing? Please help.
Comments: ** Comment from web user: pceend **

I have the same problem it is only importing the first column of the excel file into the data set. Really stange because for other files it is working.

Did you find a solution?

Kind regards,

Jorrit


New Post: Alternative to LinqToexcel: implementation of LinqToExcel Adapter

$
0
0
This is a Wrapper classes around ExcelDataReader to make it work like LinqToExcel.

Base on first on source code : http://codereview.stackexchange.com/questions/47227/reading-data-from-excel-sheet-with-exceldatareader
Linq implementation based on : https://msdn.microsoft.com/en-us/library/bb546158.aspx

Problem:
When you compile your software in 64 bits and use LinqToExcel with Office installed in 32 bits mode, you cannot use LinqToExcel.
When you compile your software in 32 bits and use LinqToExcel with Office installed in 64 bits mode, you cannot use LinqToExcel.

Why ? because it use a driver (installed with Office) that must be in the same target a your software.
Of course, installing 32 and 64 bits drivers is not easy (there are some workaroud) and not always possible (in compagny for example), or
for public users.

Idea ? Rewrite all code that use LinqToExcel in my software or used another excel reader and make an adapter to work exactly like LinqToExcel.
It is this second option that I have tried to make.
Of course, for the moment, all LinqToExcel interface is not implemented but 3 functions :
  • WorksheetRangeNoHeader
  • WorksheetRange
  • GetColumnNames
You can use Linq to query into excel, make mapping to automatically fill class on each row.
Mapping with column's name is not always the first row, it can be anywhere.

Probably it is a good start to make your library more efficient and simple to use.
Sur it's missing code to complete linq work.

Stéphane Château (Feneck91)

You can download it : ExcelDataReaderLinqToExcelAdapter.zip

New Post: Alternative to LinqToexcel: implementation of LinqToExcel Adapter

New Post: Alternative to LinqToexcel: implementation of LinqToExcel Adapter

New Post: Date time format loading is 12 hour not 24 hour format

$
0
0
Hello,
I am using Excel daat reader to read excel into datatable and converting it to CSV file.
All is working fine except the date time from excel is loading into datatable as 12 hour format string and i need it to be 24 hour format in csv output.

Can any one help me how to get the date time in 24 hour format using exceldatareader?

Regards,
Amit

New Post: Import Hidden sheet

$
0
0
I am using IExcelDataReader in my Project in order to import the Excel worksheet into DataTable. Everything works fine but in one of my project the excel sheet is hidden, and IExcelDataReader doea not import the excel which is hidden.

Please help me out on this its very urgent.

Below is my sample code:
        'Create a new DataTable.
        Dim dt As New DataTable()

        Dim lstream As FileStream = File.Open(strFileName, FileMode.Open, FileAccess.Read)

        Dim lexcReader As IExcelDataReader = ExcelReaderFactory.CreateBinaryReader(lstream)

        Dim lresult As DataSet = lexcReader.AsDataSet

        lexcReader.IsFirstRowAsColumnNames = True

        While lexcReader.Read

        End While

        lexcReader.Close()
        lexcReader.Dispose()

        Return lresult.Tables(0)
Thanks, any quick reply will be apprecited.

Created Unassigned: How to Add New Header Names? [14026]

$
0
0
I am using below code to get all excelsheel sheet data.

IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
excelReader.IsFirstRowAsColumnNames = false;
dtExcelSheetData = result.Tables[SheetName];

But I want add my own rows.

New Post: issue with some hidden chars

$
0
0
i moved to Issue section.
please remove this post.

thank you.

Created Unassigned: issue with some hidden chars [14041]

$
0
0
hi,
i found some problem reading excel with some hidden chars.
i can t understand which are.
attached the excel example.
the problem is about Label SST, that after this wrong encoding, the dll can t extract any other word and during the reading of all excel some other words are skipped.


![Image](https://s24.postimg.org/aak6oe5dx/exceldatareader.png)

Created Unassigned: issue with some hidden chars [14042]

$
0
0
hi,
i found some problems reading excel with some hidden chars.
i can t understand which are.
attached the excel i used.
the problem is about Label SST, that after this wrong encoding, the dll can t extract any other word and during the reading of all excel some other words are skipped.


![Image](https://s24.postimg.org/aak6oe5dx/exceldatareader.png)

New Post: Does this component need microsoft office?

$
0
0
Does this component need microsoft office?

Created Unassigned: e+15 in my values [14084]

$
0
0
My value in my row cell 7885266361743930 but it comes to my gridview like this => 7,88526636174393E+15

Created Unassigned: FillWeight values cannot exceed 65535 [14095]

$
0
0
Hi,
I have read excel xlsx file. one of the dataset shows
____FillWeight values cannot exceed 65535.____


System.InvalidOperationException: Sum of the columns' FillWeight values cannot exceed 65535.
at System.Windows.Forms.DataGridView.OnAddingColumn(DataGridViewColumn dataGridViewColumn)
at System.Windows.Forms.DataGridViewColumnCollection.Add(DataGridViewColumn dataGridViewColumn)
at EnhancedDataSetVisualizer.DataSetForm.InitializeDataGridView(Int32 selectedTable)
at EnhancedDataSetVisualizer.DataSetForm.comboBoxTable_SelectedIndexChanged(Object sender, EventArgs e)
at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Viewing all 448 articles
Browse latest View live


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