on 04-01-2016 1:32 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.