Menu

How to select a sheet other than activesheet

Help
SaiTanmai
2014-09-11
2014-10-19
  • SaiTanmai

    SaiTanmai - 2014-09-11

    I need to select a sheet other than active sheet in excel workbook

    The excel workbook is opened from a web application and I am using below code to access the excel.
    xl = ActiveXComponent.connectToActiveInstance("Excel.Application");
    xl.setProperty("Visible", true);
    comExcel = xl.getObject();
    sheet = Dispatch.get(comExcel, "ActiveSheet").toDispatch();

    How can we select another sheet using JACOB

     
  • Quan Nguyen

    Quan Nguyen - 2014-10-19
    workbook = Dispatch.call(workbooks, "Open", file.getPath()).toDispatch(); // Open workbook
    Dispatch workSheets = Dispatch.get(workbook, "Worksheets").toDispatch();
    int count = Dispatch.get(workSheets, "Count").getInt();
    
    for (int sheetNumber = 1; sheetNumber <= count; sheetNumber++) { // Go thru each worksheet
        Dispatch worksheet = Dispatch.invoke(workSheets, "Item", Dispatch.Get, new Object[]{sheetNumber}, new int[1]).toDispatch();
        //...
    }
    
     

Log in to post a comment.