From 7fa137bc943974e2fc7923d1b306a4959f331814 Mon Sep 17 00:00:00 2001 From: sandraros <34005250+sandraros@users.noreply.github.com> Date: Sun, 9 Jan 2022 13:07:22 +0100 Subject: [PATCH] ip_style TYPE any + add_new_style( io_clone_of = ) (#929) * ip_style TYPE any + add_new_style( io_clone_of = ) * zdemo_excel2 instead of zdemo_excel1 * Update zcl_excel_worksheet.clas.abap * Unit tests added + fix demo 2 Co-authored-by: sandraros Co-authored-by: Abo --- src/demos/zdemo_excel2.prog.abap | 276 ++++++------------ src/zcl_excel.clas.abap | 5 +- src/zcl_excel_style.clas.abap | 44 ++- src/zcl_excel_worksheet.clas.abap | 66 ++++- src/zcl_excel_worksheet.clas.testclasses.abap | 126 ++++++++ 5 files changed, 322 insertions(+), 195 deletions(-) diff --git a/src/demos/zdemo_excel2.prog.abap b/src/demos/zdemo_excel2.prog.abap index b4972f9..f0a1f2d 100644 --- a/src/demos/zdemo_excel2.prog.abap +++ b/src/demos/zdemo_excel2.prog.abap @@ -8,37 +8,31 @@ REPORT zdemo_excel2. -DATA: lo_excel TYPE REF TO zcl_excel, - lo_worksheet TYPE REF TO zcl_excel_worksheet, - lo_style_bold TYPE REF TO zcl_excel_style, - lo_style_underline TYPE REF TO zcl_excel_style, - lo_style_filled TYPE REF TO zcl_excel_style, - lo_style_border TYPE REF TO zcl_excel_style, - lo_style_button TYPE REF TO zcl_excel_style, - lo_border_dark TYPE REF TO zcl_excel_style_border, - lo_border_light TYPE REF TO zcl_excel_style_border. - -DATA: lv_style_bold_guid TYPE zexcel_cell_style, - lv_style_underline_guid TYPE zexcel_cell_style, - lv_style_filled_guid TYPE zexcel_cell_style, - lv_style_filled_green_guid TYPE zexcel_cell_style, - lv_style_border_guid TYPE zexcel_cell_style, - lv_style_button_guid TYPE zexcel_cell_style, - lv_style_filled_turquoise_guid TYPE zexcel_cell_style, - lv_style_gr_cornerlb_guid TYPE zexcel_cell_style, - lv_style_gr_cornerlt_guid TYPE zexcel_cell_style, - lv_style_gr_cornerrb_guid TYPE zexcel_cell_style, - lv_style_gr_cornerrt_guid TYPE zexcel_cell_style, - lv_style_gr_horizontal90_guid TYPE zexcel_cell_style, - lv_style_gr_horizontal270_guid TYPE zexcel_cell_style, - lv_style_gr_horizontalb_guid TYPE zexcel_cell_style, - lv_style_gr_vertical_guid TYPE zexcel_cell_style, - lv_style_gr_vertical2_guid TYPE zexcel_cell_style, - lv_style_gr_fromcenter_guid TYPE zexcel_cell_style, - lv_style_gr_diagonal45_guid TYPE zexcel_cell_style, - lv_style_gr_diagonal45b_guid TYPE zexcel_cell_style, - lv_style_gr_diagonal135_guid TYPE zexcel_cell_style, - lv_style_gr_diagonal135b_guid TYPE zexcel_cell_style. +DATA: lo_excel TYPE REF TO zcl_excel, + lo_worksheet TYPE REF TO zcl_excel_worksheet, + lo_style_bold TYPE REF TO zcl_excel_style, + lo_style_underline TYPE REF TO zcl_excel_style, + lo_style_filled TYPE REF TO zcl_excel_style, + lo_style_filled_green TYPE REF TO zcl_excel_style, + lo_style_filled_turquoise TYPE REF TO zcl_excel_style, + lo_style_border TYPE REF TO zcl_excel_style, + lo_style_button TYPE REF TO zcl_excel_style, + lo_border_dark TYPE REF TO zcl_excel_style_border, + lo_border_light TYPE REF TO zcl_excel_style_border, + lo_style_gr_cornerlb TYPE REF TO zcl_excel_style, + lo_style_gr_cornerlt TYPE REF TO zcl_excel_style, + lo_style_gr_cornerrb TYPE REF TO zcl_excel_style, + lo_style_gr_cornerrt TYPE REF TO zcl_excel_style, + lo_style_gr_horizontal90 TYPE REF TO zcl_excel_style, + lo_style_gr_horizontal270 TYPE REF TO zcl_excel_style, + lo_style_gr_horizontalb TYPE REF TO zcl_excel_style, + lo_style_gr_vertical TYPE REF TO zcl_excel_style, + lo_style_gr_vertical2 TYPE REF TO zcl_excel_style, + lo_style_gr_fromcenter TYPE REF TO zcl_excel_style, + lo_style_gr_diagonal45 TYPE REF TO zcl_excel_style, + lo_style_gr_diagonal45b TYPE REF TO zcl_excel_style, + lo_style_gr_diagonal135 TYPE REF TO zcl_excel_style, + lo_style_gr_diagonal135b TYPE REF TO zcl_excel_style. DATA: lv_file TYPE xstring, lv_bytecount TYPE i, @@ -74,7 +68,6 @@ START-OF-SELECTION. lo_style_bold->font->name = zcl_excel_style_font=>c_name_arial. lo_style_bold->font->scheme = zcl_excel_style_font=>c_scheme_none. lo_style_bold->font->color-rgb = zcl_excel_style_color=>c_red. - lv_style_bold_guid = lo_style_bold->get_guid( ). " Create an underline double style lo_style_underline = lo_excel->add_new_style( ). lo_style_underline->font->underline = abap_true. @@ -82,225 +75,148 @@ START-OF-SELECTION. lo_style_underline->font->name = zcl_excel_style_font=>c_name_roman. lo_style_underline->font->scheme = zcl_excel_style_font=>c_scheme_none. lo_style_underline->font->family = zcl_excel_style_font=>c_family_roman. - lv_style_underline_guid = lo_style_underline->get_guid( ). " Create filled style yellow lo_style_filled = lo_excel->add_new_style( ). lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. lo_style_filled->fill->fgcolor-theme = zcl_excel_style_color=>c_theme_accent6. - lv_style_filled_guid = lo_style_filled->get_guid( ). " Create border with button effects lo_style_button = lo_excel->add_new_style( ). lo_style_button->borders->right = lo_border_dark. lo_style_button->borders->down = lo_border_dark. lo_style_button->borders->left = lo_border_light. lo_style_button->borders->top = lo_border_light. - lv_style_button_guid = lo_style_button->get_guid( ). "Create style with border lo_style_border = lo_excel->add_new_style( ). lo_style_border->borders->allborders = lo_border_dark. lo_style_border->borders->diagonal = lo_border_dark. lo_style_border->borders->diagonal_mode = zcl_excel_style_borders=>c_diagonal_both. - lv_style_border_guid = lo_style_border->get_guid( ). " Create filled style green - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_green. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_filled_green_guid = lo_style_filled->get_guid( ). + lo_style_filled_green = lo_excel->add_new_style( ). + lo_style_filled_green->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled_green->fill->fgcolor-rgb = zcl_excel_style_color=>c_green. + lo_style_filled_green->font->name = zcl_excel_style_font=>c_name_cambria. + lo_style_filled_green->font->scheme = zcl_excel_style_font=>c_scheme_major. " Create filled with gradients - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_cornerlb. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_cornerlb_guid = lo_style_filled->get_guid( ). + lo_style_gr_cornerlb = lo_excel->add_new_style( ). + lo_style_gr_cornerlb->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_cornerlb. + lo_style_gr_cornerlb->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. + lo_style_gr_cornerlb->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. + lo_style_gr_cornerlb->font->name = zcl_excel_style_font=>c_name_cambria. + lo_style_gr_cornerlb->font->scheme = zcl_excel_style_font=>c_scheme_major. - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_cornerlt. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_cornerlt_guid = lo_style_filled->get_guid( ). + lo_style_gr_cornerlt = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_cornerlt->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_cornerlt. - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_cornerrb. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_cornerrb_guid = lo_style_filled->get_guid( ). + lo_style_gr_cornerrb = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_cornerrb->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_cornerrb. - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_cornerrt. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_cornerrt_guid = lo_style_filled->get_guid( ). + lo_style_gr_cornerrt = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_cornerrt->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_cornerrt. - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_horizontal90. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_horizontal90_guid = lo_style_filled->get_guid( ). + lo_style_gr_horizontal90 = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_horizontal90->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_horizontal90. - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_horizontal270. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_horizontal270_guid = lo_style_filled->get_guid( ). + lo_style_gr_horizontal270 = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_horizontal270->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_horizontal270. + lo_style_gr_horizontalb = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_horizontalb->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_horizontalb. - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_horizontalb. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_horizontalb_guid = lo_style_filled->get_guid( ). + lo_style_gr_vertical = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_vertical->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_vertical. + lo_style_gr_vertical2 = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_vertical2->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_vertical. + lo_style_gr_vertical2->fill->fgcolor-rgb = zcl_excel_style_color=>c_white. + lo_style_gr_vertical2->fill->bgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_vertical. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_vertical_guid = lo_style_filled->get_guid( ). + lo_style_gr_fromcenter = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_fromcenter->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_fromcenter. + + lo_style_gr_diagonal45 = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_diagonal45->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_diagonal45. + + lo_style_gr_diagonal45b = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_diagonal45b->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_diagonal45b. + + lo_style_gr_diagonal135 = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_diagonal135->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_diagonal135. + + lo_style_gr_diagonal135b = lo_excel->add_new_style( io_clone_of = lo_style_gr_cornerlb ). + lo_style_gr_diagonal135b->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_diagonal135b. - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_vertical. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_vertical2_guid = lo_style_filled->get_guid( ). - - - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_fromcenter. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_fromcenter_guid = lo_style_filled->get_guid( ). - - - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_diagonal45. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_diagonal45_guid = lo_style_filled->get_guid( ). - - - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_diagonal45b. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_diagonal45b_guid = lo_style_filled->get_guid( ). - - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_diagonal135. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_diagonal135_guid = lo_style_filled->get_guid( ). - - lo_style_filled = lo_excel->add_new_style( ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_gradient_diagonal135b. - lo_style_filled->fill->fgcolor-rgb = zcl_excel_style_color=>c_blue. - lo_style_filled->fill->bgcolor-rgb = zcl_excel_style_color=>c_white. - lo_style_filled->font->name = zcl_excel_style_font=>c_name_cambria. - lo_style_filled->font->scheme = zcl_excel_style_font=>c_scheme_major. - lv_style_gr_diagonal135b_guid = lo_style_filled->get_guid( ). - - - - " Create filled style turquoise using legacy excel ver <= 2003 palette. (https://code.sdn.sap.com/spaces/abap2xlsx/tickets/92) - lo_style_filled = lo_excel->add_new_style( ). + " Create filled style turquoise using legacy excel ver <= 2003 palette. (https://github.com/abap2xlsx/abap2xlsx/issues/92) + lo_style_filled_turquoise = lo_excel->add_new_style( ). lo_excel->legacy_palette->set_color( "replace built-in color from palette with out custom RGB turquoise ip_index = 16 ip_color = '0040E0D0' ). - lo_style_filled->fill->filltype = zcl_excel_style_fill=>c_fill_solid. - lo_style_filled->fill->fgcolor-indexed = 16. - lv_style_filled_turquoise_guid = lo_style_filled->get_guid( ). + lo_style_filled_turquoise->fill->filltype = zcl_excel_style_fill=>c_fill_solid. + lo_style_filled_turquoise->fill->fgcolor-indexed = 16. " Get active sheet lo_worksheet = lo_excel->get_active_worksheet( ). lo_worksheet->set_title( ip_title = 'Styles' ). lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ). - lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = 'Bold text' ip_style = lv_style_bold_guid ). - lo_worksheet->set_cell( ip_column = 'D' ip_row = 4 ip_value = 'Underlined text' ip_style = lv_style_underline_guid ). - lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'Filled text' ip_style = lv_style_filled_guid ). - lo_worksheet->set_cell( ip_column = 'C' ip_row = 6 ip_value = 'Borders' ip_style = lv_style_border_guid ). - lo_worksheet->set_cell( ip_column = 'D' ip_row = 7 ip_value = 'I''m not a button :)' ip_style = lv_style_button_guid ). - lo_worksheet->set_cell( ip_column = 'B' ip_row = 9 ip_value = 'Modified color for Excel 2003' ip_style = lv_style_filled_turquoise_guid ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = 'Bold text' ip_style = lo_style_bold ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 4 ip_value = 'Underlined text' ip_style = lo_style_underline ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 5 ip_value = 'Filled text' ip_style = lo_style_filled ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 6 ip_value = 'Borders' ip_style = lo_style_border ). + lo_worksheet->set_cell( ip_column = 'D' ip_row = 7 ip_value = 'I''m not a button :)' ip_style = lo_style_button ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 9 ip_value = 'Modified color for Excel 2003' ip_style = lo_style_filled_turquoise ). " Fill the cell and apply one style - lo_worksheet->set_cell( ip_column = 'B' ip_row = 6 ip_value = 'Filled text' ip_style = lv_style_filled_guid ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 6 ip_value = 'Filled text' ip_style = lo_style_filled ). " Change the style - lo_worksheet->set_cell_style( ip_column = 'B' ip_row = 6 ip_style = lv_style_filled_green_guid ). + lo_worksheet->set_cell_style( ip_column = 'B' ip_row = 6 ip_style = lo_style_filled_green ). " Add Style to an empty cell to test Fix for Issue "#44 Exception ZCX_EXCEL thrown when style is set for an empty cell - " https://code.sdn.sap.com/spaces/abap2xlsx/tickets/44-exception-zcx_excel-thrown-when-style-is-set-for-an-empty-cell - lo_worksheet->set_cell_style( ip_column = 'E' ip_row = 6 ip_style = lv_style_filled_green_guid ). + " https://github.com/abap2xlsx/abap2xlsx/issues/44 + lo_worksheet->set_cell_style( ip_column = 'E' ip_row = 6 ip_style = lo_style_filled_green ). - lo_worksheet->set_cell( ip_column = 'B' ip_row = 10 ip_style = lv_style_gr_cornerlb_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_cornerlb ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 10 ip_style = lo_style_gr_cornerlb ip_value = zcl_excel_style_fill=>c_fill_gradient_cornerlb ). lo_row = lo_worksheet->get_row( ip_row = 10 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'C' ip_row = 11 ip_style = lv_style_gr_cornerlt_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_cornerlt ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 11 ip_style = lo_style_gr_cornerlt ip_value = zcl_excel_style_fill=>c_fill_gradient_cornerlt ). lo_row = lo_worksheet->get_row( ip_row = 11 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'B' ip_row = 12 ip_style = lv_style_gr_cornerrb_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_cornerrb ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 12 ip_style = lo_style_gr_cornerrb ip_value = zcl_excel_style_fill=>c_fill_gradient_cornerrb ). lo_row = lo_worksheet->get_row( ip_row = 12 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'C' ip_row = 13 ip_style = lv_style_gr_cornerrt_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_cornerrt ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 13 ip_style = lo_style_gr_cornerrt ip_value = zcl_excel_style_fill=>c_fill_gradient_cornerrt ). lo_row = lo_worksheet->get_row( ip_row = 13 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'B' ip_row = 14 ip_style = lv_style_gr_horizontal90_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_horizontal90 ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 14 ip_style = lo_style_gr_horizontal90 ip_value = zcl_excel_style_fill=>c_fill_gradient_horizontal90 ). lo_row = lo_worksheet->get_row( ip_row = 14 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'C' ip_row = 15 ip_style = lv_style_gr_horizontal270_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_horizontal270 ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 15 ip_style = lo_style_gr_horizontal270 ip_value = zcl_excel_style_fill=>c_fill_gradient_horizontal270 ). lo_row = lo_worksheet->get_row( ip_row = 15 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'B' ip_row = 16 ip_style = lv_style_gr_horizontalb_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_horizontalb ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 16 ip_style = lo_style_gr_horizontalb ip_value = zcl_excel_style_fill=>c_fill_gradient_horizontalb ). lo_row = lo_worksheet->get_row( ip_row = 16 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'C' ip_row = 17 ip_style = lv_style_gr_vertical_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_vertical ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 17 ip_style = lo_style_gr_vertical ip_value = zcl_excel_style_fill=>c_fill_gradient_vertical ). lo_row = lo_worksheet->get_row( ip_row = 17 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'B' ip_row = 18 ip_style = lv_style_gr_vertical2_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_vertical ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 18 ip_style = lo_style_gr_vertical2 ip_value = zcl_excel_style_fill=>c_fill_gradient_vertical ). lo_row = lo_worksheet->get_row( ip_row = 18 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'C' ip_row = 19 ip_style = lv_style_gr_fromcenter_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_fromcenter ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 19 ip_style = lo_style_gr_fromcenter ip_value = zcl_excel_style_fill=>c_fill_gradient_fromcenter ). lo_row = lo_worksheet->get_row( ip_row = 19 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'B' ip_row = 20 ip_style = lv_style_gr_diagonal45_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_diagonal45 ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 20 ip_style = lo_style_gr_diagonal45 ip_value = zcl_excel_style_fill=>c_fill_gradient_diagonal45 ). lo_row = lo_worksheet->get_row( ip_row = 20 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'C' ip_row = 21 ip_style = lv_style_gr_diagonal45b_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_diagonal45b ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 21 ip_style = lo_style_gr_diagonal45b ip_value = zcl_excel_style_fill=>c_fill_gradient_diagonal45b ). lo_row = lo_worksheet->get_row( ip_row = 21 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'B' ip_row = 22 ip_style = lv_style_gr_diagonal135_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_diagonal135 ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 22 ip_style = lo_style_gr_diagonal135 ip_value = zcl_excel_style_fill=>c_fill_gradient_diagonal135 ). lo_row = lo_worksheet->get_row( ip_row = 22 ). lo_row->set_row_height( ip_row_height = 30 ). - lo_worksheet->set_cell( ip_column = 'C' ip_row = 23 ip_style = lv_style_gr_diagonal135b_guid ip_value = zcl_excel_style_fill=>c_fill_gradient_diagonal135b ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 23 ip_style = lo_style_gr_diagonal135b ip_value = zcl_excel_style_fill=>c_fill_gradient_diagonal135b ). lo_row = lo_worksheet->get_row( ip_row = 23 ). lo_row->set_row_height( ip_row_height = 30 ). diff --git a/src/zcl_excel.clas.abap b/src/zcl_excel.clas.abap index db17010..f80e7b1 100644 --- a/src/zcl_excel.clas.abap +++ b/src/zcl_excel.clas.abap @@ -36,6 +36,8 @@ CLASS zcl_excel DEFINITION METHODS add_new_style IMPORTING !ip_guid TYPE zexcel_cell_style OPTIONAL + !io_clone_of TYPE REF TO zcl_excel_style OPTIONAL + PREFERRED PARAMETER !ip_guid RETURNING VALUE(eo_style) TYPE REF TO zcl_excel_style . METHODS add_new_worksheet @@ -234,7 +236,8 @@ CLASS zcl_excel IMPLEMENTATION. * Create default style CREATE OBJECT eo_style EXPORTING - ip_guid = ip_guid. + ip_guid = ip_guid + io_clone_of = io_clone_of. styles->add( eo_style ). DATA: style2 TYPE zexcel_s_stylemapping. diff --git a/src/zcl_excel_style.clas.abap b/src/zcl_excel_style.clas.abap index 1a39478..1fe4446 100644 --- a/src/zcl_excel_style.clas.abap +++ b/src/zcl_excel_style.clas.abap @@ -16,7 +16,8 @@ CLASS zcl_excel_style DEFINITION METHODS constructor IMPORTING - !ip_guid TYPE zexcel_cell_style OPTIONAL . + !ip_guid TYPE zexcel_cell_style OPTIONAL + !io_clone_of TYPE REF TO zcl_excel_style OPTIONAL . METHODS get_guid RETURNING VALUE(ep_guid) TYPE zexcel_cell_style . @@ -51,6 +52,47 @@ CLASS zcl_excel_style IMPLEMENTATION. me->guid = zcl_excel_obsolete_func_wrap=>guid_create( ). ENDIF. + IF io_clone_of IS BOUND. + + font->bold = io_clone_of->font->bold. + font->color = io_clone_of->font->color. + font->family = io_clone_of->font->family. + font->italic = io_clone_of->font->italic. + font->name = io_clone_of->font->name. + font->scheme = io_clone_of->font->scheme. + font->size = io_clone_of->font->size. + font->strikethrough = io_clone_of->font->strikethrough. + font->underline = io_clone_of->font->underline. + font->underline_mode = io_clone_of->font->underline_mode. + + fill->gradtype = io_clone_of->fill->gradtype. + fill->filltype = io_clone_of->fill->filltype. + fill->rotation = io_clone_of->fill->rotation. + fill->fgcolor = io_clone_of->fill->fgcolor. + fill->bgcolor = io_clone_of->fill->bgcolor. + + borders->allborders = io_clone_of->borders->allborders. + borders->diagonal = io_clone_of->borders->diagonal. + borders->diagonal_mode = io_clone_of->borders->diagonal_mode. + borders->down = io_clone_of->borders->down. + borders->left = io_clone_of->borders->left. + borders->right = io_clone_of->borders->right. + borders->top = io_clone_of->borders->top. + + alignment->horizontal = io_clone_of->alignment->horizontal. + alignment->vertical = io_clone_of->alignment->vertical. + alignment->textrotation = io_clone_of->alignment->textrotation. + alignment->wraptext = io_clone_of->alignment->wraptext. + alignment->shrinktofit = io_clone_of->alignment->shrinktofit. + alignment->indent = io_clone_of->alignment->indent. + + number_format->format_code = io_clone_of->number_format->format_code. + + protection->hidden = io_clone_of->protection->hidden. + protection->locked = io_clone_of->protection->locked. + + ENDIF. + ENDMETHOD. diff --git a/src/zcl_excel_worksheet.clas.abap b/src/zcl_excel_worksheet.clas.abap index b0f5373..c44a521 100644 --- a/src/zcl_excel_worksheet.clas.abap +++ b/src/zcl_excel_worksheet.clas.abap @@ -356,10 +356,14 @@ CLASS zcl_excel_worksheet DEFINITION zcx_excel . METHODS get_columns RETURNING - VALUE(eo_columns) TYPE REF TO zcl_excel_columns . + VALUE(eo_columns) TYPE REF TO zcl_excel_columns + RAISING + zcx_excel . METHODS get_columns_iterator RETURNING - VALUE(eo_iterator) TYPE REF TO zcl_excel_collection_iterator . + VALUE(eo_iterator) TYPE REF TO zcl_excel_collection_iterator + RAISING + zcx_excel . METHODS get_style_cond_iterator RETURNING VALUE(eo_iterator) TYPE REF TO zcl_excel_collection_iterator . @@ -491,7 +495,7 @@ CLASS zcl_excel_worksheet DEFINITION !ip_row TYPE zexcel_cell_row OPTIONAL !ip_value TYPE simple OPTIONAL !ip_formula TYPE zexcel_cell_formula OPTIONAL - !ip_style TYPE zexcel_cell_style OPTIONAL + !ip_style TYPE any OPTIONAL !ip_hyperlink TYPE REF TO zcl_excel_hyperlink OPTIONAL !ip_data_type TYPE zexcel_cell_data_type OPTIONAL !ip_abap_type TYPE abap_typekind OPTIONAL @@ -512,7 +516,7 @@ CLASS zcl_excel_worksheet DEFINITION !ip_columnrow TYPE csequence OPTIONAL !ip_column TYPE simple OPTIONAL !ip_row TYPE zexcel_cell_row OPTIONAL - !ip_style TYPE zexcel_cell_style + !ip_style TYPE any RAISING zcx_excel . METHODS set_column_width @@ -537,7 +541,7 @@ CLASS zcl_excel_worksheet DEFINITION !ip_column_end TYPE simple OPTIONAL !ip_row TYPE zexcel_cell_row OPTIONAL !ip_row_to TYPE zexcel_cell_row OPTIONAL - !ip_style TYPE zexcel_cell_style OPTIONAL "added parameter + !ip_style TYPE any OPTIONAL !ip_value TYPE simple OPTIONAL "added parameter !ip_formula TYPE zexcel_cell_formula OPTIONAL "added parameter RAISING @@ -570,8 +574,8 @@ CLASS zcl_excel_worksheet DEFINITION METHODS set_table IMPORTING !ip_table TYPE STANDARD TABLE - !ip_hdr_style TYPE zexcel_cell_style OPTIONAL - !ip_body_style TYPE zexcel_cell_style OPTIONAL + !ip_hdr_style TYPE any OPTIONAL + !ip_body_style TYPE any OPTIONAL !ip_table_title TYPE string !ip_top_left_column TYPE zexcel_cell_column_alpha DEFAULT 'B' !ip_top_left_row TYPE zexcel_cell_row DEFAULT 3 @@ -601,7 +605,7 @@ CLASS zcl_excel_worksheet DEFINITION !ip_column_end TYPE simple OPTIONAL !ip_row TYPE zexcel_cell_row OPTIONAL !ip_row_to TYPE zexcel_cell_row OPTIONAL - !ip_style TYPE zexcel_cell_style OPTIONAL + !ip_style TYPE any OPTIONAL RAISING zcx_excel . METHODS set_area_formula @@ -623,7 +627,7 @@ CLASS zcl_excel_worksheet DEFINITION !ip_column_end TYPE simple OPTIONAL !ip_row TYPE zexcel_cell_row OPTIONAL !ip_row_to TYPE zexcel_cell_row OPTIONAL - !ip_style TYPE zexcel_cell_style + !ip_style TYPE any !ip_merge TYPE abap_bool OPTIONAL RAISING zcx_excel . @@ -636,7 +640,7 @@ CLASS zcl_excel_worksheet DEFINITION !ip_row_to TYPE zexcel_cell_row OPTIONAL !ip_value TYPE simple OPTIONAL !ip_formula TYPE zexcel_cell_formula OPTIONAL - !ip_style TYPE zexcel_cell_style OPTIONAL + !ip_style TYPE any OPTIONAL !ip_hyperlink TYPE REF TO zcl_excel_hyperlink OPTIONAL !ip_data_type TYPE zexcel_cell_data_type OPTIONAL !ip_abap_type TYPE abap_typekind OPTIONAL @@ -766,6 +770,13 @@ CLASS zcl_excel_worksheet DEFINITION ep_row_to TYPE zexcel_cell_row RAISING zcx_excel. + CLASS-METHODS normalize_style_parameter + IMPORTING + !ip_style_or_guid TYPE any + RETURNING + VALUE(rv_guid) TYPE zexcel_cell_style + RAISING + zcx_excel . METHODS print_title_set_range . METHODS update_dimension_range RAISING @@ -2970,6 +2981,35 @@ CLASS zcl_excel_worksheet IMPLEMENTATION. ENDMETHOD. + METHOD normalize_style_parameter. + + DATA: lo_style_type TYPE REF TO cl_abap_typedescr. + FIELD-SYMBOLS: +