abap2xlsx/ZA2X/PROG/ZDEMO_EXCEL34.slnk
Ivan Femia f6febd8a5c Ready to test #139
Changed methods RECURSIVE_CLASS_TO_STRUCT and RECURSIVE_STRUCT_TO_CLASS, now in class ZCL_EXCEL_COMMON
Deleted method CREATE_AUTOFILTER, now included in CREATE_XL_SHEET
Moved method ADD_STATIC_STYLES from method ZIF_EXCEL_WRITER~WRITE_FILE of class ZCL_EXCEL_WRITER_2007/ZCL_EXCEL_WRITER_XLSM to method CREATE
Renamed ZDEMO_EXCEL2A in ZDEMO_EXCEL34
Renamed ZDEMO_EXCEL2B in ZDEMO_EXCEL35
Added demos in ZDEMO_EXCEL (Demo Collection)

git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@270 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
2012-03-19 21:46:37 +00:00

163 lines
9.9 KiB
XML

<?xml version="1.0" encoding="utf-16"?>
<PROG NAME="ZDEMO_EXCEL34" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20120319" UNAM="FEMIA" UDAT="20120319" VERN="000013" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20120319" STIME="222025" IDATE="20120319" ITIME="215102" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="abap2xlsx Demo: static styles" LENGTH="33 "/>
<textElement ID="S" KEY="P_PATH" ENTRY="D ." LENGTH="9 "/>
</language>
</textPool>
<source>*&amp;---------------------------------------------------------------------*
*&amp; Report ZDEMO_EXCEL2
*&amp; Test Styles for ABAP2XLSX
*&amp;---------------------------------------------------------------------*
*&amp;
*&amp;
*&amp;---------------------------------------------------------------------*
REPORT zdemo_excel34.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_excel_writer TYPE REF TO zif_excel_writer,
lo_worksheet TYPE REF TO zcl_excel_worksheet.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
lt_file_tab TYPE solix_tab.
DATA: lv_full_path TYPE string,
lv_workdir TYPE string,
lv_file_separator TYPE c.
CONSTANTS: lv_default_file_name TYPE string VALUE &apos;34_Static_Styles.xlsx&apos;.
PARAMETERS: p_path TYPE zexcel_export_dir.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
lv_workdir = p_path.
cl_gui_frontend_services=&gt;directory_browse( EXPORTING initial_folder = lv_workdir
CHANGING selected_folder = lv_workdir ).
p_path = lv_workdir.
INITIALIZATION.
cl_gui_frontend_services=&gt;get_desktop_directory( CHANGING desktop_directory = lv_workdir ).
cl_gui_cfw=&gt;flush( ).
p_path = lv_workdir.
sy-title = &apos;ZDEMO_EXCEL2;Issue 139: Static styles instead of dynamic styles&apos;.
START-OF-SELECTION.
IF p_path IS INITIAL.
p_path = lv_workdir.
ENDIF.
cl_gui_frontend_services=&gt;get_file_separator( CHANGING file_separator = lv_file_separator ).
CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path.
&quot; Creates active sheet
CREATE OBJECT lo_excel.
&quot; Get active sheet
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
lo_worksheet-&gt;set_title( ip_title = &apos;Styles&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 2 ip_value = &apos;Hello world&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;C&apos; ip_row = 3 ip_value = &apos;Bold text&apos; ).
lo_worksheet-&gt;change_cell_style( ip_column = &apos;C&apos;
ip_row = 3
ip_font_bold = abap_true
ip_font_italic = abap_true
ip_font_name = zcl_excel_style_font=&gt;c_name_arial
ip_font_scheme = zcl_excel_style_font=&gt;c_scheme_none
ip_font_color_rgb = zcl_excel_style_color=&gt;c_red
).
lo_worksheet-&gt;set_cell( ip_column = &apos;D&apos; ip_row = 4 ip_value = &apos;Underlined text&apos; ).
lo_worksheet-&gt;change_cell_style( ip_column = &apos;D&apos;
ip_row = 4
ip_font_underline = abap_true
ip_font_underline_mode = zcl_excel_style_font=&gt;c_underline_double
ip_font_name = zcl_excel_style_font=&gt;c_name_roman
ip_font_scheme = zcl_excel_style_font=&gt;c_scheme_none
ip_font_family = zcl_excel_style_font=&gt;c_family_roman
).
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 5 ip_value = &apos;Filled text&apos; ).
lo_worksheet-&gt;change_cell_style( ip_column = &apos;B&apos;
ip_row = 5
ip_fill_filltype = zcl_excel_style_fill=&gt;c_fill_solid
ip_fill_fgcolor_theme = zcl_excel_style_color=&gt;c_theme_accent6
).
lo_worksheet-&gt;set_cell( ip_column = &apos;C&apos; ip_row = 6 ip_value = &apos;Borders&apos; ).
lo_worksheet-&gt;change_cell_style( ip_column = &apos;C&apos;
ip_row = 6
ip_borders_allbo_color_rgb = zcl_excel_style_color=&gt;c_black
ip_borders_allborders_style = zcl_excel_style_border=&gt;c_border_thin
ip_borders_diagonal_color_rgb = zcl_excel_style_color=&gt;c_black
ip_borders_diagonal_style = zcl_excel_style_border=&gt;c_border_thin
ip_borders_diagonal_mode = zcl_excel_style_borders=&gt;c_diagonal_both
).
lo_worksheet-&gt;set_cell( ip_column = &apos;D&apos; ip_row = 7 ip_value = &apos;I&apos;&apos;m not a button :)&apos; ).
lo_worksheet-&gt;change_cell_style( ip_column = &apos;D&apos;
ip_row = 7
ip_borders_down_color_rgb = zcl_excel_style_color=&gt;c_black
ip_borders_down_style = zcl_excel_style_border=&gt;c_border_thin
ip_borders_right_color_rgb = zcl_excel_style_color=&gt;c_black
ip_borders_right_style = zcl_excel_style_border=&gt;c_border_thin
ip_borders_top_color_rgb = zcl_excel_style_color=&gt;c_gray
ip_borders_top_style = zcl_excel_style_border=&gt;c_border_thin
ip_borders_left_color_rgb = zcl_excel_style_color=&gt;c_gray
ip_borders_left_style = zcl_excel_style_border=&gt;c_border_thin
).
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 9 ip_value = &apos;Modified color for Excel 2003&apos; ).
lo_excel-&gt;legacy_palette-&gt;set_color( &quot;replace built-in color from palette with out custom RGB turquoise
ip_index = 16
ip_color = &apos;0040E0D0&apos; ).
lo_worksheet-&gt;change_cell_style( ip_column = &apos;B&apos;
ip_row = 9
ip_fill_filltype = zcl_excel_style_fill=&gt;c_fill_solid
ip_fill_fgcolor_indexed = 16
).
&quot; Fill the cell and apply one style
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 6 ip_value = &apos;Filled text&apos; ).
lo_worksheet-&gt;change_cell_style( ip_column = &apos;B&apos;
ip_row = 6
ip_fill_filltype = zcl_excel_style_fill=&gt;c_fill_solid
ip_fill_fgcolor_rgb = zcl_excel_style_color=&gt;c_green
ip_font_name = zcl_excel_style_font=&gt;c_name_cambria
ip_font_scheme = zcl_excel_style_font=&gt;c_scheme_major
).
&quot; Change the style
* lo_worksheet-&gt;set_cell_style( ip_column = &apos;B&apos; ip_row = 6 ).
&quot; Add Style to an empty cell to test Fix for Issue
&quot;#44 Exception ZCX_EXCEL thrown when style is set for an empty cell
&quot; https://code.sdn.sap.com/spaces/abap2xlsx/tickets/44-exception-zcx_excel-thrown-when-style-is-set-for-an-empty-cell
* lo_worksheet-&gt;set_cell_style( ip_column = &apos;E&apos; ip_row = 6 ).
lo_worksheet-&gt;change_cell_style( ip_column = &apos;E&apos;
ip_row = 6
ip_fill_filltype = zcl_excel_style_fill=&gt;c_fill_solid
ip_fill_fgcolor_rgb = zcl_excel_style_color=&gt;c_green
ip_font_name = zcl_excel_style_font=&gt;c_name_cambria
ip_font_scheme = zcl_excel_style_font=&gt;c_scheme_major
).
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
&quot; Convert to binary
CALL FUNCTION &apos;SCMS_XSTRING_TO_BINARY&apos;
EXPORTING
buffer = lv_file
IMPORTING
output_length = lv_bytecount
TABLES
binary_tab = lt_file_tab.
* &quot; This method is only available on AS ABAP &gt; 6.40
* lt_file_tab = cl_bcs_convert=&gt;xstring_to_solix( iv_xstring = lv_file ).
* lv_bytecount = xstrlen( lv_file ).
&quot; Save the file
cl_gui_frontend_services=&gt;gui_download( EXPORTING bin_filesize = lv_bytecount
filename = lv_full_path
filetype = &apos;BIN&apos;
CHANGING data_tab = lt_file_tab ).</source>
</PROG>