Import excel to datagridview

Hi,
I need to import excel data to a datagridview, without using interop, because it only works when excel is installed in computer.

I searched and found out about OleDB, which kind of simmulates a database in order to get those values, however, i can't find a c++ code for that anywhere!

Can someone help me out with it? Or give me a way to go?

Thanks..
As you mention DataGridView, are you talking about C++/CLI ??

And when you say interop, interop to what?

Andy
Last edited on
Yes, i'm using C++/CLI with Visual Studio C++ 2010. I know it's not recommended, but I can't change due to circunstances now.

Microsoft::Oficce::Interop::Excel is a way to get and write values from/to excel files, however it only works when excel is installed on the users computer, and I can't rely on that.

Like I said, i found out some stuff about OleDb and ADO, but none in C++ algorithm.. Or maybe another better, safer and easier way to do that...

Anton
OK, just checking.

If you're using C++/CLI then you can base your code on C# examples as it's easy enough to map from C# to C++/CLI. And there are usually many more .NET examples in C# than C++/CLI.

What you need to check out is OleDbDataReader using either the newer ACE provider or Jet provider.

Difference between Microsoft.Jet.OleDb and Microsoft.Ace.OleDb
http://stackoverflow.com/questions/14401729/difference-between-microsoft-jet-oledb-and-microsoft-ace-oledb

This is in C# but should be easy enough to "translate" to C++/CLI. It shows how to use the OLE DB Jet Provider.

How to Populate a DataGridView Control using OleDbDataReader
http://www.codeproject.com/Articles/20733/How-to-Populate-a-DataGridView-Control-using-OleDb

And this page has various C++/CLI examples, inc. "Integrating a client database using OleDbDataAdaptor", but doesn't look as friendly to me.

C++/CLI code excerpts
http://www.dirkbertels.net/computing/managedCpp.php

Andy

PS In case it's of any use?

C++/CLI Cheat Sheet
http://manski.net/2011/04/cpp-cli-cheat-sheet/

This article provides a quick comparison between C++/CLI and C#. It’s meant for those who know C# (and possibly C++) and will explain which C++/CLI language construct correspond with which in C#. (I don’t know Visual Basic so I can’t add infos about this here.)

Last edited on
Topic archived. No new replies allowed.