diff --git a/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk b/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk
index 8ed67fc..a509356 100644
--- a/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk
+++ b/ZA2X/CLAS/ZCL_EXCEL_COMMON.slnk
@@ -46,13 +46,15 @@ public section.
!E_ROW type ZEXCEL_CELL_ROW .
class-methods CONVERT_RANGE2COLUMN_A_ROW
importing
- !I_RANGE type STRING
+ !I_RANGE type CLIKE
exporting
!E_COLUMN_START type ZEXCEL_CELL_COLUMN_ALPHA
!E_COLUMN_END type ZEXCEL_CELL_COLUMN_ALPHA
!E_ROW_START type ZEXCEL_CELL_ROW
!E_ROW_END type ZEXCEL_CELL_ROW
- !E_SHEET type ZEXCEL_SHEET_TITLE .
+ !E_SHEET type CLIKE
+ raising
+ ZCX_EXCEL .
class-methods DATE_TO_EXCEL_STRING
importing
!IP_VALUE type D
@@ -65,9 +67,16 @@ public section.
value(R_ENCRYPTED_PWD) type ZEXCEL_AES_PASSWORD .
class-methods ESCAPE_STRING
importing
- !IP_VALUE type STRING
+ !IP_VALUE type CLIKE
returning
value(EP_ESCAPED_VALUE) type STRING .
+ class-methods UNESCAPE_STRING
+ importing
+ !IV_ESCAPED type CLIKE
+ returning
+ value(EV_UNESCAPED_STRING) type STRING
+ raising
+ ZCX_EXCEL .
class-methods EXCEL_STRING_TO_DATE
importing
!IP_VALUE type ZEXCEL_CELL_VALUE
@@ -905,6 +914,16 @@ CLASS lcl_excel_common_test IMPLEMENTATION.
ENDMETHOD. "split_file
ENDCLASS. "lcl_Excel_Common_Test
+
+
+
+
+
+
+
+
+
+ ABAP
@@ -916,7 +935,7 @@ ENDCLASS. "lcl_Excel_Common_Test
-
+
@@ -966,7 +985,7 @@ ENDCLASS. "lcl_Excel_Common_Test
ENDIF.
endmethod.
-
+
@@ -1179,50 +1198,91 @@ endmethod.
e_row = row_str.
endmethod.
-
-
+
+
-
- method CONVERT_RANGE2COLUMN_A_ROW.
- DATA:
- sheet TYPE string,
- range TYPE string,
- columnrow_start TYPE string,
- columnrow_end TYPE string.
+
+
+ METHOD convert_range2column_a_row.
+*--------------------------------------------------------------------*
+* issue #230 - Pimp my Code
+* - Stefan Schmöcker, (done) 2012-12-07
+* - ...
+* changes: renaming variables to naming conventions
+* aligning code
+* added exceptionclass
+* added errorhandling for invalid range
+* adding comments to explain what we are trying to achieve
+*--------------------------------------------------------------------*
+* issue#241 - error when sheetname contains "!"
+* - sheetname should be returned unescaped
+* - Stefan Schmöcker, 2012-12-07
+* changes: changed coding to support sheetnames with "!"
+* unescaping sheetname
+*--------------------------------------------------------------------*
+* issue#155 - lessening restrictions of input parameters
+* - Stefan Schmöcker, 2012-12-07
+* changes: i_range changed to clike
+* e_sheet changed to clike
+*--------------------------------------------------------------------*
- IF i_range IS INITIAL
- OR NOT i_range CS ':'.
- RETURN.
+ DATA: lv_sheet TYPE string,
+ lv_range TYPE string,
+ lv_columnrow_start TYPE string,
+ lv_columnrow_end TYPE string,
+ lv_errormessage TYPE string. " Can't pass '...'(abc) to exception-class
+
+
+*--------------------------------------------------------------------*
+* Split input range into sheetname and Area
+* 4 cases - a) input empty --> nothing to do
+* - b) sheetname existing - starts with ' example 'Sheet 1'!$B$6:$D$13
+* - c) sheetname existing - does not start with ' example Sheet1!$B$6:$D$13
+* - d) no sheetname - just area example $B$6:$D$13
+*--------------------------------------------------------------------*
+ IF i_range IS INITIAL. " a) input empty --> nothing to do
+ EXIT.
+
+ ELSEIF i_range(1) = `'`. " b) sheetname existing - starts with '
+ FIND REGEX '\![^\!]*$' IN i_range MATCH OFFSET sy-fdpos. " Find last !
+ IF sy-subrc = 0.
+ lv_sheet = i_range(sy-fdpos).
+ ADD 1 TO sy-fdpos.
+ lv_range = i_range.
+ SHIFT lv_range LEFT BY sy-fdpos PLACES.
+ ELSE.
+ lv_errormessage = 'Invalid range'(001).
+ RAISE EXCEPTION TYPE zcx_excel
+ EXPORTING
+ error = lv_errormessage.
+ ENDIF.
+
+ ELSEIF i_range CS '!'. " c) sheetname existing - does not start with '
+ SPLIT i_range AT '!' INTO lv_sheet lv_range.
+
+ ELSE. " d) no sheetname - just area
+ lv_range = i_range.
ENDIF.
- IF i_range CS '!'.
- SPLIT i_range AT '!' INTO sheet range.
- e_sheet = sheet.
- ELSE.
- range = i_range.
- ENDIF.
+ REPLACE ALL OCCURRENCES OF '$' IN lv_range WITH ''.
+ SPLIT lv_range AT ':' INTO lv_columnrow_start lv_columnrow_end.
- REPLACE ALL OCCURRENCES OF '$' IN range WITH ''.
- SPLIT range AT ':' INTO columnrow_start columnrow_end.
+ convert_columnrow2column_a_row( EXPORTING
+ i_columnrow = lv_columnrow_start
+ IMPORTING
+ e_column = e_column_start
+ e_row = e_row_start ).
+ convert_columnrow2column_a_row( EXPORTING
+ i_columnrow = lv_columnrow_end
+ IMPORTING
+ e_column = e_column_end
+ e_row = e_row_end ).
- convert_columnrow2column_a_row(
- EXPORTING
- i_columnrow = columnrow_start
- IMPORTING
- e_column = e_column_start
- e_row = e_row_start
- ).
- convert_columnrow2column_a_row(
- EXPORTING
- i_columnrow = columnrow_end
- IMPORTING
- e_column = e_column_end
- e_row = e_row_end
- ).
-endmethod.
+ e_sheet = unescape_string( lv_sheet ). " Return in unescaped form
+ENDMETHOD.
@@ -1339,24 +1399,57 @@ endmethod.
endmethod.
-
+
- method ESCAPE_STRING.
- DATA lv_value TYPE string.
+ METHOD escape_string.
+*--------------------------------------------------------------------*
+* issue #230 - Pimp my Code
+* - Stefan Schmöcker, (done) 2012-12-08
+* - ...
+* changes: aligning code
+* adding comments to explain what we are trying to achieve
+*--------------------------------------------------------------------*
+* issue#242 - Support escaping for white-spaces
+* - Escaping also necessary when ' encountered in input
+* - Stefan Schmöcker, 2012-12-08
+* changes: switched check if escaping is necessary to regular expression
+* and moved the "REPLACE"
+*--------------------------------------------------------------------*
+* issue#155 - lessening restrictions of input parameters
+* - Stefan Schmöcker, 2012-12-08
+* changes: ip_value changed to clike
+*--------------------------------------------------------------------*
+ DATA: lv_value TYPE string.
+*--------------------------------------------------------------------*
+* There exist various situations when a space will be used to separate
+* different parts of a string. When we have a string consisting spaces
+* that will cause errors unless we "escape" the string by putting ' at
+* the beginning and at the end of the string.
+*--------------------------------------------------------------------*
+
+
+*--------------------------------------------------------------------*
+* When allowing clike-input parameters we might encounter trailing
+* "real" blanks . These are automatically eliminated when moving
+* the input parameter to a string.
+* Now any remaining spaces ( white-spaces or normal spaces ) should
+* trigger the escaping as well as any '
+*--------------------------------------------------------------------*
lv_value = ip_value.
- REPLACE ALL OCCURRENCES OF `'` IN lv_value WITH `''`.
- IF lv_value CP '* *'.
+ FIND REGEX `\s|'` IN lv_value. " \s finds regular and white spaces
+ IF sy-subrc = 0.
+ REPLACE ALL OCCURRENCES OF `'` IN lv_value WITH `''`.
CONCATENATE `'` lv_value `'` INTO lv_value .
ENDIF.
ep_escaped_value = lv_value.
-endmethod.
+ENDMETHOD.
-
+
@@ -1379,7 +1472,7 @@ endmethod.
ENDTRY.
endmethod.
-
+
@@ -1402,7 +1495,7 @@ endmethod.
ENDTRY.
endmethod.
-
+
@@ -1442,7 +1535,7 @@ endmethod.
endmethod.
-
+ METHOD get_fieldcatalog.
@@ -1503,7 +1596,7 @@ endmethod.
ENDMETHOD.
-
+ method NUMBER_TO_EXCEL_STRING.
@@ -1522,7 +1615,7 @@ ENDMETHOD.
ENDIF.
endmethod.
-
+
@@ -1581,7 +1674,7 @@ endmethod.
endmethod.
-
+
@@ -1688,7 +1781,7 @@ endmethod.
endmethod.
-
+
@@ -1775,7 +1868,7 @@ endmethod.
endmethod.
-
+ method TIME_TO_EXCEL_STRING.
@@ -1789,4 +1882,64 @@ endmethod.
ep_value = zcl_excel_common=>number_to_excel_string( ip_value = lv_day_fraction ).
endmethod.
+
+
+
+
+ METHOD unescape_string.
+
+ CONSTANTS lcv_regex TYPE string VALUE `^'[^']` & `|` & " Beginning single ' OR
+ `[^']'$` & `|` & " Trailing single ' OR
+ `[^']'[^']`. " Single ' somewhere in between
+
+
+ DATA: lv_errormessage TYPE string. " Can't pass '...'(abc) to exception-class
+
+*--------------------------------------------------------------------*
+* This method is used to extract the "real" string from an escaped string.
+* An escaped string can be identified by a beginning ' which must be
+* accompanied by a trailing '
+* All '' in between beginning and trailing ' are treated as single '
+*--------------------------------------------------------------------*
+
+*--------------------------------------------------------------------*
+* When allowing clike-input parameters we might encounter trailing
+* "real" blanks . These are automatically eliminated when moving
+* the input parameter to a string.
+*--------------------------------------------------------------------*
+ ev_unescaped_string = iv_escaped. " Pass through if not escaped
+
+ CHECK ev_unescaped_string IS NOT INITIAL. " Nothing to do if empty
+ CHECK ev_unescaped_string(1) = `'`. " Nothing to do if not escaped
+
+*--------------------------------------------------------------------*
+* Remove leading and trailing '
+*--------------------------------------------------------------------*
+ REPLACE REGEX `^'(.*)'$` IN ev_unescaped_string WITH '$1'.
+ IF sy-subrc <> 0.
+ lv_errormessage = 'Input not properly escaped - &'(002).
+ RAISE EXCEPTION TYPE zcx_excel
+ EXPORTING
+ error = lv_errormessage.
+ ENDIF.
+
+*--------------------------------------------------------------------*
+* Any remaining single ' should not be here
+*--------------------------------------------------------------------*
+ FIND REGEX lcv_regex IN ev_unescaped_string.
+ IF sy-subrc = 0.
+ lv_errormessage = 'Input not properly escaped - &'(002).
+ RAISE EXCEPTION TYPE zcx_excel
+ EXPORTING
+ error = lv_errormessage.
+ ENDIF.
+
+*--------------------------------------------------------------------*
+* Replace '' with '
+*--------------------------------------------------------------------*
+ REPLACE ALL OCCURRENCES OF `''` IN ev_unescaped_string WITH `'`.
+
+
+ENDMETHOD.
+