Hi,
Maybe do you know how how to read data from Excel (I have one worksheet for all .xls documents, and and table with columns and rows to retrieve info from them).
I would be very grateful if you help me, and thanks in advance
Printable View
Hi,
Maybe do you know how how to read data from Excel (I have one worksheet for all .xls documents, and and table with columns and rows to retrieve info from them).
I would be very grateful if you help me, and thanks in advance
Try to use OleDB to get data from excel sheet. Check http://www.connectionstrings.com and you will see how to connect to excel file.
While reading with C# from Word table, there is doc.Tables[1].Rows[i].Cells[j].Value property. Maybe do you know somethihg similat to read from Excel table?
Code://Open excel file
DataSet dsRecords = new DataSet();
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ExcelDocument.xls;Extended Properties=Excel 8.0;";
OleDbDataAdapter daExcel = new OleDbDataAdapter("SELECT * FROM [SomeWorksheet$]", strConn);
daExcel.Fill(dsRecords, "records");
for (int a = 0; a < dsRecords.Tables[0].Rows.Count; a++)
{
string someString = dsRecords.Tables[0].Rows[a][0].ToString().Trim();
}
Thanks a lot. It's very useful.