Excel.Application xlApp;
private void LeakageChecks_Load(object sender, EventArgs e){
Excel.Workbook xlWorkBook;Excel.Worksheet xlWorkSheet;Excel.Range range;string str;int rCnt = 0;int cCnt = 0;xlApp = new Excel.Application();xlWorkBook = xlApp.Workbooks.Open(@"C:\LeakData\LeakedData.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);range = xlWorkSheet.UsedRange;for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++){for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++){str = Convert.ToString((range.Cells[rCnt, cCnt] as Excel.Range).Value2);MessageBox.Show(str);}}xlWorkBook.Close(true, null, null);xlApp.Quit();releaseObject(xlWorkSheet);releaseObject(xlWorkBook);releaseObject(xlApp);}private void releaseObject(object obj){try{System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);obj = null;}catch (Exception ex){obj = null;MessageBox.Show("Unable to release the Object " + ex.ToString());}finally{GC.Collect();}}
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: