1. Jhonns Salas
  2. PowerBuilder
  3. Tuesday, 14 May 2024 16:00 PM UTC

Hello,

The company has an application built in PowerBuider 2017 R3, distributed using TSPlus,

in a module it is necessary import data from Excel, and it was working without problems,

but suddenly this part of the application stopped working.

When the user is going to open a file from Excel, This error message is showed:

  Error executing Excel API

  Error No. : -2

  Class name not found

 

Do you have any idea about what can produce this situation?

Thanks and regards,

 

 

John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 14 May 2024 17:53 PM UTC
  2. PowerBuilder
  3. # 1

Hi, Jhonns -

It would be extremely helpful to see the PowerScript code that is producing the error, so that we are not wasting our time playing 20 Questions back and forth. Could you please post a few lines of the code that shows how the Excel data is being imported?

Thanks and best regards, John

Comment
There are no comments made yet.
Jhonns Salas Accepted Answer Pending Moderation
  1. Tuesday, 14 May 2024 20:31 PM UTC
  2. PowerBuilder
  3. # 2

You are very right.

This is the code used in a function to read an Excel file.

of_read_xlsx_file (string as_filename)

//JS Event to read Excel file extension XLS
OleObject lole_excel, lole_workbook, lole_worksheet
String ls_columns[]
String ls_aux, ls_ole_error
Long ll_col, ll_row, ll_xls_cols, ll_xls_rows
Long ll_new, ll_row_start
Integer li_wsheets_count, li_ws
Integer li_rtn, li_total_cols, li_i

TRY
    lole_excel = CREATE OLEObject
    li_rtn = lole_excel.ConnectToNewObject("excel.application")
    IF li_rtn = 0 THEN
        st_status.Text = "Reading data"
        lole_excel.WorkBooks.Open(as_filename)        
        li_wsheets_count = lole_excel.Application.Worksheets.Count
        IF li_wsheets_count < 1 THEN            
            dw_cols_dest.Reset()
            st_workbook.Visible = False
            ddlb_wsheets.Visible = False
            messagebox("Attention", "Selected Excel file does not contains worksheets")
            st_status.Text = "Selected Excel file does not contains worksheets"
        ELSE
            FOR li_ws = 1 TO li_wsheets_count
                ddlb_wsheets.DeleteItem(li_ws)
            NEXT
            FOR li_ws = 1 TO li_wsheets_count
                ddlb_wsheets.AddItem(String(li_ws))
            NEXT
        END IF
        st_workbook.Visible = True
        ddlb_wsheets.Visible = True
        IF li_wsheets_count = 1 THEN //Data formating
            ddlb_wsheets.SelectItem(1)
            SetPointer(Hourglass!)        
            Event ue_set_xlsx_file(lole_excel, 1)
        END IF
        IF IsValid(lole_excel) THEN
            lole_excel.Application.Quit()
            lole_excel.DisconnectObject()
        END IF
        st_status.Text =String(dw_cols_dest.RowCount()) + " Rows read"
        cb_next.Enabled = True
    ELSE
        CHOOSE CASE li_rtn
            CASE -1
                ls_ole_error =  'Invalid call: the argument is the Object property of a control'
            CASE -2
                ls_ole_error = 'Class name not found'
            CASE -3
                ls_ole_error =  'Object could not be created'
            CASE -4
                ls_ole_error = 'Could not connect to object'
            CASE -5
                ls_ole_error = 'Ca not connect to the currently active object'
            CASE -6
                ls_ole_error = 'Filename is not valid'
            CASE -7
                ls_ole_error ='File not found or file could not be opened'        
            CASE -8
                ls_ole_error = 'Load from file not supported by server'        
            CASE -9
                ls_ole_error = 'Other error'
            CASE -15
                ls_ole_error = 'COM+ is not loaded on this computer'
            CASE -16
                ls_ole_error = 'Invalid Call: this function not applicable to OLETxnObject'
        END CHOOSE        
        MessageBox("Attention ", "Error executing Excel API" + "~r~n" + "Error No.: " + + String(li_rtn) &
                                        +"~r~n" + ls_ole_error )
        st_status.Text = "Error executing Excel API - " + ls_ole_error
    END IF
    Destroy lole_excel
    Return 1
CATCH (runtimeerror lo_rte)
    MessageBox("Attention", "MS Excel API runtime error")
END TRY

-----------

Thank you very much...

Comment
  1. Chris Pollach @Appeon
  2. Tuesday, 14 May 2024 23:08 PM UTC
Normally, installing the MS-Office product does this registry update during the installation process. I would contact your MS-Office support team in your organization for this to be done on that Server.
  1. Helpful
  1. Jhonns Salas
  2. Wednesday, 15 May 2024 16:34 PM UTC
Chris,

Because my IDE, I not able to test this,

Create an installer MSI type, using the PB Runtime Packager, to install the MS Excel 12 Support,

Do you think, it is going to install the Excel Class: Microsoft.Office.Interop.Excel.ApplicationClass

libraries and create an entry in the registry or it is necessary to install the libraries from MS Office support?

In the application server is not installed the PB runtime virtual machine, or any MS Office software.



Thanks for your support.



  1. Helpful
  1. Chris Pollach @Appeon
  2. Wednesday, 15 May 2024 16:45 PM UTC
No, what we are talking about is outside the PB IDE and runtime. OLE is basically a configuration issue with the MS-Windows OS itself. When the PB code performs a ConnectToNewObject() command, the request is totally serviced by the O/S. The "In Process Server" is loaded & instantiated in a different address space by the OS and only a handle to that service is returned to the PB App (if successful). HTH
  1. Helpful 1
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 14 May 2024 21:36 PM UTC
  2. PowerBuilder
  3. # 3

Thanks for posting this code.

Aside from triggering the ue_set_xlsx_file event, I see no importing of any data in this code. On what line does the error occur?

I pasted this code into a command button Clicked event, commented out statements that did not apply, such as references to st_status, ddlb_wsheets, etc. , commented out the ue_set_xlsx_file event call, and had the code open an existing Excel spreadsheet, stepped through in the debugger, and it works fine.

I suggest you code a more robust "catch" block, using the OLERuntimeError object (a descendant of the more generic RuntimeError object) when working with OLE, as it has some additional properties that may be helpful to include in your MessageBox text. Refer to the PB Help topic for "RuntimeError object" to see the additional properties listed that are provided in the OLERuntimeError object. Here is a code snippet I use when working with OLE (this example is from code that interacts with Outlook):

Try
   If Not IsValid(iole_application) Yhen
      iole_application = CREATE OLEObject
      li_rc = iole_application.ConnectToNewObject('Outlook.Application')
   End If
Catch(OLERuntimeError lore_1)
   as_msg = 'An error has occurred while connecting to Outlook.~r~n~r~n' + &
            'Error number: ' + String(lore_1.Number) + '~r~n' + &
            'Line number: ' + String(lore_1.Line) + '~r~n' + &
            'Description: ' + lore_1.Description + '~r~n' + &
            'Source: ' + lore_1.Source + '~r~n' + &
            'Message: ' + lore_1.Text + '~r~n~r~n' + &
            'Mail was not sent.'
   Return -1
End Try

Doing something similar in your app will provide you with better diagnostic information to help you troubleshoot.

Are you running this migrated app now as 64-bit and as 32-bit before?

Is Excel installed? Is it a version that supports the .xlsx file format?

Comment
  1. Jhonns Salas
  2. Tuesday, 14 May 2024 22:58 PM UTC
John,



I am thinking that the error is created due to the Excel Interop Class is not installed in the server.

In this server, even the PowerBuilder Virtual Machine is Not installed, due to politics in the company.

Normally i copy the PowerBuilder Runtime files in the folder of the application, which enhance its startup time.

I suppose, it is necessary update those DLLs using a Microsoft Installer.

Do you have any recommendation about the Excel Interop registry entry or its install.



Thank you very much.
  1. Helpful
  1. John Fauss
  2. Wednesday, 15 May 2024 18:31 PM UTC
I believe that the OLE interface for the various Office products can be installed with MS Office. The Excel Interop dll will not function will not work unless Excel is also installed.

I'm not sure this will help, but I found the following via a web search:

https://www.dllme.com/dll/files/microsoft_office_interop_excel

Good luck!
  1. Helpful 1
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.