From e029864bbb80586e5e333b0ea8a6af93c44678ea Mon Sep 17 00:00:00 2001 From: sandraros <34005250+sandraros@users.noreply.github.com> Date: Sat, 3 Jul 2021 19:07:18 +0200 Subject: [PATCH] Wrongly changed file size #722 (#741) * Fix #722 worksheet dimension (last empty rows) * Fix #722 reduce DIFF quantity (indentations) Co-authored-by: Jane Doe Co-authored-by: Abo --- src/zcl_excel_reader_2007.clas.abap | 11 +++-------- src/zcl_excel_row.clas.abap | 12 ++++++++++++ src/zcl_excel_rows.clas.abap | 27 +++++++++++++++++++++++++++ src/zcl_excel_worksheet.clas.abap | 10 ++++++++-- src/zcl_excel_writer_2007.clas.abap | 13 ++++--------- 5 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/zcl_excel_reader_2007.clas.abap b/src/zcl_excel_reader_2007.clas.abap index e42e962..f624717 100644 --- a/src/zcl_excel_reader_2007.clas.abap +++ b/src/zcl_excel_reader_2007.clas.abap @@ -2410,15 +2410,11 @@ METHOD load_worksheet. lv_max_col = lv_index. ENDIF. lv_cell_row = ls_row-r. - IF ls_row-customheight = '1' - OR ls_row-collapsed = lc_xml_attr_true - OR ls_row-collapsed = lc_xml_attr_true_int - OR ls_row-hidden = lc_xml_attr_true - OR ls_row-hidden = lc_xml_attr_true_int - OR ls_row-outlinelevel > '0'. lo_row = io_worksheet->get_row( lv_cell_row ). IF ls_row-customheight = '1'. - lo_row->set_row_height( ls_row-ht ). + lo_row->set_row_height( ip_row_height = ls_row-ht ip_custom_height = abap_true ). + ELSE. + lo_row->set_row_height( ip_row_height = ls_row-ht ip_custom_height = abap_false ). ENDIF. IF ls_row-collapsed = lc_xml_attr_true @@ -2439,7 +2435,6 @@ METHOD load_worksheet. lo_row->set_outline_level( lv_outline_level ). ENDIF. ENDIF. - ENDIF. lo_ixml_cells = lo_ixml_row_elem->get_elements_by_tag_name( name = 'c' ). lo_ixml_iterator2 = lo_ixml_cells->create_iterator( ). diff --git a/src/zcl_excel_row.clas.abap b/src/zcl_excel_row.clas.abap index 292c9ef..f194f55 100644 --- a/src/zcl_excel_row.clas.abap +++ b/src/zcl_excel_row.clas.abap @@ -24,6 +24,9 @@ public section. methods GET_ROW_HEIGHT returning value(R_ROW_HEIGHT) type FLOAT . + methods GET_CUSTOM_HEIGHT + returning + value(R_CUSTOM_HEIGHT) type ABAP_BOOL . methods GET_ROW_INDEX returning value(R_ROW_INDEX) type INT4 . @@ -46,6 +49,7 @@ public section. methods SET_ROW_HEIGHT importing !IP_ROW_HEIGHT type SIMPLE + !IP_CUSTOM_HEIGHT type abap_bool default abap_true raising ZCX_EXCEL . methods SET_ROW_INDEX @@ -70,6 +74,7 @@ private section. data OUTLINE_LEVEL type INT4 value 0. "#EC NOTEXT . . . . . . . . . " . data COLLAPSED type abap_bool . data XF_INDEX type INT4 . + data CUSTOM_HEIGHT type abap_bool . ENDCLASS. @@ -87,6 +92,7 @@ method CONSTRUCTOR. " set row dimension as unformatted by default me->xf_index = 0. + me->custom_height = abap_false. endmethod. @@ -150,6 +156,11 @@ method GET_ROW_HEIGHT. endmethod. + METHOD GET_CUSTOM_HEIGHT. + r_custom_height = me->custom_height. + ENDMETHOD. + + method GET_ROW_INDEX. r_row_index = me->row_index. endmethod. @@ -203,6 +214,7 @@ method SET_ROW_HEIGHT. CATCH cx_sy_conversion_no_number. zcx_excel=>raise_text( 'Unable to interpret ip_row_height as number' ). ENDTRY. + me->custom_height = ip_custom_height. endmethod. diff --git a/src/zcl_excel_rows.clas.abap b/src/zcl_excel_rows.clas.abap index 8202c77..4bc0085 100644 --- a/src/zcl_excel_rows.clas.abap +++ b/src/zcl_excel_rows.clas.abap @@ -42,6 +42,12 @@ class ZCL_EXCEL_ROWS definition methods SIZE returning value(EP_SIZE) type I . + methods GET_MIN_INDEX + returning + value(EP_INDEX) type I . + methods GET_MAX_INDEX + returning + value(EP_INDEX) type I . protected section. *"* private components of class ZABAP_EXCEL_RANGES *"* do not include other source files here!!! @@ -111,4 +117,25 @@ CLASS ZCL_EXCEL_ROWS IMPLEMENTATION. method SIZE. EP_SIZE = ROWS->SIZE( ). endmethod. "SIZE + + METHOD get_min_index. + FIELD-SYMBOLS: TYPE mty_s_hashed_row. + + LOOP AT rows_hasehd ASSIGNING . + IF ep_index = 0 OR -row_index < ep_index. + ep_index = -row_index. + ENDIF. + ENDLOOP. + ENDMETHOD. + + METHOD get_max_index. + FIELD-SYMBOLS: TYPE mty_s_hashed_row. + + LOOP AT rows_hasehd ASSIGNING . + IF -row_index > ep_index. + ep_index = -row_index. + ENDIF. + ENDLOOP. + ENDMETHOD. + ENDCLASS. diff --git a/src/zcl_excel_worksheet.clas.abap b/src/zcl_excel_worksheet.clas.abap index c45b3a5..d9dcd13 100644 --- a/src/zcl_excel_worksheet.clas.abap +++ b/src/zcl_excel_worksheet.clas.abap @@ -5562,10 +5562,16 @@ CLASS zcl_excel_worksheet IMPLEMENTATION. CHECK sheet_content IS NOT INITIAL. - upper_cell-cell_row = zcl_excel_common=>c_excel_sheet_max_row. + upper_cell-cell_row = rows->get_min_index( ). + IF upper_cell-cell_row = 0. + upper_cell-cell_row = zcl_excel_common=>c_excel_sheet_max_row. + ENDIF. upper_cell-cell_column = zcl_excel_common=>c_excel_sheet_max_col. - lower_cell-cell_row = zcl_excel_common=>c_excel_sheet_min_row. + lower_cell-cell_row = rows->get_max_index( ). + IF lower_cell-cell_row = 0. + lower_cell-cell_row = zcl_excel_common=>c_excel_sheet_min_row. + ENDIF. lower_cell-cell_column = zcl_excel_common=>c_excel_sheet_min_col. LOOP AT sheet_content INTO ls_sheet_content. diff --git a/src/zcl_excel_writer_2007.clas.abap b/src/zcl_excel_writer_2007.clas.abap index daa512b..9ac1a75 100644 --- a/src/zcl_excel_writer_2007.clas.abap +++ b/src/zcl_excel_writer_2007.clas.abap @@ -5846,15 +5846,11 @@ METHOD create_xl_sheet_sheet_data. lo_element_2->set_attribute_ns( name = lc_xml_attr_spans value = lv_value ). lo_row = io_worksheet->get_row( -cell_row ). - " Do we need the row dimension attributes? - IF lo_row->get_row_height( ) >= 0 OR - lo_row->get_collapsed( io_worksheet ) = abap_true OR - lo_row->get_outline_level( io_worksheet ) > 0 OR - lo_row->get_xf_index( ) <> 0 OR - l_autofilter_hidden = abap_true. - " Row dimensions - IF lo_row->get_row_height( ) >= 0. + " Row dimensions + IF lo_row->get_custom_height( ) = abap_true. lo_element_2->set_attribute_ns( name = 'customHeight' value = '1' ). + ENDIF. + IF lo_row->get_row_height( ) >= 0. lv_value = lo_row->get_row_height( ). lo_element_2->set_attribute_ns( name = 'ht' value = lv_value ). ENDIF. @@ -5875,7 +5871,6 @@ METHOD create_xl_sheet_sheet_data. lo_element_2->set_attribute_ns( name = 's' value = lv_value ). lo_element_2->set_attribute_ns( name = 'customFormat' value = '1' ). ENDIF. - ENDIF. IF lt_values IS INITIAL. " no values attached to autofilter " issue #368 autofilter filtering too much CLEAR l_autofilter_hidden. ELSE.