如何使用C#读取Excel文件的数据?
如何使用C#读取Excel文件?我打开一个Excel文件进行阅读并将其复制到剪贴板以搜索电子邮件格式,但我不知道该怎么做。
FileInfo finfo;Excel.ApplicationClass ExcelObj = new Excel.ApplicationClass();ExcelObj.Visible = false;Excel.Workbook theWorkbook;Excel.Worksheet worksheet;if (listView1.Items.Count > 0){ foreach (ListViewItem s in listView1.Items) { finfo = new FileInfo(s.Text); if (finfo.Extension == ".xls" || finfo.Extension == ".xlsx" || finfo.Extension == ".xlt" || finfo.Extension == ".xlsm" || finfo.Extension == ".csv") { theWorkbook = ExcelObj.Workbooks.Open(s.Text, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, false, false); for (int count = 1; count <= theWorkbook.Sheets.Count; count++) { worksheet = (Excel.Worksheet)theWorkbook.Worksheets.get_Item(count); worksheet.Activate(); worksheet.Visible = false; worksheet.UsedRange.Cells.Select(); } } }}
相关分类