mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 08:26:15 +08:00
No line if empty by kwaishang (#629)
* Update zcl_excel_worksheet.clas.abap Allow int8 type columns * Option to create empty file Allow to create empty excel file even if input table is empty * Update zcl_excel_worksheet.clas.abap Add the option to create the file or not if the input table is empty * Test report zdemo_excel43 When using CSV mainly, if the input table is empty, the csv file contained a line with empty fields and separators. This fooled some automation process thinking there's data to process in the file. When optional input parameter "iv_no_line_if_empty" of method "zcl_excel_worksheet->bind_table" is checked, there's no more empty line in this case. * User demo report 44 instead of 43 Mistake in test program name * Fix internal renaming of test report 44 * Correct filename and test both cases * Include test 44
This commit is contained in:
parent
e02733290f
commit
3bee79156d
|
@ -107,6 +107,7 @@ CLASS zcl_excel_worksheet DEFINITION
|
|||
!it_field_catalog TYPE zexcel_t_fieldcatalog OPTIONAL
|
||||
!is_table_settings TYPE zexcel_s_table_settings OPTIONAL
|
||||
value(iv_default_descr) TYPE c OPTIONAL
|
||||
!IV_NO_LINE_IF_EMPTY type ABAP_BOOL default ABAP_FALSE
|
||||
EXPORTING
|
||||
!es_table_settings TYPE zexcel_s_table_settings
|
||||
RAISING
|
||||
|
@ -3030,7 +3031,7 @@ CLASS ZCL_EXCEL_WORKSHEET IMPLEMENTATION.
|
|||
ADD 1 TO lv_row_int.
|
||||
|
||||
ENDLOOP.
|
||||
IF sy-subrc <> 0. "create empty row if table has no data
|
||||
IF sy-subrc <> 0 AND iv_no_line_if_empty = abap_false. "create empty row if table has no data
|
||||
me->set_cell( ip_column = lv_column_alpha
|
||||
ip_row = lv_row_int
|
||||
ip_value = space ).
|
||||
|
@ -4876,7 +4877,8 @@ CLASS ZCL_EXCEL_WORKSHEET IMPLEMENTATION.
|
|||
ep_value_type = lv_value_type ).
|
||||
ENDIF.
|
||||
CASE lv_value_type.
|
||||
WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2.
|
||||
WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2
|
||||
OR cl_abap_typedescr=>typekind_int8. "Allow INT8 types columns
|
||||
lo_addit = cl_abap_elemdescr=>get_i( ).
|
||||
CREATE DATA lo_value_new TYPE HANDLE lo_addit.
|
||||
ASSIGN lo_value_new->* TO <fs_numeric>.
|
||||
|
|
|
@ -77,6 +77,7 @@ START-OF-SELECTION.
|
|||
SUBMIT zdemo_excel39 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Charts
|
||||
SUBMIT zdemo_excel40 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Demo Printsettings
|
||||
SUBMIT zdemo_excel41 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Inheritance
|
||||
SUBMIT zdemo_excel44 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: No line if empty
|
||||
|
||||
SUBMIT zdemo_excel_comments WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Comments
|
||||
SUBMIT ztest_excel_image_header WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Image in Header and Footer
|
||||
|
|
58
src/zdemo_excel44.prog.abap
Normal file
58
src/zdemo_excel44.prog.abap
Normal file
|
@ -0,0 +1,58 @@
|
|||
*&---------------------------------------------------------------------*
|
||||
*& Report ZDEMO_EXCEL44
|
||||
*&
|
||||
*&---------------------------------------------------------------------*
|
||||
*&
|
||||
*&
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
REPORT zdemo_excel44.
|
||||
|
||||
DATA: lo_excel_no_line_if_empty TYPE REF TO zcl_excel,
|
||||
lo_excel TYPE REF TO zcl_excel,
|
||||
lo_worksheet_no_line_if_empty TYPE REF TO zcl_excel_worksheet,
|
||||
lo_worksheet TYPE REF TO zcl_excel_worksheet.
|
||||
|
||||
DATA: lt_field_catalog TYPE zexcel_t_fieldcatalog.
|
||||
|
||||
DATA: gc_save_file_name TYPE string VALUE '44_iTabEmpty.csv'.
|
||||
INCLUDE zdemo_excel_outputopt_incl.
|
||||
|
||||
SELECTION-SCREEN BEGIN OF BLOCK b44 WITH FRAME TITLE txt_b44.
|
||||
|
||||
* No line if internal table is empty
|
||||
DATA: p_mtyfil TYPE flag VALUE abap_true.
|
||||
|
||||
SELECTION-SCREEN END OF BLOCK b44.
|
||||
|
||||
INITIALIZATION.
|
||||
txt_b44 = 'Testing empty file option'(b44).
|
||||
|
||||
START-OF-SELECTION.
|
||||
|
||||
" Creates active sheet
|
||||
CREATE OBJECT lo_excel_no_line_if_empty.
|
||||
CREATE OBJECT lo_excel.
|
||||
|
||||
" Get active sheet
|
||||
lo_worksheet_no_line_if_empty = lo_excel_no_line_if_empty->get_active_worksheet( ).
|
||||
lo_worksheet = lo_excel->get_active_worksheet( ).
|
||||
lo_worksheet_no_line_if_empty->set_title( 'Internal table' ).
|
||||
lo_worksheet->set_title( 'Internal table' ).
|
||||
|
||||
DATA lt_test TYPE TABLE OF sflight.
|
||||
|
||||
lo_worksheet_no_line_if_empty->bind_table( ip_table = lt_test
|
||||
iv_no_line_if_empty = p_mtyfil ).
|
||||
|
||||
p_mtyfil = abap_false.
|
||||
lo_worksheet->bind_table( ip_table = lt_test
|
||||
iv_no_line_if_empty = p_mtyfil ).
|
||||
|
||||
*** Create output
|
||||
lcl_output=>output( EXPORTING cl_excel = lo_excel_no_line_if_empty
|
||||
iv_writerclass_name = 'ZCL_EXCEL_WRITER_CSV' ).
|
||||
|
||||
gc_save_file_name = '44_iTabNotEmpty.csv'.
|
||||
lcl_output=>output( EXPORTING cl_excel = lo_excel
|
||||
iv_writerclass_name = 'ZCL_EXCEL_WRITER_CSV' ).
|
34
src/zdemo_excel44.prog.xml
Normal file
34
src/zdemo_excel44.prog.xml
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_PROG" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<PROGDIR>
|
||||
<NAME>ZDEMO_EXCEL44</NAME>
|
||||
<SUBC>1</SUBC>
|
||||
<RSTAT>T</RSTAT>
|
||||
<RLOAD>E</RLOAD>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UCCHECK>X</UCCHECK>
|
||||
</PROGDIR>
|
||||
<TPOOL>
|
||||
<item>
|
||||
<ID>I</ID>
|
||||
<KEY>B44</KEY>
|
||||
<ENTRY>Testing empty file option</ENTRY>
|
||||
<LENGTH>50</LENGTH>
|
||||
</item>
|
||||
<item>
|
||||
<ID>R</ID>
|
||||
<ENTRY>Demo excel 44</ENTRY>
|
||||
<LENGTH>13</LENGTH>
|
||||
</item>
|
||||
<item>
|
||||
<ID>S</ID>
|
||||
<KEY>P_MTYFIL</KEY>
|
||||
<ENTRY>No data => No empty line</ENTRY>
|
||||
<LENGTH>32</LENGTH>
|
||||
</item>
|
||||
</TPOOL>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
Loading…
Reference in New Issue
Block a user