Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cell value "_x0041_" rendered as "A" #761

Closed
sandraros opened this issue Jun 20, 2021 · 0 comments
Closed

Cell value "_x0041_" rendered as "A" #761

sandraros opened this issue Jun 20, 2021 · 0 comments
Labels

Comments

@sandraros
Copy link
Collaborator

Code to reproduce:

DATA: gc_save_file_name TYPE string VALUE 'bug_rendering_value__x0041_.xlsx'.
INCLUDE zdemo_excel_outputopt_incl.
START-OF-SELECTION.
  DATA(lo_excel) = NEW zcl_excel( ).
  DATA(lo_worksheet) = lo_excel->get_active_worksheet( ).
  lo_worksheet->set_cell(
      ip_column = 1
      ip_row    = 1
      ip_value  = |_x0041_| ).
  lcl_output=>output( cl_excel = lo_excel ).

Actual result:
image

Expected result:
image

Technical note:
When _x...._ where each dot is an hexadecimal digit 0-9 a-f A-F, is stored in sharedStrings.xml file, it's a special text interpreted by Excel as being the corresponding Unicode character U+.....
The text _x0041_ should be stored as _x005f_x0041_ in the sharedStrings.xml file so that to be rendered _x0041_, _x005f_ being the character _ (first underscore).

sandraros pushed a commit to sandraros/abap2xlsx that referenced this issue Jun 20, 2021
These lines are added to method SET_CELL of ZCL_EXCEL_WORKSHEET:
    IF lv_value CS '_x'.
      " Issue abap2xlsx#761 value "_x0041_" rendered as "A".
      " "_x...._", where "." is 0-9 a-f or A-F (case insensitive), is an internal value in sharedStrings.xml
      " that Excel uses to store special characters, it's interpreted like Unicode character U+....
      " for instance "_x0041_" is U+0041 which is "A".
      " To not interpret such text, the first underscore is replaced with "_x005f_".
      " The value "_x0041_" is to be stored internally "_x005f_x0041_" so that it's rendered like "_x0041_".
      " Note that REGEX is time consuming, it's why "CS" is used above to improve the performance.
      REPLACE ALL OCCURRENCES OF REGEX '_(x[0-9a-fA-F]{4}_)' IN lv_value WITH '_x005f_$1' RESPECTING CASE.
    ENDIF.
@sandraros sandraros added the bug label Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant