Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a .NET program with a OleDbConnection connection. I am using an oledb .NET driver to query an excel file; however, i need to know the cell format (ie: General, Number Percentage) of the columns. Is there any way to obtain this info through the GetSchema GetOleDbSchemaTable .Net classes?
Posted

1 solution

Hi,

to retrieve cell format using GetOleDbSchemaTable you might use OleDbSchemaGuid. If you check it out will see a whole bunch of information that can be gathered from it.

Code below demonstrates this approach.
OleDbConnection conn = new  OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\YourFileName.xls;Extended Properties=Excel 8.0");
 conn.Open();
 DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, null);
 dataGridView1.DataSource = dt;
 dataGridView1.ReadOnly = true;
 conn.Close();

Run this code and look for a column called "DATA_TYPE". If you have some values in percentage, for instance, will see the value 130 which represents this kind of format.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900