Page tree
Skip to end of metadata
Go to start of metadata

Are you pissed off by exploring SCN to upload an excel file into abap/ webdynpro…? The entire time end up uploading the excel file by converting it to a tab limited/ comma separated files..? Are you badly hit by performance issues, by using standard function modules for en excel file upload?? Seeking for a better solution to achieve this… here you go… we have a unified way to upload an excel file into abap/ webdynpro…

  • No labels

1 Comment

  1. This document is an excellent introduction, but I ran into problems with the hard-coding of the part numbers with the get_part method. To overcome this, I go through each part in turn, and check its type is the one I want.  This particular code is designed to handle .xlsx with one sheet only.

         CONSTANTS c_workbook_part_class TYPE string VALUE '\CLASS=CL_XLSX_WORKBOOKPART' ##NO_TEXT.
        CONSTANTS c_sharedstrings_part_class TYPE string VALUE '\CLASS=CL_XLSX_SHAREDSTRINGSPART' ##NO_TEXT.
        CONSTANTS c_worksheet_part_class TYPE string VALUE '\CLASS=CL_XLSX_WORKSHEETPART' ##NO_TEXT.
             DATA(package) = cl_xlsx_document=>load_document( iv_data = cl_openxml_helper=>load_local_file( imp_file ) ).
            DATA(sheet_data)  = me->load_xlsx_xml( imp_package = package imp_requested_part = c_worksheet_part_class ).
            DATA(shared_data) = me->load_xlsx_xml( imp_package = package imp_requested_part = c_sharedstrings_part_class ).
       METHOD load_xlsx_xml.

        " Extract the XML from the XLSX file
        DATA(workbook_part) = me->get_part_from_parts( imp_parts = imp_package->get_parts( )    imp_part_class = c_workbook_part_class ).
        DATA(requested_part) = me->get_part_from_parts( imp_parts = workbook_part->get_parts( ) imp_part_class = imp_requested_part ).
        DATA(xml_part_uri) = cl_openxml_parturi=>create_from_partname( requested_part->get_uri( )->get_uri( ) ).
        ret_xml_data = imp_package->get_part_by_uri( xml_part_uri )->get_data( ).

    METHOD get_part_from_parts. 
        DO imp_parts->get_count( ) TIMES.
          DATA(part) = imp_parts->get_part( sy-index - 1 ).
          CHECK cl_abap_typedescr=>describe_by_object_ref( part )->absolute_name EQ imp_part_class.
          IF ret_part IS NOT BOUND.
            ret_part = part.

          ELSE. " Should only be one part we're ever looking for
            IF imp_part_class = c_worksheet_part_class. " If it's more than one worksheet, inform the user
              MESSAGE 'Error reading file. Excel workbooks can only have one worksheet. Please delete the other sheets and try again' TYPE 'E'.

            ELSE. " Something else is wrong with the sheet
              MESSAGE 'Problem reading file. First sheet should contain data, with no hidden sheets' TYPE 'E'.