on 05-06-2015 1:01 PM
Hi,
I am using below piece of code to download and upload(same excel) into WD screen using SALV_WD_TABLE in my custom component. Download and upload both are happening successfully.
I am facing two issues. Please help me on them
Issue 1. If I download the excel and make some changes into it. Excel shows error as below.
Test.xls may contain features that are not compatible with Text(Tab Delimited). Do you want to keep the workbook in this format ?
To keep this format, which leave out any incompatible features, click Yes
To preserve the features, click No, then save a copy in the latest excel format.
I tried YES and Saved it and tried to upload using below code, system gives me rum error on browser. In runtime, I can see variable l_string contains so many # # # symbols.
I tried No also and Made a copy then also. the same thing happens as above.
Please tell me where I am making mistakes in my code as I guess that It's some incorrect excel format compatibility issue. I want to use .xlsx format. .xls will also do if .xlsx if not possible.
Issue 2. in downloaded excel, my columns are starting from column B of excel. means first columns is downloaded empty and table starts from 2nd column.
Code to download excel
CALL METHOD lo_nd_vbak->get_static_attributes_table
EXPORTING
from = 1
to = 2147483647
IMPORTING
table = ls_vbak.
DATA : lv_qua(10) TYPE c,
lv_price(10) TYPE c.
LOOP AT ls_vbak INTO lw_vbak.
CLEAR : lv_qua, lv_price.
lv_qua = lw_vbak-zquan. "For non-char to char conversion
lv_price = lw_vbak-zprice.
CONCATENATE str
lw_vbak-colum
lw_vbak-matnr
lv_qua
lv_price
lw_vbak-desc
cl_abap_char_utilities=>newline INTO str
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ENDLOOP.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = str
mimetype = ' '
* ENCODING =
IMPORTING
buffer = xstr
EXCEPTIONS
failed = 1.
CALL METHOD cl_wd_runtime_services=>attach_file_to_response
EXPORTING
i_filename = 'Test.xls'
i_content = xstr
i_mime_type = 'EXCEL'
* i_mime_type = 'APPLICATION/XLS'
i_in_new_window = abap_false
i_inplace = abap_false.
Code to upload excel.
wd_context->get_attribute(
EXPORTING
name = `DATASOURCE`
IMPORTING
value = l_xstring ).
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
in_xstring = l_xstring
IMPORTING
out_string = l_string.
* SPLIT l_string AT cl_abap_char_utilities=>newline INTO TABLE i_data.
FIND cl_abap_char_utilities=>cr_lf IN l_string.
IF sy-subrc = 0.
SPLIT l_string AT cl_abap_char_utilities=>cr_lf INTO TABLE i_data.
ELSE.
SPLIT l_string AT cl_abap_char_utilities=>newline INTO TABLE i_data.
ENDIF.
* Bind With table Element.
LOOP AT i_data INTO l_string.
SPLIT l_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE fields.
READ TABLE fields INTO lv_field INDEX 1.
fs_table-colum = lv_field.
READ TABLE fields INTO lv_field INDEX 2.
fs_table-matnr = lv_field.
READ TABLE fields INTO lv_field INDEX 3.
fs_table-quan_commtd = lv_field.
READ TABLE fields INTO lv_field INDEX 4.
fs_table-pric_commtd = lv_field.
READ TABLE fields INTO lv_field INDEX 5.
fs_table-desc = lv_field.
APPEND fs_table TO t_table1.
ENDLOOP.
Could anyone please help me. Thanks a lot in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ratnesh,
In your code, your are concatenating an empty string being separated by a horizontal tab. That is why you are always getting an empty first column.
Please refer the below doc for downloading the content in .XLSX format. I always used to prefer this way of code, as it gives a rich look and so easy too.
You can call the method
cl_fdt_xl_spreadsheet=>if_fdt_doc_spreadsheet~create_document(
EXPORTING
itab = lref_data
iv_call_type = 1
columns = lt_column
RECEIVING
xdocument = lv_xstring ).
lref_data is your input content that needs to be downloaded as data and lt_column is a separate local table that you need to pass the column name. That's all, please try it this and let me know in-case you do have any doubt.
This design will sort all of your issues.
BR,
RAM.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
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.