K
K
kykyryky2016-07-29 13:56:13
Programming
kykyryky, 2016-07-29 13:56:13

What are the features when working with excel files through ole db?

For example there is a code:

OleDbCommand command = new OleDbCommand();
OleDbConnection connection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=Excel 8.0;");
connection.Open();
string sql = "select * from Sheet1";
command.Connection = connection;
command.CommandText = sql;
OleDbDataReader reader = command.ExecuteReader();
...

Do I understand correctly that the file structure should be exactly like a database table? no merged cells, no fancy headers and titles.
If I create a file using the CREATE TABLE query, and then add rows there in MS Excel or Calc, then when loading the content using ole db, it does not see these rows, or I get the exception ""unable to find installable ISAM", or "Object "Sheet1" was not found by the Microsoft Access database engine. Make sure the object exists, and its name and path are correct." etc.
It seems that if I created a file with a similar code with a CREATE TABLE query, then it's better not to change anything in this file except using my program third-party programs... And it turns out that an arbitrary file cannot be parsed in this way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
saltydogd, 2016-07-29
@kykyryky

A logical impression, in principle)
Yes, the opportunity is convenient, but for a "regular" cell structure, you can write (it was a long time ago, offhand) anything without changing the format
Plus dancing with the data source (is there an appropriate provider in the system, settings)
If the format is floating, then it is more logical to use the Excel Primary Interop Assembly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question