Question How do I read excel ?

atuldalvi

Member
I am having excel file with mutiple sheet tabs. I want to read data from each sheet. Please let me know how do i do that .
 

Cringer

ProgressTalk.com Moderator
Staff member
It depends on all sorts of things, but one way is to create a com handle using the standard excel com object. Google it.
 

atuldalvi

Member
Code is available to create excel sheet using com handle but i want to read excel with mutiple sheets available in it.
 

Cringer

ProgressTalk.com Moderator
Staff member
If you already have com handle based code then it shouldn't be too hard to read the documentation for the com object and engineer what you want.
We have our com stuff in a manager program so you won't get the actual code for that, but here is a code snippet that uses the com manager functions to get the worksheet names:
Code:
  DEFINE VARIABLE lv-WorkSheets     AS CHARACTER NO-UNDO.
    DEFINE VARIABLE lv-WorksheetCount AS INTEGER   NO-UNDO.
    DEFINE VARIABLE lv-xls-handle     AS HANDLE    NO-UNDO.
    DEFINE VARIABLE lv-i              AS INTEGER   NO-UNDO.

    RUN excelmgr.p PERSISTENT SET lv-xls-handle.

    RUN EXCEL-SetParameter  IN lv-xls-handle (INPUT "VISIBLE","NO").
    RUN EXCEL-SetParameter  IN lv-xls-handle (INPUT "DISPLAYALERTS","NO").
    RUN EXCEL-SetParameter  IN lv-xls-handle (INPUT "READONLY","YES").
    RUN EXCEL-OpenExcelFile IN lv-xls-handle (INPUT ip-FileName).
    RUN EXCEL-SetParameter  IN lv-xls-handle (INPUT "AUTONEWSHEET","NO").
    RUN EXCEL-SetParameter  IN lv-xls-handle (INPUT "SCREENUPDATING","NO").

    lv-WorksheetCount = DYNAMIC-FUNCTION("fn-EXCEL-WorksheetCount" IN lv-xls-handle).

    DO lv-i = 1 TO lv-WorksheetCount:
      RUN EXCEL-SelectWorkSheet IN lv-xls-handle (INPUT lv-i).
      lv-WorkSheets = lv-WorkSheets + min(lv-WorkSheets,",") + DYNAMIC-FUNCTION("fn-EXCEL-WorkSheetName" IN lv-xls-handle).
    END.
    RETURN lv-WorkSheets.
 
Top