¡Caminando hacia el éxito!

Aprende en Comunidad

Avalados por :

Como resolver a exceção upload_ole = 2 ao ler um arquivo do Excel

  • Creado 01/03/2024
  • Modificado 01/03/2024
  • 18 Vistas
0
Cargando...

Olá pessoal, estou usando esta função para ler um arquivo do Excel, no entanto, estou recebendo a exceção upload_ole = 2, por que isso acontece? Aqui está um trecho de código:

...

Pedro Pascal
Se unió el 07/03/2018
Pinterest
Telegram
Linkedin
Whatsapp

4 Respuestas

0
Cargando...

Olá Ali,

Tente usar o código abaixo para sua solicitação.

Espero que isso resolva o seu problema....


    FORM p_upload_data .
    DATA : gd_scol   TYPE i VALUE '1',
            gd_srow   TYPE i VALUE '2',
            gd_ecol   TYPE i VALUE '5',
            gd_erow   TYPE i VALUE '60000'.

    DATA: it_tab TYPE filetable,
          gd_subrc TYPE i.

    DATA : lt_intern TYPE  kcde_cells OCCURS 0 WITH HEADER LINE.

    DATA : ld_index TYPE i.
    FIELD-SYMBOLS : <fs> .

    CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
      EXPORTING
        filename                = p_path
        i_begin_col             = gd_scol
        i_begin_row             = gd_srow
        i_end_col               = gd_ecol
        i_end_row               = gd_erow
      TABLES
        intern                  = lt_intern
      EXCEPTIONS
        inconsistent_parameters = 1
        upload_ole              = 2
        OTHERS                  = 3.
    IF sy-subrc <> 0.
      FORMAT COLOR COL_BACKGROUND INTENSIFIED.
      WRITE:/ 'Erro ao carregar o arquivo'.
      EXIT.
    ENDIF.

    IF lt_intern[] IS INITIAL.
      FORMAT COLOR COL_BACKGROUND INTENSIFIED.
      WRITE:/ 'Nenhum dado foi carregado'.
      EXIT.
    ELSE.
      SORT lt_intern BY row col.
      LOOP AT lt_intern.
        MOVE lt_intern-col TO ld_index.
        ASSIGN 
            
Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019
0
Cargando...

Olá Ali Sanchez ,

Primeiro feche sua planilha do Excel antes de executar seu programa.

Veja o código a seguir.

FORM get_filddata .

  file = 'C:\Documents and Settings\maheswari.chegu\Desktop\Materialtype.XLS'.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = file
      i_begin_col             = '1'
      i_begin_row             = '1'
      i_end_col               = '5'
      i_end_row               = '6000'
    TABLES
      intern                  = xcel
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.

  LOOP AT xcel.

    CASE xcel-col.
      WHEN '0001'.
        itab-fld1 = xcel-value.
      WHEN '0002'.
        itab-fld2 = xcel-value.
      WHEN '0003'.
        itab-fld3 = xcel-value.
      WHEN '0004'.
        itab-fld4 = xcel-value.
      WHEN '0005'.
        itab-fld5 = xcel-value.
    ENDCASE.

    AT END OF row.
      APPEND itab.
      CLEAR itab.
    ENDAT.

  ENDLOOP.

ENDFORM.                    " GET_FILDDATA

Saudações,

Mahi

Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019
0
Cargando...

Olá, aqui está como eu usei este módulo de função...

Tire ajuda disso...

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

exporting

filename = l_file_name

i_begin_col = 1

i_begin_row = 1

i_end_col = 255

i_end_row = 65536

tables

intern = lt_excel

exceptions

inconsistent_parameters = 1

upload_ole = 2

others = 3.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

Obrigado,

Kushagra Sharma

Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019
0
Cargando...

Olá Ali Sanchez ,

Primeiro feche sua planilha do Excel antes de executar seu código.

Exemplo de código para carregar um arquivo do Excel.

FORM get_filddata .

  file = 'C:\Documents and Settings\maheswari.chegu\Desktop\Materialtype.XLS'.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = file
      i_begin_col             = '1'
      i_begin_row             = '1'
      i_end_col               = '5'
      i_end_row               = '6000'
    TABLES
      intern                  = xcel
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.

  LOOP AT xcel.

    CASE xcel-col.
      WHEN '0001'.
        itab-fld1 = xcel-value.
      WHEN '0002'.
        itab-fld2 = xcel-value.
      WHEN '0003'.
        itab-fld3 = xcel-value.
      WHEN '0004'.
        itab-fld4 = xcel-value.
      WHEN '0005'.
        itab-fld5 = xcel-value.
    ENDCASE.

    AT END OF row.
      APPEND itab.
      CLEAR itab.
    ENDAT.

  ENDLOOP.

ENDFORM.                    " GET_FILDDATA

Saudações,

Mahi

Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019

contacto@primeinstitute.com

(+51) 1641 9379
(+57) 1489 6964

© 2024 Copyright. Todos los derechos reservados.

Desarrollado por Prime Institute

¡Hola! Soy Diana, asesora académica de Prime Institute, indícame en que curso estas interesado, saludos!
Hola ¿Puedo ayudarte?