如何在C#中获取Excel导入的工作表名称 [英] How to get excel imported sheet name in c #

查看:100
本文介绍了如何在C#中获取Excel导入的工作表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

我正在将1个excel文件导入到我的数据库中.

我需要阅读以下声明的工作表名称

Dear ,

i am importing 1 excel file into my database.

I need to read its sheet name for below statement

command.CommandText = "SELECT * FROM [Sheet1$]";



但是,并非总是第一个excel工作表名称不是"Sheet1"的情况.

我想重新使用第一个Excel工作表名称.请指导我.

谢谢



But it is not case where always first excel sheet name is not "Sheet1".

I want to reas first excel sheet name. Please guide me.

Thank you

推荐答案

;



但是,并非总是第一个excel工作表名称不是"Sheet1"的情况.

我想重新使用第一个Excel工作表名称.请指导我.

谢谢



But it is not case where always first excel sheet name is not "Sheet1".

I want to reas first excel sheet name. Please guide me.

Thank you


您好,

请阅读本文.它可能对您有帮助
C#-检索Excel工作簿工作表名称.

关于AR
Hi,

Please go through with this article. It might help you
C# - Retrieve Excel Workbook Sheet Names.

Regards AR


u可以这样做

u can do like this

DataTable dtExcelsheetname = new DataTable();
       excelcon.Open();
       dtExcelsheetname = excelcon.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
       string[] excelSheets = new String[dtExcelsheetname.Rows.Count];
       int j = 0;
       foreach (DataRow row in dtExcelsheetname.Rows)
       {
           excelSheets[j] = row["TABLE_NAME"].ToString();
           j++;
       }
       excelcon.Close();
       string strquery = "select * from [" + excelSheets[0].ToString() + "]";



希望对您有帮助



hope it helps


这篇关于如何在C#中获取Excel导入的工作表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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