c# - 我如何从 C# 中的 Excel 工作表中选择特定列?

标签 c# excel

如何从 Excel 工作表中选择特定列而不是所有列

string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", txtPath.Text);
string query = String.Format("select * from [{0}$]", "Sheet1");
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
dataGridView1.DataSource = dataSet.Tables[0];    

最佳答案

关于:

SELECT * FROM [Sheet1$B14:C20]

这应该选择单元格 B14C20

关于c# - 我如何从 C# 中的 Excel 工作表中选择特定列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7150684/

相关文章:

c# - ASP.NET Web API CORS 不适用于 AngularJS

vba - 删除底部的空行

excel - 路径适用于 PC,但不适用于 Mac

vba - excel不刷新所有数据透视表

php - 如何使用纯 PHP 格式化带有样式、字体、颜色、表格等的 excel 文件?

c# - SQL Server CLR 硬编码 SQL 语句

c# - IIS 0x80070020 错误

c# - Windows 安装程序中的通用应用程序数据路径

excel - 创建具有多个索引属性的类

c# - 在样式中使用RelativeSource作为ConverterParameter