mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 14:06:24 +08:00
Enhance report ZDEMO_EXCEL31 to show better autosize function from issue:
#310 More sophisticated calculation of cell widths
This commit is contained in:
parent
1409cf8741
commit
7dcee8edeb
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-2"?>
|
||||
<PROG NAME="ZDEMO_EXCEL31" VARCL="X" SUBC="1" CNAM="BCUSER" CDAT="20110929" UNAM="K2_SCHMOECK" UDAT="20120324" VERN="000039" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20120324" STIME="112316" IDATE="20120324" ITIME="112316" UCCHECK="X">
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PROG NAME="ZDEMO_EXCEL31" VARCL="X" SUBC="1" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" UCCHECK="X">
|
||||
<textPool>
|
||||
<language SPRAS="E">
|
||||
<textElement ID="R" ENTRY="abap2xlsx Demo: Autosize Column with different Font sizes" LENGTH="58 "/>
|
||||
|
@ -26,8 +26,11 @@ DATA: fieldval TYPE text80,
|
|||
row TYPE i,
|
||||
style_column_a TYPE REF TO zcl_excel_style,
|
||||
style_column_a_guid TYPE zexcel_cell_style,
|
||||
style_column_b TYPE REF TO zcl_excel_style,
|
||||
style_column_b_guid TYPE zexcel_cell_style,
|
||||
style_column_c TYPE REF TO zcl_excel_style,
|
||||
style_column_c_guid TYPE zexcel_cell_style.
|
||||
style_column_c_guid TYPE zexcel_cell_style,
|
||||
style_font TYPE REF TO zcl_excel_style_font.
|
||||
|
||||
CONSTANTS: gc_save_file_name TYPE string VALUE '31_AutosizeWithDifferentFontSizes.xlsx'.
|
||||
INCLUDE zdemo_excel_outputopt_incl.
|
||||
|
@ -35,10 +38,10 @@ INCLUDE zdemo_excel_outputopt_incl.
|
|||
|
||||
START-OF-SELECTION.
|
||||
|
||||
" Creates active sheet
|
||||
CREATE OBJECT lo_excel.
|
||||
" Use active sheet
|
||||
lo_worksheet = lo_excel->get_active_worksheet( ).
|
||||
lo_worksheet->set_title( ip_title = 'Sheet1' ).
|
||||
lo_worksheet->set_title( ip_title = 'Regular Font' ).
|
||||
|
||||
style_column_a = lo_excel->add_new_style( ).
|
||||
style_column_a->font->size = 32. " quite large
|
||||
|
@ -67,8 +70,79 @@ START-OF-SELECTION.
|
|||
column_dimension = lo_worksheet->get_column_dimension( 'C' ).
|
||||
column_dimension->set_auto_size( ip_auto_size = abap_true ).
|
||||
|
||||
" Add sheet
|
||||
lo_worksheet = lo_excel->add_new_worksheet( ).
|
||||
lo_worksheet->set_title( ip_title = 'Bold Font' ).
|
||||
|
||||
style_column_a = lo_excel->add_new_style( ).
|
||||
style_column_a->font->size = 32. " quite large
|
||||
style_column_a->font->bold = abap_true.
|
||||
style_column_a_guid = style_column_a->get_guid( ).
|
||||
|
||||
style_column_b = lo_excel->add_new_style( ).
|
||||
style_column_b->font->bold = abap_true.
|
||||
style_column_b_guid = style_column_b->get_guid( ).
|
||||
|
||||
style_column_c = lo_excel->add_new_style( ).
|
||||
style_column_c->font->size = 16. " not so large
|
||||
style_column_c->font->bold = abap_true.
|
||||
style_column_c_guid = style_column_c->get_guid( ).
|
||||
|
||||
DO 20 TIMES.
|
||||
row = sy-index.
|
||||
CLEAR fieldval.
|
||||
DO sy-index TIMES.
|
||||
CONCATENATE fieldval 'X' INTO fieldval.
|
||||
ENDDO.
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = row ip_value = fieldval ip_style = style_column_a_guid ).
|
||||
lo_worksheet->set_cell( ip_column = 'B' ip_row = row ip_value = fieldval ip_style = style_column_b_guid ).
|
||||
lo_worksheet->set_cell( ip_column = 'C' ip_row = row ip_value = fieldval ip_style = style_column_c_guid ).
|
||||
ENDDO.
|
||||
|
||||
column_dimension = lo_worksheet->get_column_dimension( 'A' ).
|
||||
column_dimension->set_auto_size( ip_auto_size = abap_true ).
|
||||
column_dimension = lo_worksheet->get_column_dimension( 'B' ).
|
||||
column_dimension->set_auto_size( ip_auto_size = abap_true ).
|
||||
column_dimension = lo_worksheet->get_column_dimension( 'C' ).
|
||||
column_dimension->set_auto_size( ip_auto_size = abap_true ).
|
||||
|
||||
" Add sheet
|
||||
lo_worksheet = lo_excel->add_new_worksheet( ).
|
||||
lo_worksheet->set_title( ip_title = 'Italic Font' ).
|
||||
|
||||
style_column_a = lo_excel->add_new_style( ).
|
||||
style_column_a->font->size = 32. " quite large
|
||||
style_column_a->font->italic = abap_true.
|
||||
style_column_a_guid = style_column_a->get_guid( ).
|
||||
|
||||
style_column_b = lo_excel->add_new_style( ).
|
||||
style_column_b->font->italic = abap_true.
|
||||
style_column_b_guid = style_column_b->get_guid( ).
|
||||
|
||||
style_column_c = lo_excel->add_new_style( ).
|
||||
style_column_c->font->size = 16. " not so large
|
||||
style_column_c->font->italic = abap_true.
|
||||
style_column_c_guid = style_column_c->get_guid( ).
|
||||
|
||||
DO 20 TIMES.
|
||||
row = sy-index.
|
||||
CLEAR fieldval.
|
||||
DO sy-index TIMES.
|
||||
CONCATENATE fieldval 'X' INTO fieldval.
|
||||
ENDDO.
|
||||
lo_worksheet->set_cell( ip_column = 'A' ip_row = row ip_value = fieldval ip_style = style_column_a_guid ).
|
||||
lo_worksheet->set_cell( ip_column = 'B' ip_row = row ip_value = fieldval ip_style = style_column_b_guid ).
|
||||
lo_worksheet->set_cell( ip_column = 'C' ip_row = row ip_value = fieldval ip_style = style_column_c_guid ).
|
||||
ENDDO.
|
||||
|
||||
column_dimension = lo_worksheet->get_column_dimension( 'A' ).
|
||||
column_dimension->set_auto_size( ip_auto_size = abap_true ).
|
||||
column_dimension = lo_worksheet->get_column_dimension( 'B' ).
|
||||
column_dimension->set_auto_size( ip_auto_size = abap_true ).
|
||||
column_dimension = lo_worksheet->get_column_dimension( 'C' ).
|
||||
column_dimension->set_auto_size( ip_auto_size = abap_true ).
|
||||
|
||||
lo_excel->set_active_sheet_index( i_active_worksheet = 1 ).
|
||||
|
||||
*** Create output
|
||||
lcl_output=>output( lo_excel ).</source>
|
||||
|
|
Loading…
Reference in New Issue
Block a user