Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Download excel file template on desktop

Former Member
0 Kudos

Hi all,

I am working on a requirement in which I am creating an excel file template on the user's system on the click of a pushbutton. The path of the file has to be given by user in an input/output field provided.

Now the user can enter this path manually or through F4 help. I want to put a check on this path such that it should exist in the user's system.

I am using MS_EXCEL_OLE_STANDARD_DAT

FM for creating an excel file template.

How to check that?

Regards

Natasha Garg

5 REPLIES 5

Former Member
0 Kudos

Hi,

Hope this would help you. Please dont forget to give points.

REPORT zdir_test.

TYPE-POOLS: abap.

DATA: v_dir TYPE string.

DATA: v_bol TYPE abap_bool.

v_dir = 'c:\sap\'.

CALL METHOD cl_gui_frontend_services=>directory_exist

EXPORTING

directory = v_dir

RECEIVING

result = v_bol

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

not_supported_by_gui = 4

OTHERS = 5.

IF NOT v_bol IS INITIAL.

WRITE:/ 'Directory exists.'.

ELSE.

WRITE:/ 'Directory does not exist.'.

ENDIF.

Regards,

Deepthi Dandibhotla.

Former Member
0 Kudos

hi,

you already know the function module right just go and check it in the code or go to se37 and provide the path and check.

Former Member
0 Kudos

at selection-screen on value-request for p_file.

call method cl_gui_frontend_services=>file_open_dialog

exporting

window_title = 'Select File'

default_extension = 'TXT'

  • DEFAULT_FILENAME =

  • FILE_FILTER =

  • WITH_ENCODING =

  • INITIAL_DIRECTORY =

  • MULTISELECTION = ' '

changing

file_table = it_filetable

rc = v_rc

  • USER_ACTION =

  • FILE_ENCODING =

exceptions

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

not_supported_by_gui = 4

others = 5

.

if sy-subrc = 0.

read table it_filetable into wa_filetable index 1.

if sy-subrc = 0.

p_file = wa_filetable.

endif.

endif.

Former Member
0 Kudos

Hi,

Try using the function module for F4 help.

p_name -


> name of the field for which you need the Search Help.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_name.

  • F4 help for layout Variant

PERFORM f4_for_variant.

*& Form f4_for_variant

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form f4_for_variant .

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

FILE_NAME = p_name

.

endform.

Please, Let me know if the problem still persists.

Regards,

Amit.

Former Member
0 Kudos

REPORT ZCREATEEXCEL.

TYPE-POOLS OLE2.

DATA: EXCEL TYPE OLE2_OBJECT,

WORKBOOKS TYPE OLE2_OBJECT,

WORKBOOK TYPE OLE2_OBJECT.

DATA: FILENAME LIKE RLGRAP-FILENAME.

  • START THE EXCEL APPLICATION

CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.

PERFORM ERR_HDL.

  • PUT EXCEL IN FRONT

SET PROPERTY OF EXCEL 'VISIBLE' = 1.

PERFORM ERR_HDL.

  • INFORM USER OF THE CURRENT STATUS

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

PERCENTAGE = 0

TEXT = TEXT-I08

EXCEPTIONS

OTHERS = 1.

  • CREATE AN EXCEL WORKBOOK OBJECT

CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOKS.

PERFORM ERR_HDL.

CALL METHOD OF WORKBOOKS 'ADD' = WORKBOOK.

PERFORM ERR_HDL.

  • EXCEL FILENAME

CONCATENATE SY-REPID '_' SY-DATUM6(2) '_' SY-DATUM4(2) '_'

SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.

CALL METHOD OF WORKBOOK 'SAVEAS' EXPORTING #1 = FILENAME.

FORM ERR_HDL.

IF SY-SUBRC <> 0.

WRITE: / 'OLE ERROR: RETURN CODE ='(I10), SY-SUBRC.

STOP.

ENDIF.

ENDFORM.