Skip to content

Commit

Permalink
Merge branch 'master' into New-solution-instead-of-PR-abap2xlsx#743
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf committed Jun 21, 2021
2 parents 9838ebc + 8c92b12 commit 8a16f67
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
20 changes: 15 additions & 5 deletions abaplint.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
"globalMacros": []
},
"rules": {
"dangerous_statement": true,
"db_operation_in_loop": false,
"identical_descriptions": false,
"intf_referencing_clas": false,
"max_one_method_parameter_per_line": false,
"method_implemented_twice": true,
"modify_only_own_db_tables": false,
"no_yoda_conditions": false,
"parser_702_chaining": true,
"prefer_raise_exception_new": true,
"select_add_order_by": false,
"select_performance": false,
"uncaught_exception": false,
"unsecure_fae": false,
"use_class_based_exceptions": false,
"call_transaction_authority_check": true,
"function_module_recommendations": false,
"identical_contents": false,
Expand Down Expand Up @@ -57,13 +72,8 @@
"ambiguous_statement": false,
"avoid_use": {
"define": false,
"endselect": false,
"execSQL": true,
"describeLines": false,
"kernelCall": true,
"communication": true,
"statics": false,
"systemCall": true,
"defaultKey": false,
"break": true
},
Expand Down
1 change: 1 addition & 0 deletions src/demos/zdemo_excel22.prog.abap
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ START-OF-SELECTION.
<fs_field_catalog>-position = 1.
<fs_field_catalog>-dynpfld = abap_true.
<fs_field_catalog>-style = lo_style->get_guid( ).
<fs_field_catalog>-scrtext_m = |Flight\r\nNumber|. " Demonstrates header on 2 lines
WHEN 'FLDATE'.
<fs_field_catalog>-position = 2.
<fs_field_catalog>-dynpfld = abap_true.
Expand Down
2 changes: 1 addition & 1 deletion src/zcl_excel_common.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ method ENCRYPT_PASSWORD.

DATA lv_pwd TYPE zexcel_aes_password.

lv_pwd = i_pwd(15).
lv_pwd = i_pwd.

lv_pwd_len = STRLEN( lv_pwd ).
lv_curr_offset = lv_pwd_len - 1.
Expand Down
11 changes: 11 additions & 0 deletions src/zcl_excel_worksheet.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -5019,6 +5019,17 @@ CLASS zcl_excel_worksheet IMPLEMENTATION.
me->hyperlinks->add( ip_hyperlink ).
ENDIF.

IF lv_value CS '_x'.
" Issue #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.

* Begin of change issue #152 - don't touch exisiting style if only value is passed
* Read table moved up, so that current style may be evaluated
* lv_column = zcl_excel_common=>convert_column2int( ip_column ).
Expand Down
25 changes: 25 additions & 0 deletions src/zcl_excel_writer_2007.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -7140,6 +7140,31 @@ METHOD create_xl_table.
lo_element2->set_attribute_ns( name = 'id'
value = lv_value ).
lv_value = ls_fieldcat-scrtext_l.

" The text "_x...._", with "_x" not "_X", with exactly 4 ".", each being 0-9 a-f or A-F (case insensitive), is interpreted
" like Unicode character U+.... (e.g. "_x0041_" is rendered like "A") is for characters.
" To not interpret it, Excel replaces the first "_" is to be replaced with "_x005f_".
IF lv_value CS '_x'.
REPLACE ALL OCCURRENCES OF REGEX '_(x[0-9a-fA-F]{4}_)' IN lv_value WITH '_x005f_$1' RESPECTING CASE.
ENDIF.

" XML chapter 2.2: Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
" NB: although Excel supports _x0009_, it's not rendered except if you edit the text.
" Excel considers _x000d_ as being an error (_x000a_ is sufficient and rendered).
sy-fdpos = 0.
WHILE sy-fdpos < strlen( lv_value ).
IF lv_value CA |\r\n\t|. "table_special_characters.
CASE lv_value+sy-fdpos(1).
WHEN cl_abap_char_utilities=>newline.
REPLACE SECTION OFFSET sy-fdpos LENGTH 1 OF lv_value WITH '_x000a_'.
WHEN cl_abap_char_utilities=>cr_lf(1).
REPLACE SECTION OFFSET sy-fdpos LENGTH 1 OF lv_value WITH ``.
WHEN cl_abap_char_utilities=>horizontal_tab.
REPLACE SECTION OFFSET sy-fdpos LENGTH 1 OF lv_value WITH '_x0009_'.
ENDCASE.
ENDIF.
ENDWHILE.

lo_element2->set_attribute_ns( name = 'name'
value = lv_value ).

Expand Down

0 comments on commit 8a16f67

Please sign in to comment.