简体   繁体   中英

How to exclude headdings from excel files while reading the data to dataset using c#

my excel file contains large amount of data.I am reading the data starting with column names. But my excel file contains Headdding in first row which is unwanted data for me to read.how to avoid unwanted data and read the only necessary data.. can u plz provuide the solution....

使用ADO.NET,它使您可以将电子表格视为数据库表。

You can read the data from the excel file using the following code:

using System.Data;
using System.Data.OleDb;

OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Book1.xls;Extended Properties=Excel 8.0");

OleDbDataAdapter da = new OleDbDataAdapter("select * from MyObject", con);

DataTable dt = new DataTable();
da.Fill(dt);

Once your datatable is populated with rows, just delete the first row.

dt.Rows.RemoveAt(0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM