mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 13:46:17 +08:00
#230 - Pimp my Code - ZCL_EXCEL_READER_2007->ZIF_EXCEL_READER~LOAD_FILE
git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@360 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049
This commit is contained in:
parent
a9701a7605
commit
c21a49617b
|
@ -65,7 +65,7 @@
|
||||||
"/>
|
"/>
|
||||||
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_REL_DRAWINGS" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="15 " TYPTYPE="4" SRCROW1="69 " SRCCOLUMN1="4 " SRCROW2="69 " SRCCOLUMN2="45 " TYPESRC_LENG="44 " TYPESRC="t_rel_drawings type TABLE OF t_rel_drawing
|
<types CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="T_REL_DRAWINGS" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="15 " TYPTYPE="4" SRCROW1="69 " SRCCOLUMN1="4 " SRCROW2="69 " SRCCOLUMN2="45 " TYPESRC_LENG="44 " TYPESRC="t_rel_drawings type TABLE OF t_rel_drawing
|
||||||
"/>
|
"/>
|
||||||
<implementing CLSNAME="ZCL_EXCEL_READER_2007" REFCLSNAME="ZIF_EXCEL_READER" VERSION="1" EXPOSURE="2" STATE="1" RELTYPE="1" EDITORDER="0 "/>
|
<implementing CLSNAME="ZCL_EXCEL_READER_2007" REFCLSNAME="ZIF_EXCEL_READER" VERSION="1" EXPOSURE="2" STATE="1" RELTYPE="1"/>
|
||||||
<publicSection>class ZCL_EXCEL_READER_2007 definition
|
<publicSection>class ZCL_EXCEL_READER_2007 definition
|
||||||
public
|
public
|
||||||
create public .
|
create public .
|
||||||
|
@ -246,6 +246,11 @@ protected section.
|
||||||
*"* implementation or private method's signature</localTypes>
|
*"* implementation or private method's signature</localTypes>
|
||||||
<localMacros>*"* use this source file for any macro definitions you need
|
<localMacros>*"* use this source file for any macro definitions you need
|
||||||
*"* in the implementation part of the class</localMacros>
|
*"* in the implementation part of the class</localMacros>
|
||||||
|
<textPool>
|
||||||
|
<language SPRAS="E">
|
||||||
|
<textElement ID="I" KEY="001" ENTRY="A problem occured when reading the file" LENGTH="60 "/>
|
||||||
|
</language>
|
||||||
|
</textPool>
|
||||||
<typeUsage CLSNAME="ZCL_EXCEL_READER_2007" TYPEGROUP="IXML" VERSION="1" TPUTYPE="0" EXPLICIT="X"/>
|
<typeUsage CLSNAME="ZCL_EXCEL_READER_2007" TYPEGROUP="IXML" VERSION="1" TPUTYPE="0" EXPLICIT="X"/>
|
||||||
<forwardDeclaration>IXML</forwardDeclaration>
|
<forwardDeclaration>IXML</forwardDeclaration>
|
||||||
<attribute CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="EXCEL2007" VERSION="1" LANGU="E" DESCRIPT="Excel 2007 data" EXPOSURE="0" STATE="1" EDITORDER="1 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="XSTRING" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
|
<attribute CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="EXCEL2007" VERSION="1" LANGU="E" DESCRIPT="Excel 2007 data" EXPOSURE="0" STATE="1" EDITORDER="1 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="XSTRING" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
|
||||||
|
@ -297,32 +302,95 @@ endmethod.</source>
|
||||||
</interfaceMethod>
|
</interfaceMethod>
|
||||||
<interfaceMethod CLSNAME="ZCL_EXCEL_READER_2007" CPDNAME="ZIF_EXCEL_READER~LOAD_FILE">
|
<interfaceMethod CLSNAME="ZCL_EXCEL_READER_2007" CPDNAME="ZIF_EXCEL_READER~LOAD_FILE">
|
||||||
<source>method ZIF_EXCEL_READER~LOAD_FILE.
|
<source>method ZIF_EXCEL_READER~LOAD_FILE.
|
||||||
DATA: excel_data TYPE xstring.
|
*--------------------------------------------------------------------*
|
||||||
DATA filelength TYPE i.
|
* ToDos:
|
||||||
DATA bin_tab TYPE TABLE OF x255.
|
* 2do§1 decision whether to load from frontend or backend
|
||||||
" Background processing
|
* current behavior ( autodecide ) should be default
|
||||||
DATA bin_data LIKE LINE OF bin_tab.
|
* add optional parameter to allow user to choose
|
||||||
DATA len TYPE i.
|
* to load from backend even when online
|
||||||
DATA alen TYPE i.
|
* 2do§2 loosen typing of i_filename to CLIKE
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
|
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
|
* issue #230 - Pimp my Code
|
||||||
|
* - Stefan Schmöcker, 2012-11-05
|
||||||
|
* - ...
|
||||||
|
* changes: renaming variables to naming conventions
|
||||||
|
* renaming variables to indicate what they are used for
|
||||||
|
* adding comments to explain what we are trying to achieve
|
||||||
|
* message made to support multilinguality
|
||||||
|
* aligning code
|
||||||
|
* commenting on problems/future enhancements/todos we already know of or should decide upon
|
||||||
|
* adding issue # that has initiated the change - date provided to allow cleaning of code after a certain period
|
||||||
|
* explicit declaration of type of table instead of implicit declaration
|
||||||
|
* added errorhandling for open dataset
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
|
|
||||||
|
CONSTANTS: lcv_load_from_frontend TYPE char1 VALUE 'F',
|
||||||
|
lcv_load_from_backend TYPE char1 VALUE 'B'.
|
||||||
|
|
||||||
|
DATA: lv_load_from_source TYPE char1,
|
||||||
|
|
||||||
|
lv_filelength TYPE i,
|
||||||
|
lt_binary_data TYPE STANDARD TABLE OF x255 WITH NON-UNIQUE DEFAULT KEY,
|
||||||
|
ls_binary_data LIKE LINE OF lt_binary_data,
|
||||||
|
* Background processing
|
||||||
|
lv_max_length_line TYPE i,
|
||||||
|
lv_actual_length_line TYPE i,
|
||||||
|
|
||||||
|
lv_errormessage TYPE string, " Can't pass '...'(abc) to exception-class
|
||||||
|
lv_excel_data TYPE xstring. " Binary content of .xlsx file
|
||||||
|
|
||||||
|
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
|
* ToDos: 2do§1 Decision whether to load from frontend or backend
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
|
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
|
* Autodecide on frontend or backend reading
|
||||||
|
* Background-processing --> backend reading
|
||||||
|
* Online-processing --> frontend reading
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
IF sy-batch = abap_true.
|
IF sy-batch = abap_true.
|
||||||
DESCRIBE FIELD bin_data LENGTH len IN BYTE MODE.
|
lv_load_from_source = lcv_load_from_backend.
|
||||||
|
ELSE.
|
||||||
|
lv_load_from_source = lcv_load_from_frontend.
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
CASE lv_load_from_source.
|
||||||
|
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
|
* Read from backend
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
|
WHEN lcv_load_from_backend.
|
||||||
|
DESCRIBE FIELD ls_binary_data LENGTH lv_max_length_line IN BYTE MODE.
|
||||||
OPEN DATASET i_filename FOR INPUT IN BINARY MODE.
|
OPEN DATASET i_filename FOR INPUT IN BINARY MODE.
|
||||||
|
IF sy-subrc <> 0.
|
||||||
|
lv_errormessage = 'A problem occured when reading the file'(001).
|
||||||
|
RAISE EXCEPTION TYPE zcx_excel
|
||||||
|
EXPORTING
|
||||||
|
error = lv_errormessage.
|
||||||
|
ENDIF.
|
||||||
WHILE sy-subrc = 0.
|
WHILE sy-subrc = 0.
|
||||||
READ DATASET i_filename INTO bin_data MAXIMUM LENGTH len ACTUAL LENGTH alen.
|
|
||||||
APPEND bin_data TO bin_tab.
|
READ DATASET i_filename INTO ls_binary_data MAXIMUM LENGTH lv_max_length_line ACTUAL LENGTH lv_actual_length_line.
|
||||||
filelength = filelength + alen.
|
APPEND ls_binary_data TO lt_binary_data.
|
||||||
|
lv_filelength = lv_filelength + lv_actual_length_line.
|
||||||
|
|
||||||
ENDWHILE.
|
ENDWHILE.
|
||||||
CLOSE DATASET i_filename.
|
CLOSE DATASET i_filename.
|
||||||
ELSE.
|
|
||||||
cl_gui_frontend_services=>gui_upload(
|
*--------------------------------------------------------------------*
|
||||||
EXPORTING
|
* Read from frontend
|
||||||
filename = i_filename " Name of file
|
*--------------------------------------------------------------------*
|
||||||
filetype = 'BIN' " File Type (ASCII, Binary)
|
WHEN lcv_load_from_frontend.
|
||||||
|
cl_gui_frontend_services=>gui_upload( EXPORTING
|
||||||
|
filename = i_filename
|
||||||
|
filetype = 'BIN' " We are basically working with zipped directories --> force binary read
|
||||||
IMPORTING
|
IMPORTING
|
||||||
filelength = filelength
|
filelength = lv_filelength
|
||||||
CHANGING
|
CHANGING
|
||||||
data_tab = bin_tab
|
data_tab = lt_binary_data
|
||||||
EXCEPTIONS
|
EXCEPTIONS
|
||||||
file_open_error = 1
|
file_open_error = 1
|
||||||
file_read_error = 2
|
file_read_error = 2
|
||||||
|
@ -342,22 +410,31 @@ endmethod.</source>
|
||||||
dp_timeout = 16
|
dp_timeout = 16
|
||||||
not_supported_by_gui = 17
|
not_supported_by_gui = 17
|
||||||
error_no_gui = 18
|
error_no_gui = 18
|
||||||
OTHERS = 19
|
OTHERS = 19 ).
|
||||||
).
|
|
||||||
IF sy-subrc <> 0.
|
IF sy-subrc <> 0.
|
||||||
|
lv_errormessage = 'A problem occured when reading the file'(001).
|
||||||
RAISE EXCEPTION TYPE zcx_excel
|
RAISE EXCEPTION TYPE zcx_excel
|
||||||
EXPORTING
|
EXPORTING
|
||||||
error = 'A problem occured when reading the file'.
|
error = lv_errormessage.
|
||||||
ENDIF.
|
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
|
||||||
|
ENDCASE.
|
||||||
|
|
||||||
|
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
|
* Binary data needs to be provided as XSTRING for further processing
|
||||||
|
*--------------------------------------------------------------------*
|
||||||
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
|
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
|
||||||
EXPORTING
|
EXPORTING
|
||||||
input_length = filelength
|
input_length = lv_filelength
|
||||||
IMPORTING
|
IMPORTING
|
||||||
buffer = excel_data
|
buffer = lv_excel_data
|
||||||
TABLES
|
TABLES
|
||||||
binary_tab = bin_tab.
|
binary_tab = lt_binary_data.
|
||||||
r_excel = me->zif_excel_reader~load( excel_data ).
|
|
||||||
|
r_excel = me->zif_excel_reader~load( lv_excel_data ).
|
||||||
|
|
||||||
|
|
||||||
endmethod.</source>
|
endmethod.</source>
|
||||||
</interfaceMethod>
|
</interfaceMethod>
|
||||||
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="FILL_STRUCT_FROM_ATTRIBUTES" VERSION="1" LANGU="E" DESCRIPT="Fills structure fields based on XML node attributes" EXPOSURE="1" STATE="1" EDITORDER="2 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
|
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="FILL_STRUCT_FROM_ATTRIBUTES" VERSION="1" LANGU="E" DESCRIPT="Fills structure fields based on XML node attributes" EXPOSURE="1" STATE="1" EDITORDER="2 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
|
||||||
|
@ -1117,7 +1194,7 @@ endmethod.</source>
|
||||||
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKBOOK" SCONAME="IP_PATH" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
|
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKBOOK" SCONAME="IP_PATH" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
|
||||||
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKBOOK" SCONAME="IP_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Excel creator" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZCL_EXCEL"/>
|
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKBOOK" SCONAME="IP_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Excel creator" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZCL_EXCEL"/>
|
||||||
<exception CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKBOOK" SCONAME="ZCX_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Exceptions for ABAP2XLSX" MTDTYPE="0" EDITORDER="1 "/>
|
<exception CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKBOOK" SCONAME="ZCX_EXCEL" VERSION="1" LANGU="E" DESCRIPT="Exceptions for ABAP2XLSX" MTDTYPE="0" EDITORDER="1 "/>
|
||||||
<source>METHOD load_workbook.
|
<source>method LOAD_WORKBOOK.
|
||||||
|
|
||||||
CONSTANTS: lc_shared_strings TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings',
|
CONSTANTS: lc_shared_strings TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings',
|
||||||
lc_worksheet TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet',
|
lc_worksheet TYPE string VALUE 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet',
|
||||||
|
@ -1273,7 +1350,7 @@ endmethod.</source>
|
||||||
* #229: Set active worksheet - end coding
|
* #229: Set active worksheet - end coding
|
||||||
*--------------------------------------------------------------------*
|
*--------------------------------------------------------------------*
|
||||||
|
|
||||||
ENDMETHOD.</source>
|
endmethod.</source>
|
||||||
</method>
|
</method>
|
||||||
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET" VERSION="1" LANGU="E" DESCRIPT="Loads worksheet" EXPOSURE="1" STATE="1" EDITORDER="7 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
|
<method CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET" VERSION="1" LANGU="E" DESCRIPT="Loads worksheet" EXPOSURE="1" STATE="1" EDITORDER="7 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
|
||||||
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET" SCONAME="IP_PATH" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
|
<parameter CLSNAME="ZCL_EXCEL_READER_2007" CMPNAME="LOAD_WORKSHEET" SCONAME="IP_PATH" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING"/>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user