C#基于OLEDB获取Excel文件表结构信息的方法
作者:roucheng 时间:2022-03-06 07:29:44
本文实例讲述了C#基于OLEDB获取Excel文件表结构信息的方法。分享给大家供大家参考,具体如下:
这个问题来自论坛提问,同理可以获得access等数据库的表结构信息。
using System;
namespace ConsoleApplication11
{
class Program
{
public static void Main()
{
getExcelFileInfo( @" c:a.xls " );
}
private static void getExcelFileInfo(string Path)
{
string strConn = " Provider=Microsoft.Jet.OLEDB.4.0; " + " Data Source= " + Path + " ; " + " Extended Properties=Excel 8.0; " ;
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn);
conn.Open();
System.Data.DataTable table = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null );
foreach (System.Data.DataRow drow in table.Rows)
{
string TableName = drow[ " Table_Name " ].ToString();
Console.WriteLine(TableName + " : " );
System.Data.DataTable tableColumns = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, new object [] { null , null , TableName , null } );
foreach (System.Data.DataRow drowColumns in tableColumns.Rows)
{
string ColumnName = drowColumns[ " Column_Name " ].ToString();
Console.WriteLine( " " + ColumnName);
}
}
Console.ReadKey( true );
}
}
}
希望本文所述对大家C#程序设计有所帮助。
标签:C#,OLEDB,Excel
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
spring boot 实现配置多个DispatcherServlet最简单方式
2023-12-18 03:24:46
![](https://img.aspxhome.com/file/2023/9/63769_0s.jpg)
c# 动态构建LINQ查询表达式
2022-03-23 20:40:47
![](https://img.aspxhome.com/file/2023/2/77252_0s.png)
C#自定义繁体和简体字库实现中文繁体和简体之间转换的方法
2023-03-16 06:00:33
MyBatis中XML 映射文件中常见的标签说明
2023-01-07 08:02:59
Java 用反射设置对象的属性值实例详解
2023-11-26 03:56:51
Java实现通讯录管理系统项目
2022-11-17 02:41:03
![](https://img.aspxhome.com/file/2023/3/71903_0s.jpg)
spring mvc中@PathVariable / 带斜杠方式获取
2022-09-15 04:47:27
二叉搜索树实例练习
2022-09-20 22:03:06
springboot bean循环依赖实现以及源码分析
2022-06-05 11:50:15
![](https://img.aspxhome.com/file/2023/9/61509_0s.png)
一文带你彻底理解Java序列化和反序列化
2021-12-23 05:24:12
maven profile动态选择配置文件详解
2023-11-05 22:05:20
![](https://img.aspxhome.com/file/2023/4/64514_0s.png)
Spring的Aware接口实现及执行顺序详解
2023-03-09 09:50:53
![](https://img.aspxhome.com/file/2023/6/71646_0s.png)
Java去掉数字字符串开头的0三种方法(推荐)
2022-05-31 08:04:41
Mybatis关于动态排序 #{} ${}问题
2023-09-01 17:34:57
常见JavaWeb安全问题和解决方案
2023-11-09 01:02:17
Java中GUI工具包AWT和Swing用法介绍
2022-02-06 09:02:35
![](https://img.aspxhome.com/file/2023/6/71176_0s.jpg)
Dubbo实现分布式日志链路追踪
2023-08-23 21:00:54
![](https://img.aspxhome.com/file/2023/2/58292_0s.png)
SpringCloud Eureka服务注册中心应用入门详解
2022-02-23 08:48:44
![](https://img.aspxhome.com/file/2023/1/79951_0s.png)
详解Java利用深度优先遍历解决迷宫问题
2022-08-20 02:46:54
SpringBoot读取yaml文件操作详解
2022-09-16 09:38:31