Skip to content

Commit a6ca91c

Browse files
sandrarossandraros
and
sandraros
authored
demo028 CSV no output filtered/hidden rows/columns (#87)
Co-authored-by: sandraros <[email protected]>
1 parent 44031d3 commit a6ca91c

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

src/demo028/zdemo_excel28.prog.abap

+51-1
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@ DATA: lv_file TYPE xstring,
2020
DATA: lv_full_path TYPE string,
2121
lv_workdir TYPE string,
2222
lv_file_separator TYPE c.
23+
24+
DATA lo_autofilter TYPE REF TO zcl_excel_autofilter.
25+
DATA ls_area TYPE zexcel_s_autofilter_area.
26+
DATA lo_row TYPE REF TO zcl_excel_row.
27+
2328
CONSTANTS c_initial_date TYPE d VALUE IS INITIAL.
2429

2530
CONSTANTS: lv_default_file_name TYPE string VALUE '28_HelloWorld.csv'.
2631

27-
PARAMETERS: p_path TYPE string.
32+
PARAMETERS: p_path TYPE string LOWER CASE.
33+
34+
PARAMETERS p_skip_c AS CHECKBOX DEFAULT abap_true.
35+
PARAMETERS p_skip_r AS CHECKBOX DEFAULT abap_true.
36+
PARAMETERS p_xlsx AS CHECKBOX DEFAULT abap_false.
2837

2938
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
3039

@@ -50,11 +59,39 @@ START-OF-SELECTION.
5059
" Get active sheet
5160
lo_worksheet = lo_excel->get_active_worksheet( ).
5261
lo_worksheet->set_title( ip_title = 'Sheet1' ).
62+
lo_worksheet->set_cell( ip_column = 'A' ip_row = 1 ip_value = 'Name' ).
63+
lo_worksheet->set_cell( ip_column = 'B' ip_row = 1 ip_value = 'Value 1' ).
64+
lo_worksheet->set_cell( ip_column = 'C' ip_row = 1 ip_value = 'Value 2' ).
65+
lo_worksheet->set_cell( ip_column = 'D' ip_row = 1 ip_value = 'Column hidden' ).
66+
lo_worksheet->set_cell( ip_column = 'A' ip_row = 2 ip_value = 'Text' ).
5367
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ).
68+
lo_worksheet->set_cell( ip_column = 'A' ip_row = 3 ip_value = 'Date and time' ).
5469
lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = sy-datum ).
5570
lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = sy-uzeit ).
5671
lo_worksheet->set_cell( ip_column = 'A' ip_row = 4 ip_value = 'Initial Date' ).
5772
lo_worksheet->set_cell( ip_column = 'B' ip_row = 4 ip_value = c_initial_date ).
73+
lo_worksheet->set_cell( ip_column = 'A' ip_row = 5 ip_value = 'Row filtered out' ).
74+
lo_worksheet->set_cell( ip_column = 'A' ip_row = 6 ip_value = 'Row hidden' ).
75+
76+
lo_autofilter = lo_excel->add_new_autofilter( io_sheet = lo_worksheet ) .
77+
ls_area-row_start = 1.
78+
ls_area-col_start = 1.
79+
ls_area-row_end = lo_worksheet->get_highest_row( ).
80+
ls_area-col_end = lo_worksheet->get_highest_column( ).
81+
lo_autofilter->set_filter_area( is_area = ls_area ).
82+
lo_autofilter->set_value( i_column = 1 " column A
83+
i_value = 'Text' ).
84+
lo_autofilter->set_value( i_column = 1 " column A
85+
i_value = 'Date and time' ).
86+
lo_autofilter->set_value( i_column = 1 " column A
87+
i_value = 'Initial Date' ).
88+
lo_autofilter->get_filter_area( ).
89+
90+
lo_row = lo_worksheet->get_row( 6 ).
91+
lo_row->set_visible( abap_false ).
92+
93+
lo_column = lo_worksheet->get_column( 'D' ).
94+
lo_column->set_visible( abap_false ).
5895

5996
lo_column = lo_worksheet->get_column( 'B' ).
6097
lo_column->set_width( 11 ).
@@ -68,6 +105,8 @@ START-OF-SELECTION.
68105
zcl_excel_writer_csv=>set_enclosure( ip_value = '''' ).
69106
zcl_excel_writer_csv=>set_endofline( ip_value = cl_abap_char_utilities=>cr_lf ).
70107
zcl_excel_writer_csv=>set_initial_ext_date( ip_value = '' ).
108+
zcl_excel_writer_csv=>set_skip_hidden_columns( p_skip_c ).
109+
zcl_excel_writer_csv=>set_skip_hidden_rows( p_skip_r ).
71110

72111
zcl_excel_writer_csv=>set_active_sheet_index( i_active_worksheet = 2 ).
73112

@@ -107,3 +146,14 @@ START-OF-SELECTION.
107146
filename = lv_full_path
108147
filetype = 'BIN'
109148
CHANGING data_tab = lt_file_tab ).
149+
150+
IF p_xlsx = abap_true.
151+
REPLACE FIRST OCCURRENCE OF '_Sheet1.csv' IN lv_full_path WITH '.xlsx'.
152+
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
153+
lv_file = lo_excel_writer->write_file( lo_excel ).
154+
lt_file_tab = cl_bcs_convert=>xstring_to_solix( lv_file ).
155+
cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = xstrlen( lv_file )
156+
filename = lv_full_path
157+
filetype = 'BIN'
158+
CHANGING data_tab = lt_file_tab ).
159+
ENDIF.

0 commit comments

Comments
 (0)