mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 11:06:15 +08:00
+ change_area_style (same as change_cell_style, but for area) (#922)
* + change_area_style New method change_area_style as combination of change_cell_style and set_area_style Co-authored-by: sandraros <sandra.rossi@gmail.com> Co-authored-by: Lars Hvam <larshp@hotmail.com> Co-authored-by: Abo <andrea@borgia.bo.it>
This commit is contained in:
parent
df709ace6a
commit
3df52da4c2
|
@ -2,7 +2,8 @@ REPORT zdemo_excel40.
|
|||
|
||||
|
||||
DATA: lo_excel TYPE REF TO zcl_excel,
|
||||
lo_worksheet TYPE REF TO zcl_excel_worksheet.
|
||||
lo_worksheet TYPE REF TO zcl_excel_worksheet,
|
||||
lo_style_changer TYPE REF TO zif_excel_style_changer.
|
||||
|
||||
DATA: lv_row TYPE zexcel_cell_row,
|
||||
lv_col TYPE i,
|
||||
|
@ -29,41 +30,32 @@ START-OF-SELECTION.
|
|||
* - first 3 rows will have fontcolor set
|
||||
* These marked cells will be used for repeatable rows/columns on printpages
|
||||
*--------------------------------------------------------------------*
|
||||
DO 100 TIMES. " Rows
|
||||
lo_worksheet->set_area(
|
||||
ip_column_start = 1
|
||||
ip_column_end = 20
|
||||
ip_row = 1
|
||||
ip_row_to = 100
|
||||
ip_formula = 'CHAR(64+COLUMN())&TEXT(ROW(),"????????0")'
|
||||
ip_area = lo_worksheet->c_area-whole ).
|
||||
|
||||
lv_row = sy-index .
|
||||
WRITE lv_row TO lv_row_char.
|
||||
|
||||
DO 20 TIMES.
|
||||
|
||||
lv_col = sy-index - 1.
|
||||
CONCATENATE sy-abcde+lv_col(1) lv_row_char INTO lv_value.
|
||||
lv_col = sy-index.
|
||||
lo_worksheet->set_cell( ip_row = lv_row
|
||||
ip_column = lv_col
|
||||
ip_value = lv_value ).
|
||||
|
||||
TRY.
|
||||
IF lv_row <= 3.
|
||||
lo_worksheet->change_cell_style( ip_column = lv_col
|
||||
ip_row = lv_row
|
||||
ip_fill_filltype = zcl_excel_style_fill=>c_fill_solid
|
||||
ip_fill_fgcolor_rgb = zcl_excel_style_color=>c_yellow ).
|
||||
ENDIF.
|
||||
IF lv_col <= 4.
|
||||
lo_worksheet->change_cell_style( ip_column = lv_col
|
||||
ip_row = lv_row
|
||||
ip_font_color_rgb = zcl_excel_style_color=>c_red ).
|
||||
ENDIF.
|
||||
CATCH zcx_excel .
|
||||
ENDTRY.
|
||||
|
||||
ENDDO.
|
||||
|
||||
|
||||
|
||||
ENDDO.
|
||||
lo_style_changer = zcl_excel_style_changer=>create( lo_excel ).
|
||||
lo_style_changer->set_fill_filltype( zcl_excel_style_fill=>c_fill_solid ).
|
||||
lo_style_changer->set_fill_fgcolor_rgb( zcl_excel_style_color=>c_yellow ).
|
||||
lo_worksheet->change_area_style(
|
||||
ip_column_start = 1
|
||||
ip_column_end = 20
|
||||
ip_row = 1
|
||||
ip_row_to = 3
|
||||
ip_style_changer = lo_style_changer ).
|
||||
|
||||
lo_style_changer = zcl_excel_style_changer=>create( lo_excel ).
|
||||
lo_style_changer->set_font_color_rgb( zcl_excel_style_color=>c_red ).
|
||||
lo_worksheet->change_area_style(
|
||||
ip_column_start = 1
|
||||
ip_column_end = 4
|
||||
ip_row = 1
|
||||
ip_row_to = 100
|
||||
ip_style_changer = lo_style_changer ).
|
||||
|
||||
*--------------------------------------------------------------------*
|
||||
* Printsettings
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
<TPOOL>
|
||||
<item>
|
||||
<ID>R</ID>
|
||||
<ENTRY>abap2xlsx Demo: Print settings</ENTRY>
|
||||
<LENGTH>30</LENGTH>
|
||||
<ENTRY>abap2xlsx Demo: Area and Print settings</ENTRY>
|
||||
<LENGTH>39</LENGTH>
|
||||
</item>
|
||||
<item>
|
||||
<ID>S</ID>
|
||||
|
|
|
@ -176,6 +176,15 @@ CLASS zcl_excel_worksheet DEFINITION
|
|||
METHODS calculate_column_widths
|
||||
RAISING
|
||||
zcx_excel .
|
||||
METHODS change_area_style
|
||||
IMPORTING
|
||||
!ip_column_start TYPE simple
|
||||
!ip_column_end TYPE simple OPTIONAL
|
||||
!ip_row TYPE zexcel_cell_row
|
||||
!ip_row_to TYPE zexcel_cell_row OPTIONAL
|
||||
!ip_style_changer TYPE REF TO zif_excel_style_changer
|
||||
RAISING
|
||||
zcx_excel.
|
||||
METHODS change_cell_style
|
||||
IMPORTING
|
||||
!ip_column TYPE simple
|
||||
|
@ -1387,6 +1396,65 @@ CLASS zcl_excel_worksheet IMPLEMENTATION.
|
|||
ENDMETHOD. "CALCULATE_COLUMN_WIDTHS
|
||||
|
||||
|
||||
METHOD change_area_style.
|
||||
|
||||
DATA: lv_row TYPE zexcel_cell_row,
|
||||
lv_row_start TYPE zexcel_cell_row,
|
||||
lv_row_to TYPE zexcel_cell_row,
|
||||
lv_column_int TYPE zexcel_cell_column_alpha,
|
||||
lv_column TYPE zexcel_cell_column_alpha,
|
||||
lv_column_start TYPE zexcel_cell_column_alpha,
|
||||
lv_column_end TYPE zexcel_cell_column_alpha,
|
||||
lv_column_start_int TYPE zexcel_cell_column_alpha,
|
||||
lv_column_end_int TYPE zexcel_cell_column_alpha.
|
||||
|
||||
lv_row_to = ip_row_to.
|
||||
lv_row = ip_row.
|
||||
|
||||
IF lv_row_to IS INITIAL OR ip_row_to IS NOT SUPPLIED.
|
||||
lv_row_to = lv_row.
|
||||
ENDIF.
|
||||
|
||||
lv_column_start = ip_column_start.
|
||||
lv_column_end = ip_column_end.
|
||||
|
||||
IF lv_column_end IS INITIAL OR ip_column_end IS NOT SUPPLIED.
|
||||
lv_column_end = lv_column_start.
|
||||
ENDIF.
|
||||
|
||||
lv_column_start_int = zcl_excel_common=>convert_column2int( lv_column_start ).
|
||||
lv_column_end_int = zcl_excel_common=>convert_column2int( lv_column_end ).
|
||||
|
||||
IF lv_column_start_int > lv_column_end_int OR lv_row > lv_row_to.
|
||||
|
||||
RAISE EXCEPTION TYPE zcx_excel
|
||||
EXPORTING
|
||||
error = 'Wrong Merging Parameters'.
|
||||
|
||||
ENDIF.
|
||||
|
||||
lv_column_int = lv_column_start_int.
|
||||
lv_row_start = lv_row.
|
||||
WHILE lv_column_int <= lv_column_end_int.
|
||||
|
||||
lv_column = zcl_excel_common=>convert_column2alpha( lv_column_int ).
|
||||
lv_row = lv_row_start.
|
||||
|
||||
WHILE lv_row <= lv_row_to.
|
||||
|
||||
ip_style_changer->apply( ip_worksheet = me
|
||||
ip_column = lv_column_int
|
||||
ip_row = lv_row ).
|
||||
|
||||
ADD 1 TO lv_row.
|
||||
ENDWHILE.
|
||||
|
||||
ADD 1 TO lv_column_int.
|
||||
ENDWHILE.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD change_cell_style.
|
||||
|
||||
DATA: changer TYPE REF TO zif_excel_style_changer.
|
||||
|
|
|
@ -189,6 +189,12 @@
|
|||
<LANGU>I</LANGU>
|
||||
<DESCRIPT>Calculate widths for auto-size columns</DESCRIPT>
|
||||
</SEOCOMPOTX>
|
||||
<SEOCOMPOTX>
|
||||
<CLSNAME>ZCL_EXCEL_WORKSHEET</CLSNAME>
|
||||
<CMPNAME>CHANGE_AREA_STYLE</CMPNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>Change area style</DESCRIPT>
|
||||
</SEOCOMPOTX>
|
||||
<SEOCOMPOTX>
|
||||
<CLSNAME>ZCL_EXCEL_WORKSHEET</CLSNAME>
|
||||
<CMPNAME>CHANGE_CELL_STYLE</CMPNAME>
|
||||
|
|
Loading…
Reference in New Issue
Block a user