1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
| private void Button_Click(object sender, EventArgs e) { string file = "C:\\Book1.xls"; Excel._Application xlApp; Excel.Workbook xlWorkbook; Excel.Worksheet xlWorksheet; Excel.Range xlRange; xlApp = new Excel.Application(); xlWorkbook = xlApp.Workbooks.Open(file, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorksheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(2); if (xlWorksheet.Cells[1, 2].Value != null) { TextBox1.Text = xlWorksheet.Cells[1, 2].Value.ToString(); }
xlWorkbook.Close(); xlApp.Quit(); } |