cancel
Showing results for 
Search instead for 
Did you mean: 

Error while downloading data into excel file.

Former Member
0 Kudos

Hi,

I have a requirement to download data available in xstring to excel file.

I have a RFC which has export parameter 'file_data' of type xstring. When i call RFC

from web dynpro abap application it gives data out pout in xstring format.

I am opening excel file using that xstring data as below

cl_wd_runtime_services=>attach_file_to_response(

i_filename = 'file.xls'

i_content = ls_data_source-data_source ***[xstring data from RFC]

i_mime_type = 'x-excel/application'

i_in_new_window = abap_true ).

But excel file not coming in correct format. its giving an error while download

excel file

Error is

" the file you are trying to open , 'file[1].xls', is in a different format than

specified by the file extension. Verify that the file is not corrupted and is from

a trusted source before opening the file. Do you want to open the file now? "

If i click on 'YES' button file opening but not in proper excel format. Data is coming

in tab delimiter format in excel file.

Please suggest any solution for this problem.

Thanks,

Venkat.

Accepted Solutions (0)

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

The root of the question is, how are you building the XSTRING?

Former Member
0 Kudos

Hi Thomas,

Following is the logic implemented in RFC which is giving XSTRING as export parameter

STEP1 create a dynamic internal table

Create field catalog for the table using LVC_FIELDCATALOG_MERGE

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = dyn_table.

CREATE EXCEL SHEET BY SENDING FIELD CATALOG AND DATA TAB

STEP2 # Convert text table to xstring.

CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'

IMPORTING

buffer = l_content

TABLES

text_tab = lt_data_tab

EXCEPTIONS

failed = 1

OTHERS = 2.

STEP3 *# Psss Data to Netweaver

PERFORM pass_data_to_nw USING is_import

CHANGING es_attachment_metadata.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I don't see where you are converting the data to Excel format. What is lt_data_tab and how did you build it? Is it just an ABAP internal table? If you want Excel format you need to convert to something Excel understands. If you want complex formatting in Excel you should consider using an XSTL to transform your data in to the Excel XML format. This is very similiar to what the ALV does for exporting data to Excel. On that subject - why are you manually building this export to Excel. Why not just display the data in an ALV component and use the SAP provided functionality for export to Excel?

Former Member
0 Kudos

Hi Thomas,

lt_data_tab is a text string genereated with data in excel fromat. after that i am converting string to xstring.

as following i am preparing string in excel format.

PERFORM f_common_part_xml TABLES lt_data_tab.

PERFORM f_excel_sheet TABLES <dyn_table>

it_fieldcat

lt_data_tab

USING wa_tablename.

I canot use ALV component for my requirement. Please suggest if any solution.