1

I am reading an excel file using C# code into a data-table and displaying it into WPF data-grid. When I am reading dates from excel file and display them into data-grid the format of dates changes. I am using Oledb ADO.NET to read excel file.

The query I am using is:

SELECT * FROM [Sheet1$]

So basically I want to read data from excel, they it appears to user when he/she opens an excel and the same way I want to display it in my data-grid. Please guide me. If you need any other information about this problem, please ask me.

Regards, Priyank Thakkar

1
  • 1
    Could you provide connction string that you are using for Oledb? Commented Feb 7, 2012 at 13:41

2 Answers 2

1

Use a connection string similar to this:

OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";

As quoted from ConnectionStrings.com:

"IMEX=1;" tells the driver to always read "intermixed" (numbers, dates, strings etc) data columns as text. Note that this option might affect excel sheet write access negative.

Sign up to request clarification or add additional context in comments.

1 Comment

Also target the x86 platform, as the Jet drivers will not run in 64-bit mode.
0

You could save the file as a .csv and:

        string[] fileLines = File.ReadAllLines("path\file.csv");

        foreach (string s in fileLines)
        {
            string[] splitRow = s.Split(',');
            //do stuff w/ row columns
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.