on 02-22-2010 12:14 PM
Hi all,
Am downloading the content of UI table in screen on click of a UI button 'EXPORT' using the following method.
DATA: lo_nd_n_one TYPE REF TO if_wd_context_node,
lt_temp TYPE STANDARD TABLE OF ztable
wa_temp LIKE LINE OF li_temp,
table_string TYPE string,
table_xstring TYPE xstring,
lv_amount TYPE string.
lo_nd_n_one = wd_context->get_child_node( name = wd_this->wdctx_n_one ).
CALL METHOD lo_nd_n_one->get_static_attributes_table
IMPORTING
table = lt_temp.
if row is selected
IF li_temp[] IS NOT INITIAL.
concatenate the column heading into a single line seperated by horizontal tab
CONCATENATE ' ' lc_billno lc_billdate lc_vendesc lc_invno lc_value lc_desc lc_status lc_appremarks
cl_abap_char_utilities=>newline INTO table_string SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
get each row from table and concatenate into string variable
LOOP AT lt_temp INTO wa_temp.
CLEAR lv_amount.
lv_amount = wa_temp-field_five.
concatenate the column values into a single line seperated by horizontal tab
CONCATENATE table_string
wa_temp-field_one wa_temp-field_two wa_temp-field_three wa_temp-field_Four lv_amount wa_temp-field_six wa_temp-seven
cl_abap_char_utilities=>cr_lf INTO table_string SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ENDLOOP.
FM to convert string format to xstring format for downloading to excel sheel
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = table_string
IMPORTING
buffer = table_xstring.
create excel sheet
CL_WD_RUNTIME_SERVICES=>attach_file_to_response( i_filename = 'SAMPLE.XLS'
i_content = table_xstring
i_mime_type = 'EXCEL' ).
ENDIF.
I am able to download the contents into 'EXCEL' sheet. But the problem in my first column i.e COLUMN 'A' is blank for the entire content from the table. The header was coming properly from COLUMN A. The contents are starting from the COLUMN 'B'.
As a temporary solution i have added a space for the header so that it starts from COLUMN B itself.
Please explain how to overcome this problem.
Not really WDA related, but your problem is in this line of code:
CONCATENATE table_string
wa_temp-field_one wa_temp-field_two wa_temp-field_three wa_temp-field_Four lv_amount wa_temp-field_six wa_temp-seven
cl_abap_char_utilities=>cr_lf INTO table_string SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
You are concatenating the previous section of the string and then the fields with the SEPARATED BY Tab. That means you are inserting an extra horizontal tab before your first column of data. That is the reason why your data is starting in Column B - this extra tab.
Instead concatenate your fields into a temporary string and then combine that with the table_string.
CLEAR tmp_string.
CONCATENATE
wa_temp-field_one wa_temp-field_two wa_temp-field_three wa_temp-field_Four lv_amount wa_temp-field_six wa_temp-seven
cl_abap_char_utilities=>cr_lf INTO tmp_string SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
CONCATENATE table_string tmp_string into table_string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thomas,
The solution given by you solved my issue. Thanks a lot.
I have one more query regarding the format of the downloaded excel sheet.
It can be seen that the excel sheet columns widths are reduced when we open the excel sheet. So we are manually expanding the columns to view the entire data in a column.
Is there any solution for solving this issue.
Is it possible to allign the contents of a particular. (Because for a given column some of the values are left aligned and some other aligned).
You aren't going to be able to control any formatting with the text-tab delimited file format. It is a very basic - yet simple to program - way of getting data into Excel. But you only have the possibility to pass the raw data, not any metadata or formatting. If you need to pass formatting information into Excel, then you should consider using the Excel XML format.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.