事务代码:STRANS 启动转换器
步骤
1. 将参数填入模板,并另存为word 2003 xml文档
2.使用网页打开xml文档,并将xml拷贝到转换器tt:template中,添加参数
3.替换参数,部分xml可能存在错误或者跑偏根据实际情况检查修改
4.程序调用
FORM frm_export_proof .
DATA:xml_str TYPE string,
l_bindata TYPE xstring,
l_cntbin TYPE sdokcntbins,
w_len TYPE i,
l_filename TYPE string,
l_file_path TYPE string,
l_full_path TYPE string,
l_doc_name TYPE localfile.
DATA: lo_xml_doc TYPE REF TO cl_xml_document.
*调用STRANS
CONCATENATE gs_alv-personid_ext gs_alv-ename gs_alv-zcomname '收入证明' INTO l_filename SEPARATED BY '-'.
IF p_zmlx = TEXT-002 AND p_langu = TEXT-017.
CALL TRANSFORMATION zword_proof_income_zh
SOURCE
gs_alv = gs_alv
RESULT XML xml_str.
ENDIF.
IF p_zmlx = TEXT-002 AND p_langu = TEXT-018.
DO 21 TIMES.
CONCATENATE ' ' gs_alv-zdat02 INTO gs_alv-zdat02 SEPARATED BY '' .
ENDDO.
DO 4 TIMES.
CONCATENATE ' ' gs_alv-zcomnature INTO gs_alv-zcomnature SEPARATED BY '' .
ENDDO.
DO 2 TIMES.
CONCATENATE ' ' gs_alv-zcomname INTO gs_alv-zcomname SEPARATED BY ' ' .
ENDDO.
DO 11 TIMES.
CONCATENATE ' ' gs_alv-zcontact INTO gs_alv-zcontact SEPARATED BY '' .
CONCATENATE ' ' gs_alv-ztel INTO gs_alv-ztel SEPARATED BY '' .
ENDDO.
CALL TRANSFORMATION zword_proof_income_en
SOURCE
gs_alv = gs_alv
RESULT XML xml_str.
ENDIF.
IF p_zmlx = TEXT-003.
CALL TRANSFORMATION zword_proof_cpf_income
SOURCE
gs_alv = gs_alv
RESULT XML xml_str.
ENDIF.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = xml_str
* MIMETYPE = ' '
IMPORTING
buffer = l_bindata
EXCEPTIONS
failed = 1
OTHERS = 2.
CLEAR w_len.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_bindata
IMPORTING
output_length = w_len
TABLES
binary_tab = l_cntbin.
CALL METHOD cl_gui_frontend_services=>file_save_dialog "调用保存对话框
EXPORTING
default_extension = 'DOC' "把文件保存成.doc格式 (doc文档)
default_file_name = l_filename
CHANGING
filename = l_filename
path = l_file_path
fullpath = l_full_path
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc NE 0.
ELSE.
l_doc_name = l_full_path.
CREATE OBJECT lo_xml_doc.
lo_xml_doc->parse_string( xml_str ).
lo_xml_doc->export_to_file( l_doc_name ).
ENDIF.
ENDFORM.
预览
CALL SCREEN 0100.
PBO:
MODULE initial_0100 OUTPUT.
IF go_html_control IS NOT BOUND.
"创建容器与组件对象
PERFORM create_container_assembly.
"设置组件展示用的内容
PERFORM set_assembly_data.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form CREATE_CONTAINER_ASSEMBLY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM create_container_assembly .
IF go_html_container IS INITIAL .
CREATE OBJECT go_html_container
EXPORTING
container_name = 'PDF'.
CREATE OBJECT go_html_control
EXPORTING
parent = go_html_container.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SET_ASSEMBLY_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM set_assembly_data .
DATA:xml_str TYPE string,
l_bindata TYPE xstring,
l_cntbin TYPE sdokcntbins,
w_len TYPE i,
l_filename TYPE string,
l_file_path TYPE string,
l_full_path TYPE string,
l_doc_name TYPE localfile.
*调用STRANS
IF p_zmlx = TEXT-002 AND p_langu = TEXT-017.
CALL TRANSFORMATION zword_proof_income_zh
SOURCE
gs_alv = gs_alv
RESULT XML xml_str.
ENDIF.
IF p_zmlx = TEXT-002 AND p_langu = TEXT-018.
CALL TRANSFORMATION zword_proof_income_en
SOURCE
gs_alv = gs_alv
RESULT XML xml_str.
ENDIF.
IF p_zmlx = TEXT-003.
CALL TRANSFORMATION zword_proof_cpf_income
SOURCE
gs_alv = gs_alv
RESULT XML xml_str.
ENDIF.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = xml_str
* MIMETYPE = ' '
IMPORTING
buffer = l_bindata
EXCEPTIONS
failed = 1
OTHERS = 2.
CLEAR w_len.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_bindata
IMPORTING
output_length = w_len
TABLES
binary_tab = l_cntbin.
"展示PDF文件
CALL METHOD go_html_control->load_data(
EXPORTING
type = 'application'
subtype = 'PDF'
IMPORTING
assigned_url = lv_url
CHANGING
data_table = l_cntbin
EXCEPTIONS
dp_invalid_parameter = 1
dp_error_general = 2
cntl_error = 3
OTHERS = 4 ).
"展示组件内容
CALL METHOD go_html_control->show_url(
url = lv_url
in_place = 'X' ).
ENDFORM.
PAI:
MODULE exit INPUT.
LEAVE TO SCREEN 0.
ENDMODULE.
问题
notes:1146711