private void button1_Click(object sender, EventArgs e)
{
try
{
OleDbConnection oleDbConnection = new OleDbConnection();
oleDbConnection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=D:\MSExcel\ProjectTimeline.xls;"+
@"Extended Properties=""Excel 8.0;"+
@"HDR=Yes;IMEX=1"";";
oleDbConnection.Open();
DataTable dtSheets =
oleDbConnection.GetOleDbSchemaTable(
OleDbSchemaGuid.Tables, null);
if (dtSheets != null)
{
string strName = "";
foreach (DataRow row in dtSheets.Rows)
{
string sheetName = row["TABLE_NAME"].ToString();
strName += sheetName.Substring(0,
sheetName.Length - 1);
listBox1.Items.Add(sheetName);
}
dtSheets.Dispose();
oleDbConnection.Close();
oleDbConnection.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.Replace(
"Please", "\nPlease"), Common.displayWelcome);
}
}