abap2xlsx/demos

zdemo_excel_checker reports issues for all demo programs

Closed this issue · 0 comments

The program zdemo_excel_checker which is used by the contributors after they did a fix, to verify that there are no regressions, is currently reporting regressions everywhere concerning the element <cp:lastModifiedBy> in the file core.xml:
image

For zdemo_excel_comments, we can also see this error:
image

Analysis: this happens when running the tests with a SAP user that is not DEVELOPER.

It can be fixed by adding CLEAR docprops_core-last_modified_by:

    CLEAR: docprops_core-creator,
           docprops_core-description,
           docprops_core-last_modified_by, "<==== add this line
           docprops_core-created,
           docprops_core-modified.

and by adding this code to clear the XML element value <comments ...><authors><author> in the files xl/comments*.xml:

    LOOP AT zip->files ASSIGNING <file>
        WHERE name CP 'xl/comments*.xml'.

      zip->get(
        EXPORTING
          name                    = <file>-name
        IMPORTING
          content                 = content
        EXCEPTIONS
          zip_index_error         = 1
          zip_decompression_error = 2
          OTHERS                  = 3 ).
      IF sy-subrc <> 0.
        RAISE EXCEPTION TYPE zcx_excel EXPORTING error = |{ <file>-name } not found|.
      ENDIF.

      lo_ixml = cl_ixml=>create( ).
      lo_streamfactory = lo_ixml->create_stream_factory( ).
      lo_istream = lo_streamfactory->create_istream_xstring( content ).
      lo_document = lo_ixml->create_document( ).
      lo_parser = lo_ixml->create_parser(
                  document       = lo_document
                  istream        = lo_istream
                  stream_factory = lo_streamfactory ).
      lo_parser->parse( ).

      lo_element = lo_document->find_from_path_ns(
                  default_uri = ''
                  path = '/"http://schemas.openxmlformats.org/spreadsheetml/2006/main:comments"'
                      && '/"http://schemas.openxmlformats.org/spreadsheetml/2006/main:authors"'
                      && '/"http://schemas.openxmlformats.org/spreadsheetml/2006/main:author"' ).
      IF lo_element IS BOUND.
        lo_element->set_value( '' ).
      ENDIF.

      CLEAR content.
      lo_ostream = lo_streamfactory->create_ostream_xstring( content ).
      lo_renderer = lo_ixml->create_renderer(
                  document = lo_document
                  ostream  = lo_ostream ).
      lo_renderer->render( ).

      ls_file-name = <file>-name.
      ls_file-content = content.
      APPEND ls_file TO lt_file.

    ENDLOOP.