Public System. data. datatable getexceldata (string excelfilepath) {try {excel. application APP = new excel. application (); excel. sheet sheet; excel. workbook workbook; system. data. datatable dt = new system. data. datatable (); If (APP = NULL) {return NULL;} object omissiong = system. reflection. missing. value; workbook = app. workbooks. open (excelfilepath, omissiong, OMI Ssiong, omissiong, omissiong); // read data to the able -- start sheets = workbook. worksheets; excel. worksheet worksheet = (Excel. worksheet) sheets. get_item (1); If (worksheet = NULL) return NULL; string cellcontent; int irowcount = worksheet. usedrange. rows. count; int icolcount = worksheet. usedrange. columns. count; excel. range rang E; For (INT irow = 1; irow <= irowcount; irow ++) {datarow DR = DT. newrow (); For (INT icol = 1; icol <= icolcount; icol ++) {range = (Excel. range) worksheet. cells [irow, icol]; cellcontent = (range. value2 = NULL )? "": Range. text. tostring (); If (irow = 1) {DT. columns. add (cellcontent) ;}else {Dr [icol-1] = cellcontent ;}} if (irow! = 1) dt. rows. add (DR);} // read data to the able -- end workbook. close (false, omissiong, omissiong); system. runtime. interopservices. marshal. releasecomobject (workbook); workbook = NULL; app. workbooks. close (); app. quit (); system. runtime. interopservices. marshal. releasecomobject (APP); APP = NULL; GC. collect (); GC. waitforpendingfinalizers (); Return DT;} catch {return NULL ;}}