Forum Discussion

shiva_ranabhat's avatar
shiva_ranabhat
Contributor
9 years ago
Solved

how to check if sheet in excel driver exist or not

Hi,    I want to check if Sheet1 exists or not. Sometimes 'Sheet1' is named as Error in our application, and hence is an actual error in export. Even though file is exported correctly.    Attempt...
  • HKosova's avatar
    9 years ago

    As Alex said, you can use Excel's COM object, Excel.Application for that. Something along the lines of:

     

    var oExcel = Sys.OleObject("Excel.Application");
    var oWb = oExcel.Workbooks.Open("C:\\MyFile.xls");
    var oSheet = null; try { oSheet = oWb.Sheets("Sheet1"); } catch (e) {} if (oSheet != null) { Log.Message("The specified sheet exists."); } else { Log.Error("The specified sheet does not exists."); } oExcel.Quit();