Sunday, March 29, 2015

Read Excel File to String Question


Hi vkid12,


Another way using OLEDB read data from excel



private void button2_Click(object sender, EventArgs e)
{
string PATH = @"D:\C# Repro\Winform\ReadExcel\ReadExcel\bin\Debug\test111.xls";
string connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + PATH + ";Extended Properties=Excel 12.0";
OleDbConnection connExcel = new OleDbConnection(connection);
connExcel.Open();
List<string> result = new List<string>();

DataTable xlsData = new DataTable();
OleDbDataAdapter dbAdapter = new OleDbDataAdapter("select * from [Sheet1$] WHERE ID <= 6 ", connExcel);
dbAdapter.Fill(xlsData);// the data are in datatable, you could filter what you want

}



Best regards,


Kristin




We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

Click HERE to participate the survey.



what namespace assembly do I need to use?

No comments:

Post a Comment