Issue #83 and issue #90 fixed

git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@169 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
This commit is contained in:
Ivan Femia 2011-05-04 19:15:49 +00:00
parent 9b9915e3e8
commit b7481a4077
5 changed files with 206 additions and 227 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-16"?>
<CLAS CLSNAME="ZCL_EXCEL_WRITER_CSV" VERSION="1" LANGU="E" DESCRIPT="Excel writer 2007" UUID="ADD4B74D93C52E57E1000000C0A8FA28" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" AUTHOR="JACQUED" CREATEDON="20110420" CHANGEDON="00000000" CHGDANYON="00000000" CLSFINAL="X" CLSCCINCL="X" FIXPT="X" UNICODE="X" R3RELEASE="701" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 ">
<implementing CLSNAME="ZCL_EXCEL_WRITER_CSV" REFCLSNAME="ZIF_EXCEL_WRITER" VERSION="1" EXPOSURE="2" STATE="1" AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDON="00000000" RELTYPE="1"/>
<CLAS CLSNAME="ZCL_EXCEL_WRITER_CSV" VERSION="1" LANGU="E" DESCRIPT="Excel writer 2007" UUID="4DADD1E5BEEA005BE1008000AC17C0C6" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" AUTHOR="JACQUED" CREATEDON="20110420" CHANGEDBY="FEMIA" CHANGEDON="20110504" CHGDANYON="00000000" CLSFINAL="X" CLSCCINCL="X" FIXPT="X" UNICODE="X" R3RELEASE="701" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 ">
<implementing CLSNAME="ZCL_EXCEL_WRITER_CSV" REFCLSNAME="ZIF_EXCEL_WRITER" VERSION="1" EXPOSURE="2" STATE="1" AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDBY="FEMIA" CHANGEDON="20110504" RELTYPE="1"/>
<publicSection>class ZCL_EXCEL_WRITER_CSV definition
public
final
@ -10,7 +10,18 @@
*&quot;* do not include other source files here!!!
public section.
interfaces ZIF_EXCEL_WRITER .</publicSection>
interfaces ZIF_EXCEL_WRITER .
class-methods SET_DELIMITER
importing
value(IP_VALUE) type CHAR01 default &apos;;&apos; .
class-methods SET_ENCLOSURE
importing
value(IP_VALUE) type CHAR01 default &apos;&quot;&apos; .
class CL_ABAP_CHAR_UTILITIES definition load .
class-methods SET_ENDOFLINE
importing
value(IP_VALUE) type ANY default CL_ABAP_CHAR_UTILITIES=&gt;CR_LF .</publicSection>
<protectedSection>*&quot;* protected components of class ZCL_EXCEL_WRITER_2007
*&quot;* do not include other source files here!!!
protected section.</protectedSection>
@ -19,6 +30,9 @@ protected section.</protectedSection>
private section.
data EXCEL type ref to ZCL_EXCEL .
class-data DELIMITER type CHAR01 value &apos;;&apos;. &quot;#EC NOTEXT .
class-data ENCLOSURE type CHAR01 value &apos;&quot;&apos;. &quot;#EC NOTEXT .
class-data EOL type CHAR01 value CL_ABAP_CHAR_UTILITIES=&gt;CR_LF. &quot;#EC NOTEXT .
methods CREATE
returning
@ -34,15 +48,18 @@ private section.
*&quot;* implementation or private method&apos;s signature</localTypes>
<localMacros>*&quot;* use this source file for any macro definitions you need
*&quot;* in the implementation part of the class</localMacros>
<attribute CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="EXCEL" VERSION="1" LANGU="E" DESCRIPT="Excel creator" EXPOSURE="0" STATE="1" EDITORDER="1 " AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDON="00000000" ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="3" TYPE="ZCL_EXCEL" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " R3RELEASE="701" TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="DELIMITER" VERSION="1" LANGU="E" DESCRIPT="Delimiter" EXPOSURE="0" STATE="1" EDITORDER="2 " AUTHOR="FEMIA" CREATEDON="20110504" CHANGEDON="00000000" ATTDECLTYP="1" ATTVALUE="&apos;;&apos;" ATTEXPVIRT="0" TYPTYPE="1" TYPE="CHAR01" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " R3RELEASE="701" TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="ENCLOSURE" VERSION="1" LANGU="E" DESCRIPT="Text inclusure character" EXPOSURE="0" STATE="1" EDITORDER="3 " AUTHOR="FEMIA" CREATEDON="20110504" CHANGEDON="00000000" ATTDECLTYP="1" ATTVALUE="&apos;&quot;&apos;" ATTEXPVIRT="0" TYPTYPE="1" TYPE="CHAR01" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " R3RELEASE="701" TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="EOL" VERSION="1" LANGU="E" DESCRIPT="End Of line" EXPOSURE="0" STATE="1" EDITORDER="4 " AUTHOR="FEMIA" CREATEDON="20110504" CHANGEDON="00000000" ATTDECLTYP="1" ATTVALUE="CL_ABAP_CHAR_UTILITIES=&gt;CR_LF" ATTEXPVIRT="0" TYPTYPE="1" TYPE="CHAR01" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " R3RELEASE="701" TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="EXCEL" VERSION="1" LANGU="E" DESCRIPT="Excel creator" EXPOSURE="0" STATE="1" EDITORDER="1 " AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDBY="FEMIA" CHANGEDON="20110504" ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="3" TYPE="ZCL_EXCEL" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " R3RELEASE="701" TYPESRC_LENG="0 "/>
<interfaceMethod CLSNAME="ZCL_EXCEL_WRITER_CSV" CPDNAME="ZIF_EXCEL_WRITER~WRITE_FILE">
<source>method ZIF_EXCEL_WRITER~WRITE_FILE.
me-&gt;excel = io_excel.
ep_file = me-&gt;create( ).
endmethod.</source>
</interfaceMethod>
<method CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="CREATE" VERSION="1" LANGU="E" DESCRIPT="Create" EXPOSURE="0" STATE="1" EDITORDER="1 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDON="00000000" MTDTYPE="0" MTDDECLTYP="0" R3RELEASE="701" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="CREATE" SCONAME="EP_EXCEL" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDON="00000000" PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="XSTRING"/>
<method CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="CREATE" VERSION="1" LANGU="E" DESCRIPT="Create" EXPOSURE="0" STATE="1" EDITORDER="1 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDBY="FEMIA" CHANGEDON="20110504" MTDTYPE="0" MTDDECLTYP="0" R3RELEASE="701" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="CREATE" SCONAME="EP_EXCEL" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDBY="FEMIA" CHANGEDON="20110504" PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="XSTRING"/>
<source>method CREATE.
* .csv format with ; delimiter
@ -51,8 +68,8 @@ endmethod.</source>
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="CREATE_CSV" VERSION="1" LANGU="E" DESCRIPT="Create CSV ; Delimited format" EXPOSURE="0" STATE="1" EDITORDER="2 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDON="00000000" MTDTYPE="0" MTDDECLTYP="0" R3RELEASE="701" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="CREATE_CSV" SCONAME="EP_CONTENT" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDON="00000000" PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="XSTRING"/>
<method CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="CREATE_CSV" VERSION="1" LANGU="E" DESCRIPT="Create CSV ; Delimited format" EXPOSURE="0" STATE="1" EDITORDER="2 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDBY="FEMIA" CHANGEDON="20110504" MTDTYPE="0" MTDDECLTYP="0" R3RELEASE="701" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="CREATE_CSV" SCONAME="EP_CONTENT" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110428" CHANGEDBY="FEMIA" CHANGEDON="20110504" PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="XSTRING"/>
<source>method CREATE_CSV.
TYPES: BEGIN OF lty_format,
@ -60,7 +77,10 @@ endmethod.</source>
attvalue TYPE SEOVALUE,
END OF lty_format.
DATA: lt_format TYPE STANDARD TABLE OF lty_format,
ls_format LIKE LINE OF lt_format.
ls_format LIKE LINE OF lt_format,
lv_date TYPE DATS,
lv_tmp TYPE string,
lv_time TYPE CHAR08.
DATA: lo_iterator TYPE REF TO cl_object_collection_iterator,
lo_worksheet TYPE REF TO zcl_excel_worksheet.
@ -85,11 +105,23 @@ endmethod.</source>
AND typtype = 1
AND type = &apos;ZEXCEL_NUMBER_FORMAT&apos;.
* --- Retrieve SAP date format
CLEAR ls_format.
SELECT ddtext INTO ls_format-attvalue FROM dd07t WHERE domname = &apos;XUDATFM&apos;
AND ddlanguage = sy-langu.
ls_format-cmpname = &apos;DATE&apos;.
CONDENSE ls_format-attvalue.
CONCATENATE &apos;&apos;&apos;&apos; ls_format-attvalue &apos;&apos;&apos;&apos; INTO ls_format-attvalue.
APPEND ls_format TO lt_format.
ENDSELECT.
LOOP AT lt_format INTO ls_format.
TRANSLATE ls_format-attvalue TO UPPER CASE.
MODIFY lt_format FROM ls_format.
ENDLOOP.
* STEP 1: Collect strings from the first worksheet
lo_iterator = excel-&gt;get_worksheets_iterator( ).
WHILE lo_iterator-&gt;if_object_collection_iterator~has_next( ) EQ abap_true.
@ -163,14 +195,17 @@ endmethod.</source>
* --- Add empty rows
WHILE lv_row &lt; &lt;fs_sheet_content&gt;-cell_row.
CONCATENATE lv_string cl_abap_char_utilities=&gt;newline INTO lv_string.
* CONCATENATE lv_string cl_abap_char_utilities=&gt;newline INTO lv_string.
* CONCATENATE lv_string cl_abap_char_utilities=&gt;cr_lf INTO lv_string.
CONCATENATE lv_string zcl_excel_writer_csv=&gt;eol INTO lv_string.
lv_row = lv_row + 1.
lv_col = 1.
ENDWHILE.
* --- Add empty columns
WHILE lv_col &lt; &lt;fs_sheet_content&gt;-cell_column.
CONCATENATE lv_string &apos;;&apos; INTO lv_string. &quot; ls_shared_string-string_value.
* CONCATENATE lv_string &apos;;&apos; INTO lv_string.
CONCATENATE lv_string zcl_excel_writer_csv=&gt;delimiter INTO lv_string.
lv_col = lv_col + 1.
ENDWHILE.
@ -181,18 +216,43 @@ endmethod.</source>
WHEN &apos;d&apos; OR &apos;D&apos;.
lc_value = zcl_excel_common=&gt;excel_string_to_date( ip_value = &lt;fs_sheet_content&gt;-cell_value ).
TRY.
lv_date = lc_value.
CALL FUNCTION &apos;CONVERT_DATE_TO_EXTERNAL&apos;
EXPORTING
DATE_INTERNAL = lv_date
IMPORTING
DATE_EXTERNAL = lv_tmp
EXCEPTIONS
DATE_INTERNAL_IS_INVALID = 1
OTHERS = 2
.
IF SY-SUBRC = 0.
lc_value = lv_tmp.
ENDIF.
CATCH CX_SY_CONVERSION_NO_NUMBER.
ENDTRY.
WHEN &apos;t&apos; OR &apos;T&apos;.
lc_value = zcl_excel_common=&gt;excel_string_to_time( ip_value = &lt;fs_sheet_content&gt;-cell_value ).
write lc_value to lv_time USING EDIT MASK &apos;__:__:__&apos;.
lc_value = lv_time.
WHEN OTHERS.
lc_value = &lt;fs_sheet_content&gt;-cell_value.
ENDCASE.
REPLACE ALL OCCURRENCES OF &apos;&quot;&apos; in lc_value with &apos;&quot;&quot;&apos;.
FIND FIRST OCCURRENCE OF &apos;;&apos; IN lc_value. &quot; &lt;fs_sheet_content&gt;-cell_value.
* REPLACE ALL OCCURRENCES OF &apos;&quot;&apos; in lc_value with &apos;&quot;&quot;&apos;.
CONCATENATE zcl_excel_writer_csv=&gt;enclosure zcl_excel_writer_csv=&gt;enclosure INTO lv_tmp.
CONDENSE lv_tmp.
REPLACE ALL OCCURRENCES OF zcl_excel_writer_csv=&gt;enclosure in lc_value with lv_tmp.
* FIND FIRST OCCURRENCE OF &apos;;&apos; IN lc_value.
FIND FIRST OCCURRENCE OF zcl_excel_writer_csv=&gt;delimiter IN lc_value.
IF sy-subrc = 0.
CONCATENATE lv_string &apos;&quot;&apos; lc_value &apos;&quot;&apos; INTO lv_string.
CONCATENATE lv_string zcl_excel_writer_csv=&gt;enclosure lc_value zcl_excel_writer_csv=&gt;enclosure INTO lv_string.
ELSE.
CONCATENATE lv_string lc_value INTO lv_string.
ENDIF.
@ -213,6 +273,24 @@ endmethod.</source>
OTHERS = 2
.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="SET_DELIMITER" VERSION="1" LANGU="E" DESCRIPT="Set Delimiter value" EXPOSURE="2" STATE="1" EDITORDER="3 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110504" CHANGEDON="00000000" MTDTYPE="0" MTDDECLTYP="1" R3RELEASE="701" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="SET_DELIMITER" SCONAME="IP_VALUE" VERSION="1" LANGU="E" DESCRIPT="Delimiter Value" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110504" CHANGEDON="00000000" PARDECLTYP="0" PARPASSTYP="0" TYPTYPE="1" TYPE="CHAR01" PARVALUE="&apos;;&apos;"/>
<source>method SET_DELIMITER.
delimiter = ip_value.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="SET_ENCLOSURE" VERSION="1" LANGU="E" DESCRIPT="Set Enclosure character" EXPOSURE="2" STATE="1" EDITORDER="4 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110504" CHANGEDON="00000000" MTDTYPE="0" MTDDECLTYP="1" R3RELEASE="701" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="SET_ENCLOSURE" SCONAME="IP_VALUE" VERSION="1" LANGU="E" DESCRIPT="Text field enclosure character" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110504" CHANGEDON="00000000" PARDECLTYP="0" PARPASSTYP="0" TYPTYPE="1" TYPE="CHAR01" PARVALUE="&apos;&quot;&apos;"/>
<source>method SET_ENCLOSURE.
zcl_excel_writer_csv=&gt;enclosure = ip_value.
endmethod.</source>
</method>
<method CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="SET_ENDOFLINE" VERSION="1" LANGU="E" DESCRIPT="Set End Of Line character" EXPOSURE="2" STATE="1" EDITORDER="5 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110504" CHANGEDON="00000000" MTDTYPE="0" MTDDECLTYP="1" R3RELEASE="701" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_EXCEL_WRITER_CSV" CMPNAME="SET_ENDOFLINE" SCONAME="IP_VALUE" VERSION="1" LANGU="E" DESCRIPT="End Of Line Character" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " AUTHOR="FEMIA" CREATEDON="20110504" CHANGEDON="00000000" PARDECLTYP="0" PARPASSTYP="0" TYPTYPE="1" TYPE="ANY" PARVALUE="CL_ABAP_CHAR_UTILITIES=&gt;CR_LF"/>
<source>method SET_ENDOFLINE.
zcl_excel_writer_csv=&gt;eol = ip_value.
endmethod.</source>
</method>
</CLAS>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<PROG NAME="ZDEMO_EXCEL" VARCL="X" SUBC="1" CNAM="BCUSER" CDAT="20100817" UNAM="FEMIA" UDAT="20110426" VERN="000043" RSTAT="T" RMAND="000" RLOAD="E" FIXPT="X" SDATE="20110426" STIME="050556" IDATE="20110426" ITIME="050556" UCCHECK="X">
<PROG NAME="ZDEMO_EXCEL" VARCL="X" SUBC="1" CNAM="BCUSER" CDAT="20100817" UNAM="FEMIA" UDAT="20110504" VERN="000044" RSTAT="T" RMAND="000" RLOAD="E" FIXPT="X" SDATE="20110504" STIME="211211" IDATE="20110504" ITIME="211211" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="Run all ABAP2XLSX Demo Programs" LENGTH="31 "/>
@ -62,6 +62,7 @@ START-OF-SELECTION.
SUBMIT zdemo_excel23 WITH p_path = p_path AND RETURN. &quot; abap2xlsx Demo: Multiple sheets with and w/o grid lines, print options
SUBMIT zdemo_excel24 WITH p_path = p_path AND RETURN. &quot; abap2xlsx Demo: Multiple sheets with different default date formats
SUBMIT zdemo_excel25 AND RETURN. &quot; abap2xlsx Demo: Create and xlsx on Application Server (could be executed in batch mode)
SUBMIT zdemo_excel26 WITH p_path = p_path WITH p_reader = abap_true AND RETURN. &quot; abap2xlsx Demo: Read cell format
SUBMIT zdemo_excel27 WITH p_path = p_path WITH p_reader = abap_true AND RETURN. &quot; abap2xlsx Demo: Read style format</source>
SUBMIT zdemo_excel26 WITH p_path = p_path AND RETURN. &quot; abap2xlsx Demo: Reader demo
* SUBMIT zdemo_excel27 WITH p_path = p_path AND RETURN. &quot; abap2xlsx Demo: empty
SUBMIT zdemo_excel28 WITH p_path = p_path AND RETURN. &quot; abap2xlsx Demo: Read style format</source>
</PROG>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<PROG NAME="ZDEMO_EXCEL26" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100711" UNAM="FEMIA" UDAT="20110426" VERN="000063" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110426" STIME="050556" IDATE="20110426" ITIME="050556" UCCHECK="X">
<PROG NAME="ZDEMO_EXCEL26" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100711" UNAM="FEMIA" UDAT="20110504" VERN="000065" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110504" STIME="211130" IDATE="20110504" ITIME="211130" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="abap2xlsx Demo: Hello World" LENGTH="27 "/>
@ -19,10 +19,7 @@ REPORT zdemo_excel26.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_excel_writer TYPE REF TO zif_excel_writer,
lo_excel_reader TYPE REF TO zif_excel_reader,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
lo_hyperlink TYPE REF TO zcl_excel_hyperlink,
column_dimension TYPE REF TO zcl_excel_worksheet_columndime.
lo_excel_reader TYPE REF TO zif_excel_reader.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
@ -32,10 +29,10 @@ DATA: lv_full_path TYPE string,
lv_workdir TYPE string,
lv_file_separator TYPE c.
CONSTANTS: lv_default_file_name TYPE string VALUE &apos;26_HelloWorld.xlsx&apos;.
CONSTANTS: lv_demo01 TYPE string VALUE &apos;01_HelloWorld.xlsx&apos;.
CONSTANTS: lv_demo02 TYPE string VALUE &apos;02_Styles.xlsx&apos;.
PARAMETERS: p_path TYPE zexcel_export_dir,
p_reader TYPE abap_bool AS CHECKBOX.
PARAMETERS: p_path TYPE zexcel_export_dir.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
lv_workdir = p_path.
@ -54,25 +51,16 @@ START-OF-SELECTION.
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.
* Demo01
&quot; Get active sheet
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
lo_worksheet-&gt;set_title( ip_title = &apos;Sheet1&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;B&apos; ip_row = 3 ip_value = sy-datum ).
lo_worksheet-&gt;set_cell( ip_column = &apos;C&apos; ip_row = 3 ip_value = sy-uzeit ).
lo_hyperlink = zcl_excel_hyperlink=&gt;create_external_link( iv_url = &apos;https://cw.sdn.sap.com/cw/groups/abap2xlsx&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 4 ip_value = &apos;Click here to visit abap2xlsx homepage&apos; ip_hyperlink = lo_hyperlink ).
column_dimension = lo_worksheet-&gt;get_column_dimension( ip_column = &apos;B&apos; ).
column_dimension-&gt;set_width( ip_width = 11 ).
CONCATENATE p_path lv_file_separator lv_demo01 INTO lv_full_path.
CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007.
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lo_excel = lo_excel_reader-&gt;load_file( lv_full_path ).
lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
REPLACE &apos;.xlsx&apos; IN lv_full_path WITH &apos;FromReader.xlsx&apos;.
&quot; Convert to binary
CALL FUNCTION &apos;SCMS_XSTRING_TO_BINARY&apos;
@ -82,36 +70,34 @@ START-OF-SELECTION.
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 ).
* Demo02
IF p_reader = abap_true.
CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007.
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lo_excel = lo_excel_reader-&gt;load_file( lv_full_path ).
lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
REPLACE &apos;.xlsx&apos; IN lv_full_path WITH &apos;FromReader.xlsx&apos;.
CONCATENATE p_path lv_file_separator lv_demo02 INTO lv_full_path.
&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.
CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007.
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lo_excel = lo_excel_reader-&gt;load_file( lv_full_path ).
lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
REPLACE &apos;.xlsx&apos; IN lv_full_path WITH &apos;FromReader.xlsx&apos;.
&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 ).
ENDIF.</source>
&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; 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>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<PROG NAME="ZDEMO_EXCEL27" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100711" UNAM="FEMIA" UDAT="20110426" VERN="000044" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110426" STIME="050557" IDATE="20110426" ITIME="050557" UCCHECK="X">
<PROG NAME="ZDEMO_EXCEL27" VARCL="X" SUBC="1" CNAM="FEMIA" CDAT="20100711" UNAM="FEMIA" UDAT="20110504" VERN="000047" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110504" STIME="211236" IDATE="20110504" ITIME="211236" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" ENTRY="abap2xlsx Demo: Styles" LENGTH="22 "/>
@ -16,160 +16,60 @@
*&amp;---------------------------------------------------------------------*
REPORT zdemo_excel27.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_excel_writer TYPE REF TO zif_excel_writer,
lo_excel_reader TYPE REF TO zif_excel_reader,
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.
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;27_Styles.xlsx&apos;.
PARAMETERS: p_path TYPE zexcel_export_dir,
p_reader TYPE abap_bool AS CHECKBOX.
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_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
cl_gui_cfw=&gt;flush( ).
p_path = lv_workdir.
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; Create border object
CREATE OBJECT lo_border_dark.
lo_border_dark-&gt;border_color = zcl_excel_style_color=&gt;c_black.
lo_border_dark-&gt;border_style = zcl_excel_style_border=&gt;c_border_thin.
CREATE OBJECT lo_border_light.
lo_border_light-&gt;border_color = zcl_excel_style_color=&gt;c_gray.
lo_border_light-&gt;border_style = zcl_excel_style_border=&gt;c_border_thin.
&quot; Create a bold / italic style
lo_style_bold = lo_excel-&gt;add_new_style( ).
lo_style_bold-&gt;font-&gt;bold = abap_true.
lo_style_bold-&gt;font-&gt;italic = abap_true.
lo_style_bold-&gt;font-&gt;color = zcl_excel_style_color=&gt;c_red.
lv_style_bold_guid = lo_style_bold-&gt;get_guid( ).
&quot; Create an underline double style
lo_style_underline = lo_excel-&gt;add_new_style( ).
lo_style_underline-&gt;font-&gt;underline = abap_true.
lo_style_underline-&gt;font-&gt;underline_mode = zcl_excel_style_font=&gt;c_underline_double.
lv_style_underline_guid = lo_style_underline-&gt;get_guid( ).
&quot; Create filled style yellow
lo_style_filled = lo_excel-&gt;add_new_style( ).
lo_style_filled-&gt;fill-&gt;filltype = zcl_excel_style_fill=&gt;c_fill_solid.
lo_style_filled-&gt;fill-&gt;fgcolor = zcl_excel_style_color=&gt;c_yellow.
lv_style_filled_guid = lo_style_filled-&gt;get_guid( ).
&quot; Create border with button effects
lo_style_button = lo_excel-&gt;add_new_style( ).
lo_style_button-&gt;borders-&gt;right = lo_border_dark.
lo_style_button-&gt;borders-&gt;down = lo_border_dark.
lo_style_button-&gt;borders-&gt;left = lo_border_light.
lo_style_button-&gt;borders-&gt;top = lo_border_light.
lv_style_button_guid = lo_style_button-&gt;get_guid( ).
&quot;Create style with border
lo_style_border = lo_excel-&gt;add_new_style( ).
lo_style_border-&gt;borders-&gt;allborders = lo_border_dark.
lv_style_border_guid = lo_style_border-&gt;get_guid( ).
&quot; Create filled style green
lo_style_filled = lo_excel-&gt;add_new_style( ).
lo_style_filled-&gt;fill-&gt;filltype = zcl_excel_style_fill=&gt;c_fill_solid.
lo_style_filled-&gt;fill-&gt;fgcolor = zcl_excel_style_color=&gt;c_green.
lv_style_filled_green_guid = lo_style_filled-&gt;get_guid( ).
&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; ip_style = lv_style_bold_guid ).
lo_worksheet-&gt;set_cell( ip_column = &apos;D&apos; ip_row = 4 ip_value = &apos;Underlined text&apos; ip_style = lv_style_underline_guid ).
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 5 ip_value = &apos;Filled text&apos; ip_style = lv_style_filled_guid ).
lo_worksheet-&gt;set_cell( ip_column = &apos;C&apos; ip_row = 6 ip_value = &apos;Borders&apos; ip_style = lv_style_border_guid ).
lo_worksheet-&gt;set_cell( ip_column = &apos;D&apos; ip_row = 7 ip_value = &apos;I&apos;&apos;m not a button :)&apos; ip_style = lv_style_button_guid ).
&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; ip_style = lv_style_filled_guid ).
&quot; Change the style
lo_worksheet-&gt;set_cell_style( ip_column = &apos;B&apos; ip_row = 6 ip_style = lv_style_filled_green_guid ).
&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 ip_style = lv_style_filled_green_guid ).
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 ).
IF p_reader = abap_true.
CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007.
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lo_excel = lo_excel_reader-&gt;load_file( lv_full_path ).
lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
REPLACE &apos;.xlsx&apos; IN lv_full_path WITH &apos;FromReader.xlsx&apos;.
&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; 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 ).
ENDIF.</source>
*
*DATA: lo_excel TYPE REF TO zcl_excel,
* lo_excel_writer TYPE REF TO zif_excel_writer,
* lo_excel_reader TYPE REF TO zif_excel_reader.
*
*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;27_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_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
* cl_gui_cfw=&gt;flush( ).
* p_path = lv_workdir.
*
*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.
*
* CREATE OBJECT lo_excel_reader TYPE zcl_excel_reader_2007.
* CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
* lo_excel = lo_excel_reader-&gt;load_file( lv_full_path ).
* lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
* REPLACE &apos;.xlsx&apos; IN lv_full_path WITH &apos;FromReader.xlsx&apos;.
*
* &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; 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>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<PROG NAME="ZDEMO_EXCEL28" VARCL="X" SUBC="1" CNAM="JACQUED" CDAT="20110427" UNAM="FEMIA" UDAT="20110428" VERN="000017" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110428" STIME="212317" IDATE="20110428" ITIME="212317" UCCHECK="X">
<PROG NAME="ZDEMO_EXCEL28" VARCL="X" SUBC="1" CNAM="JACQUED" CDAT="20110427" UNAM="FEMIA" UDAT="20110504" VERN="000020" RSTAT="T" RMAND="001" RLOAD="E" FIXPT="X" SDATE="20110504" STIME="210429" IDATE="20110504" ITIME="210429" UCCHECK="X">
<textPool>
<language SPRAS="E">
<textElement ID="R" LENGTH="27 "/>
@ -42,6 +42,7 @@ AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
INITIALIZATION.
cl_gui_frontend_services=&gt;get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
cl_gui_cfw=&gt;flush( ).
p_path = lv_workdir.
START-OF-SELECTION.
@ -50,7 +51,7 @@ START-OF-SELECTION.
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 p_path.
CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path.
&quot; Creates active sheet
CREATE OBJECT lo_excel.
@ -58,7 +59,7 @@ START-OF-SELECTION.
&quot; Get active sheet
lo_worksheet = lo_excel-&gt;get_active_worksheet( ).
lo_worksheet-&gt;set_title( ip_title = &apos;Sheet1&apos; ).
lo_worksheet-&gt;set_cell( ip_column = &apos;B&apos; ip_row = 2 ip_value = &apos;Hello ;&quot;; world&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;B&apos; ip_row = 3 ip_value = sy-datum ).
lo_worksheet-&gt;set_cell( ip_column = &apos;C&apos; ip_row = 3 ip_value = sy-uzeit ).
lo_hyperlink = zcl_excel_hyperlink=&gt;create_external_link( iv_url = &apos;https://cw.sdn.sap.com/cw/groups/abap2xlsx&apos; ).
@ -68,15 +69,28 @@ START-OF-SELECTION.
column_dimension-&gt;set_width( 11 ).
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_csv.
zcl_excel_writer_csv=&gt;set_delimiter( ip_value = cl_abap_char_utilities=&gt;horizontal_tab ).
zcl_excel_writer_csv=&gt;set_enclosure( ip_value = &apos;&apos;&apos;&apos; ).
zcl_excel_writer_csv=&gt;set_endofline( ip_value = cl_abap_char_utilities=&gt;cr_lf ).
lv_file = lo_excel_writer-&gt;write_file( lo_excel ).
* Convert to binary
lt_file_tab = cl_bcs_convert=&gt;xstring_to_solix( iv_xstring = lv_file ).
lv_bytecount = xstrlen( lv_file ).
&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 = p_path
filename = lv_full_path
filetype = &apos;BIN&apos;
CHANGING data_tab = lt_file_tab ).</source>
</PROG>