Excel表格架构 [英] excel table schema

查看:77
本文介绍了Excel表格架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发带有OleDbConnection连接的.NET程序.我正在使用oledb .NET驱动程序来查询Excel文件.但是,我需要知道列的单元格格式(即:常规,数字百分比).是否可以通过GetSchema GetOleDbSchemaTable .Net类获取此信息?

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?

推荐答案



要使用GetOleDbSchemaTable检索单元格格式,可以使用OleDbSchemaGuid.如果您将其签出,将会看到一大堆可以从中收集的信息.

下面的代码演示了这种方法.
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();


运行此代码,然后查找名为"DATA_TYPE"的列.例如,如果您有一些百分比值,则会看到代表这种格式的值130.


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.


这篇关于Excel表格架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆