cancel
Showing results for 
Search instead for 
Did you mean: 

How can I change the file name while using EXPORT functionality of WEB DYNPRO ALV?

Former Member
0 Kudos

Hi Everyone,

I have a requirement where I have to change the file name, while exporting ALV to excel sheet.

By default file name is 'Export.XLSX', I have to change it.

Is it possible?

Also, When I am exporting my internal table into Excel, using the below mentioned code, I always get the following warning ''The file format and extension don't match ''.

LOOP AT lt_comp_dtls INTO ls_comp_dtls.

           CONCATENATE  ls_comp_dtls-pernr

                        ls_comp_dtls-name

                        ls_comp_dtls-div_desc

                        ls_comp_dtls-div1_desc

                        ls_comp_dtls-org

                        ls_comp_dtls-cost_c

                        ls_comp_dtls-job_ttl

                        ls_comp_dtls-ch_nch

                        ls_comp_dtls-mandt_assigned

                        ls_comp_dtls-mandt_due

                        ls_comp_dtls-mandt_complete

                        ls_comp_dtls-duelt30days

                        ls_comp_dtls-duege30days

                        ls_comp_dtls-emp_email

                        ls_comp_dtls-sup_name

                        ls_comp_dtls-sup_email

                        ls_comp_dtls-pers_admin

                        cl_abap_char_utilities=>newline INTO lv_text1

                        SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

           CONCATENATE  lv_text_full lv_text lv_text1 INTO lv_text_full.

CALL FUNCTION 'SDOK_MIMETYPE_GET'

           EXPORTING

             extension = '.XLS'

           IMPORTING

             mimetype  = lv_mime.



CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

           EXPORTING

             text   = lv_text_full

           IMPORTING

             buffer = lv_xtext.


CALL METHOD cl_wd_runtime_services=>attach_file_to_response

           EXPORTING

*           i_filename      = 'Download.xls'

             i_filename      = lv_filename

             i_content       = lv_xtext

             i_mime_type     = lv_mime_str "'EXCEL'

             i_in_new_window = abap_false

             i_inplace       = abap_false.

Please provide your valuable suggestions on this.

Thanks,

Faraz Khan

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member

Hi Faraz ,


please try below code it may help u



data: lv_text1 type string,

         lv_xtext type xstring.



LOOP AT lt_comp_dtls INTO ls_comp_dtls.

           CONCATENATE  ls_comp_dtls-pernr

                        ls_comp_dtls-name

                        ls_comp_dtls-div_desc

                        ls_comp_dtls-div1_desc

                        ls_comp_dtls-org

                        ls_comp_dtls-cost_c

                        ls_comp_dtls-job_ttl

                        ls_comp_dtls-ch_nch

                        ls_comp_dtls-mandt_assigned

                        ls_comp_dtls-mandt_due

                        ls_comp_dtls-mandt_complete

                        ls_comp_dtls-duelt30days

                        ls_comp_dtls-duege30days

                        ls_comp_dtls-emp_email

                        ls_comp_dtls-sup_name

                        ls_comp_dtls-sup_email

                        ls_comp_dtls-pers_admin

                        cl_abap_char_utilities=>newline INTO lv_text1

                        SEPARATED BY cl_abap_char_utilities=>horizontal_tab.


           CONCATENATE  lv_text_full lv_text lv_text1 INTO lv_text_full.


CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

           EXPORTING

             text   = lv_text_full

           IMPORTING

             buffer = lv_xtext.

  WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
**path to the word file
  I_FILENAME = 'flight_details.xls' " here is your File Name
* String Variable
  I_CONTENT = lv_xtext
* File Type
  I_MIME_TYPE = 'EXCEL' ).   " this is the type of file you r exporting like "EXCEL" , "WORD",                                                                          "TXT" etc




Thanks

Nidhi

Former Member
0 Kudos

Hi Nidhi,

Thanks for your suggestion.

I have tried by passing 'EXCEL' to the I_MIME_TYPE parameter of Class 'CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE', but I am getting the same warning.


Thanks,

Faraz Khan

Former Member
0 Kudos

Hi Faraz,

If your system is NetWeaver 7.0 Enhancement Package 2, than we have Export  button(Default button) functionality in WD ALV and user have also options to rename their file with save as options .


I'm not aware why you are using extra functionality to export the ALV content to Excel until unless you need any customization in the data content(e.g. color, header information change) .

sometime  long concatenations also give problem while exporting the data.

After Exporting the file to your local machine, if you are  getting  warning while opening the Excel file, than its file compatible issue file content and extension which is from MS EXCEL.

I think it should not be an issue, If still user don't want  the warning ,please check below link it may be help you.

you can check below link for more information

https://support.microsoft.com/en-us/kb/948615

Thanks

Nidhi

Former Member
0 Kudos

Hello,

The warning might be coming due to missing length calculation. Please check the below thread-

Hope this helps.

Mohit

Former Member
0 Kudos

Hi Nidhi,

The initial requirement was to download the contents of an internal table into Excel file.But while doing so, Excel gives the warning (Stated in the first post) and this is the problem.

On Selecting 'Open', following warning appears:

After opening and then Saving the file, following Dialog box appears with blank file name and .TXT extension:

If user ignores the warning and opens the excel and then try to save it, the dialog box appears with blank file name and extension as .TXT.

In order to fix the extension mismatch warning, I created one POP UP ALV (with the internal table fields) so that user can review the entries and if needed can use the standard EXPORT functionality and save the file, however there is again a limitation that the file name is always set as 'EXPORT.XLS' by default.We have dropped this approach because user does not want to name the file manually as the file name is the concatenation of many fields.

Currently as a workaround, user doesn't open the file directly, but use 'Save as' to download it and then open it, edit it ,and save it again.

Thanks,

Faraz Khan

Former Member
0 Kudos

Hi Mohit,

Thanks for your suggestion.

My excel file is not an Email attachment.I have to download excel from my Webdynpro Component.

Thanks,

Faraz Khan

former_member193460
Contributor
0 Kudos

Hi Faraz,

   you are propted with the issue because the file downloaded from the application is actually a text file (table delimeted text file). These text file can be opened in excel as you have shown in the screenshot.

After opening it in the excel, if you do a save operation you will be prompted with another warning dialog box (which is not in the screenshot you have pasted above). Screenshot is below:

Choose "No" when you are prompted with this option, then excel option will come up and you can save the file as a original excel file.

Hope this helps.

Note: Webdynpro ALV does have a standard option to download excel file in proper excel format, it is in the application bar of the alv (which might be hidden in the program as of now).

Regards,

Tashi

Former Member
0 Kudos

Hi Tashi,

Thanks for your suggestion.

I have informed the user about the same and I am waiting for his feedback.

I hope this will do the trick!

Thanks again!

Faraz Khan

0 Kudos

Hi Faraz,

Please try below code once. It may help you.

data: lv_text1 type string,
         lv_xtext type xstring.


LOOP AT lt_comp_dtls INTO ls_comp_dtls.

 

CONCATENATE LV_TEXT1 ls_comp_dtls-pernr
                                               ls_comp_dtls-name
                                               ls_comp_dtls-div_desc
                                               ls_comp_dtls-div1_desc
                                               ls_comp_dtls-org
                                               ls_comp_dtls-cost_c
                                               ls_comp_dtls-job_ttl
                                               ls_comp_dtls-ch_nch
                                               ls_comp_dtls-mandt_assigned
                                               ls_comp_dtls-mandt_due
                                               ls_comp_dtls-mandt_complete
                                               ls_comp_dtls-duelt30days
                                               ls_comp_dtls-duege30days
                                               ls_comp_dtls-emp_email
                                               ls_comp_dtls-sup_name
                                               ls_comp_dtls-sup_email
                                               ls_comp_dtls-pers_admin
                                   cl_abap_char_utilities=>newline INTO lv_text1 SEPARATED BY                 

                                   cl_abap_char_utilities=>horizontal_tab.

ENDLOOP.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
           EXPORTING
             text   = lv_text1
           IMPORTING
             buffer = lv_xtext.

  WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(

**path to the word file
  I_FILENAME = 'flight_details.xls'            " here is your File Name

* String Variable
  I_CONTENT = lv_xtext

* File Type
  I_MIME_TYPE = 'EXCEL' ).       "THIS IS THE TYPE OF THE OUTPUT FILE

Regards,

Naresh.

Former Member
0 Kudos

Hi Naresh,

Thanks for your suggestion.

I will try the code as mentioned by you and I will let you know the result.

Thanks,

Faraz Khan