* save error object in collection
APPEND errors.
CLEAR item_url.
DATA: bds_instance TYPE REF TO cl_bds_document_set.
DATA: doc_signature TYPE sbdst_signature,
wa_doc_signature LIKE LINE OF doc_signature,
doc_components TYPE sbdst_components,
doc_uris TYPE sbdst_uri,
wa_doc_uris LIKE LINE OF doc_uris.
*
以下三个值为
Tcode:OAOR
里面新建模板文件的参数
DATA: doc_classname TYPE sbdst_classname V
ALUE 'PICTURES',
doc_classtype TYPE sbdst_classtype V
ALUE 'OT',
doc_object_key TYPE sbdst_object_key V
ALUE 'ZEXCEL'.
wa_doc_signature-prop_name = 'DESCRIPTION'.
app = 'excel'.
IF app = 'excel'.
document_type = excel.
wa_doc_signature-prop_value = p_docname.
ELSE.
ENDIF.
APPEND wa_doc_signature TO doc_signature.
CREATE OBJECT bds_instance.
CALL METHOD bds_instance->get_info
EXPORTING
classname
= doc_classname
classtype
= doc_classtype
object_key = doc_object_key
CHANGING
components = doc_components
signature
= doc_signature.
CALL METHOD bds_instance->get_with_url
EXPORTING
classname
= doc_classname
classtype
= doc_classtype
object_key = doc_object_key
CHANGING
uris
= doc_uris
signature
= doc_signature.
FREE bds_instance.
READ TABLE doc_uris INTO wa_doc_uris INDEX 1.
item_url = wa_doc_uris-uri.
* ask the SAP DOI container for a i_oi_document_proxy for Excel
CALL METHOD control->get_document_proxy
EXPORTING
document_type
= 'Excel.Sheet'
no_flush
= 'X'
IMPORTING
document_proxy = document
error
= errors.
APPEND errors.
* open a document saved in business document service.
CALL METHOD document->open_document
EXPORTING
open_inplace = inplace
document_url = item_url.
DATA: has TYPE i.
CALL METHOD document->has_spreadsheet_interface
EXPORTING
no_flush
= ''
IMPORTING
is_available = has
error
= errors.
APPEND errors.
CALL METHOD document->get_spreadsheet_interface
EXPORTING
no_flush
= ' '
IMPORTING
sheet_interface = spreadsheet
error
= errors.
APPEND errors.
* Activate
sheet 1
CALL METHOD spreadsheet->select_sheet
EXPORTING
name
=
'
表整理
'
*
NO_FLUSH = ' '
IMPORTING
error
= errors.
*
RETCODE
=
.
APPEND errors.
LOOP AT errors.
CALL METHOD errors->raise_message
EXPORTING
type = 'E'.
ENDLOOP.
FREE errors.
initialized = 'X'.
ENDFORM.
"CREATE_BASIC_OBJECTS
*&---------------------------------------------------------------------*
*&
Form
output_to_excel
*&---------------------------------------------------------------------*
*
fill the EXCEL sheet
*----------------------------------------------------------------------*
FORM output_to_excel.
DATA num TYPE i V
ALUE 1.
LOOP AT itab.
num = num + sy-tabix.
PERFORM fill_cell USING num 1 itab-matnr.
PERFORM fill_cell USING num 2 itab-spras.
PERFORM fill_cell USING num 3 itab-maktx.
PERFORM fill_cell USING num 4 itab-maktg.
num = 1.
ENDLOOP.
ENDFORM.
"output_to_excel
*&---------------------------------------------------------------------*
*&
Form
FILL_CELL
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->I
text
*
-->J
text
*
-->V
AL
text
*----------------------------------------------------------------------*
FORM fill_cell
USING i j val.
DATA: columns_number TYPE i,
rows_number
TYPE i.
columns_number = 1.
rows_number = 1.
CALL METHOD spreadsheet->insert_range_dim
EXPORTING
name
= 'cell'
no_flush = 'X'
top
= i
left
= j
rows
= rows_number
columns
= columns_number
IMPORTING
error
= errors.
APPEND errors.
REFRESH: ranges, excel_input.
rangeitem-name = 'cell'.
rangeitem-columns = 1.
rangeitem-rows = 1.
APPEND rangeitem TO ranges.
excel_input_wa-column = 1.
excel_input_wa-row = 1.
excel_input_wa-value = val.
APPEND excel_input_wa TO excel_input.
* set data
CALL METHOD spreadsheet->set_ranges_data
EXPORTING
ranges
= ranges
contents = excel_input
no_flush = 'X'
IMPORTING
error
= errors.
APPEND errors.
CALL METHOD spreadsheet->fit_widest
EXPORTING
name
= space
no_flush = 'X'.
REFRESH: ranges, excel_input.
ENDFORM.
"fill_cell
本
文
来
自
CSDN
博
客
,
转
载
请
标
明
出
处
:
http://blog.csdn.net/animalbe/archive/2010/05/31/5635607.aspx