1. Raquel Rodriguez
  2. PowerBuilder
  3. Monday, 21 October 2024 07:46 AM UTC


Hola buenas,

A ver si alguien me puede ayudar con esto.

No puedo realizar la apertura de un excel, para hacer una importación de dicho documento: OLEObject lnvo_excel n_cst_datetime lnv_retardo lnvo_excel = create OLEObject // Se realiza la conexión al objeto OLE de EXCEL li_retorno = lnvo_excel.ConnectToNewObject("excel.application") // Evalúa retorno IF li_retorno <> 0 THEN // ERROR ls_param[1] = "Error connecting to Object OLE EXCEL" gnv_app.inv_error.of_Message(gnv_var.cs_mb_attention, ls_param) DESTROY lnvo_excel RETURN -1 END IF // Abre el archivo excel lnvo_excel.WorkBooks.Open( as_ruta_fichero ) --> aquí es donde da el fallo, tanto al debugar como al compilar *Reproduce Steps: Si se lanza la aplicación el error que aparece es el siguiente: Error calling object function open ... Error number 35 Un saludo y gracias de antemano
John Fauss Accepted Answer Pending Moderation
  1. Monday, 21 October 2024 14:10 PM UTC
  2. PowerBuilder
  3. # 1

Hola, Raquel -

El problema puede deberse a que Excel no puede encontrar el archivo de hoja de cálculo solicitado.

¿Qué estás intentando lograr? ¿Abrir una hoja de cálculo de Excel existente o crear una nueva?

Si quieres abrir una hoja de cálculo existente, debes asignar la colección Workbooks a otro OLEObject para poder manipular los libros de trabajo dentro de la hoja de cálculo. Aquí hay un ejemplo que abre una hoja de cálculo de Excel y luego obtiene y muestra todas las propiedades integradas del documento:

[Translation]
Hi, Raquel -
The problem may be due to Excel not being able to find the requested spreadsheet file.
What are you trying to accomplish? Open an existing Excel spreadsheet or create a new one?
If you are wanting to open an existing spreadsheet, you need to assign the Workbooks collection to another OLEObject in order that you may manipulate the workbooks within the spreadsheet. Here is an example that opens an Excel spreadsheet, then obtains and displays all of the built-in document properties:

// Tests how to access built-in document properties in Excel.

Integer   li_rc, li_count, li_index
String    ls_msg, ls_prop_name, ls_prop_value, ls_last_author_prev
OLEObject lole_excelapp, lole_workbook, lole_builtin

// Establish and OLE connection to the Excel application.
lole_excelapp = CREATE OLEObject
li_rc = lole_excelapp.ConnectToNewObject("Excel.Application")

// Open an Excel workbook (a .xlsx file).
lole_workbook = CREATE OLEObject
lole_workbook = lole_excelapp.Workbooks.Open("C:\Test.xlsx")   // <--- Specify the path/name of an Excel spreadsheet here.

// How many built-in document properties are there in the collection?
li_count = lole_workbook.BuiltinDocumentProperties.Count
//MessageBox("Built-In Document Properties Count",String(li_count))

// Create an OLE object to access/modify a document property.
lole_builtin = CREATE OLEObject

ls_msg = ""

// Obtain the name of each built-in document property and if possible,
// its value.
//
// The use of Try/Catch statements is required, because Excel will throw a runtime error
// if you try to obtain the value of a document property that does not have a value.
For li_index = 1 To li_count
   // Obtain the next built-in document property from the collection.
   lole_builtin = lole_workbook.BuiltinDocumentProperties(li_index)
   
   // Get the name of this built-in document property.
   Try
      ls_prop_name = lole_builtin.Name
   Catch (RuntimeError lrte_name1)
      ls_prop_name = "(unknown)"
   End Try
   // Get the value of this built-in document property.
   Try
      ls_prop_value = lole_builtin.Value
   Catch (RuntimeError lrte_value1)
      ls_prop_value = "(unknown)"
   End Try
   
   // List up to ten built-in document property name/value pairs at a time.
   If Mod(li_index,10) <> 1 Then ls_msg += "~r~n~r~n"
   ls_msg += String(li_index,"00") + "  " + ls_prop_name + "~r~n~t" + ls_prop_value
   If Mod(li_index,10) = 0 Then
      MessageBox("Built-in Document Properties",ls_msg)
      ls_msg = ""
   End If
Next

// Are there any remaining built-in document properties that need to be displayed?
If ls_msg <> "" Then
   MessageBox("Built-in Document Properties",ls_msg)
   ls_msg = ""
End If

// We're finished with the built-in document property OLE object.
DESTROY lole_builtin

// Close the Excel workbook.
lole_excelapp.Workbooks.Close
DESTROY lole_workbook

// Clean up before finishing.
DESTROY lole_excelapp

Return 0

Saludos cordiales, John

Comment
  1. Raquel Rodriguez
  2. Tuesday, 22 October 2024 07:11 AM UTC
Hola John,



Muchas gracias por tu contestación. He estado probando la opción que me comentas y sigue sin funcionar. Da el mismo error en la apertura, teniendo en cuenta tus indicaciones.



Un saludo y de nuevo gracias
  1. Helpful
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.