public void button1_Click(object sender, EventArgs e) { openFileDialog1.Filter = "Excel File|*.xls|Excel File|*.xlsx"; openFileDialog1.ShowDialog(); string path = openFileDialog1.FileName; comboBox1.Items.Clear(); Microsoft.Office.Interop.Excel.Application xlr = new Microsoft.Office.Interop.Excel.Application(); Workbook wb = xlr.Workbooks.Open(path, 0, false, 5, "", "", false, XlPlatform.xlWindows, "", true, false, 0, true, false, false); foreach (Worksheet w in xlr.Worksheets) { comboBox1.Items.Add(w.Name); } xlr.Visible = true; wb.Close(); xlr.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(wb); System.Runtime.InteropServices.Marshal.ReleaseComObject(xlr); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)