How to access excel file in C #

I need to open an excel sheet from a specific location ( d:\temp\emp.xls ), and then bold the column headers and save the file.

I am trying to do this, but not getting how to open a file and access 1 line and make them bold in C #?

0
source share
1 answer

string connectionString = "Provider = Microsoft.Jet.OleDb.4.0; data source = c: \ customers.xls; Advanced properties = Excel 8.0;";

  // Select using a Named Range //string selectString = "SELECT * FROM Customers"; // Select using a Worksheet name string selectString = "SELECT * FROM [Sheet1$]"; OleDbConnection con = new OleDbConnection(connectionString); OleDbCommand cmd = new OleDbCommand(selectString,con); try { con.Open(); OleDbDataReader theData = cmd.ExecuteReader(); while (theData.Read()) { Console.WriteLine("{0}: {1} ({2}) - {3} ({4})", theData.GetString(0),theData.GetString(1),theData.GetString(2),theData.GetString(3),theData.GetString(4)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { con.Dispose(); } 
0
source

All Articles