无论使用OleDb的表单名称如何,都从Excel文档中获取第一张表单 [英] Getting the first sheet from an Excel document regardless of sheet name with OleDb

查看:105
本文介绍了无论使用OleDb的表单名称如何,都从Excel文档中获取第一张表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些用户将其工作表命名为各种疯狂的东西,但是我希望能够获得Excel文档的第一张表,而无论其名称如何.

I have users that name their sheets all sorts of crazy things, but I want to be able to get the first sheet of the Excel document regardless of what it is named.

我当前正在使用:

OleDbDataAdapter adapter = new OleDbDataAdapter(
"SELECT * FROM [sheetName$]", connString);

无论名称如何,我将如何获得第一张纸?

How would I go about getting the first sheet no matter what it is named?

谢谢.

推荐答案

使用以下命令:

using (OleDbConnection conn = new OleDbConnection(connString))
{
    conn.Open();
    dtSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
    Sheet1= dtSchema.Rows[0].Field<string>("TABLE_NAME");
}

这篇关于无论使用OleDb的表单名称如何,都从Excel文档中获取第一张表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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