Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

excel download problem

Former Member
0 Likes
1,621

Hello friends,

I am using FM 'gui_download' to download data into

excel sheet.

But the fields on the excel sheet gets compressed in length

while downloading.

So what should I do in order to get the data with proper field length.

Please reply my query as this is urgent.

Regards,

Sapna Agarwal

13 REPLIES 13
Read only

Former Member
0 Likes
1,341

Hi

I excel sheet adjust the colum width,then you will get the required data

Regards

Shibin

Read only

0 Likes
1,341

Hi Shibin,

Actually I dont manually want to adjust the column in the downloaded file.

what i need to do is to get the adjusted columns at runtime.

regards,

Sapna Agarwal

Read only

Former Member
0 Likes
1,341

hi,

use this fucntion module 'WS_EXCEL' to solve your issue......

reward points if useful...........

Read only

0 Likes
1,341

Hi All,

I would like to download the excel with proper field length. I don't like to do manually the column adjustment after downloading the excel sheet. Please answer my query.

Thanks,

Umashankar

Read only

Former Member
0 Likes
1,341

Hi Sapna,

You can try the following FMs

Gui_download is one of them the others are :

1)in class CL_GUI_ALV_GRID there is a method called EXPORT_TO_SPREAD_SHEET

2) 'RH_START_EXCEL_WITH_DATA'

using gui_download

3) SAP_CONVERT_TO_XLS_FORMAT

Regards,

Lalit

Read only

Former Member
0 Likes
1,341

Hi Sapna,

Have you solved your problem?. If yes can you please tell me the solution.

Thanks,

Umashankar

Read only

Former Member
0 Likes
1,341

You can use FM 'SAP_CONVERT_TO_XLS_FORMAT' to download in excel format

Read only

Subhankar
Active Contributor
0 Likes
1,341

Hi,

To download in excel use the following code. First you need to create one excel container at initialization event. Then download the same.

form sub_create_container .

  • Create Instance control for container

call method c_oi_container_control_creator=>get_container_control

importing

control = iref_control

error = iref_error.

if iref_error->has_failed = c_check.

call method iref_error->raise_message

exporting

type = 'E'.

endif.

  • Create generic container linked to container in screen 100

create object oref_container

exporting

container_name = 'CONT'

exceptions

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

others = 6.

if sy-subrc <> 0.

message e000 with 'Error while creating container'(012).

endif.

  • Establish connection to GUI Control

call method iref_control->init_control

exporting

inplace_enabled = c_check

r3_application_name = 'EXCEL CONTAINER'

parent = oref_container

importing

error = iref_error

exceptions

javabeannotsupported = 1

others = 2.

if iref_error->has_failed = c_check.

call method iref_error->raise_message

exporting

type = 'E'.

endif.

  • Create Document Proxy

call method iref_control->get_document_proxy

exporting

document_type = soi_doctype_excel_sheet

importing

document_proxy = iref_document

error = iref_error.

if iref_error->has_failed = c_check.

call method iref_error->raise_message

exporting

type = 'E'.

endif.

endform.

Thanks

Subhankar.

Edited by: Subhankar Garani on Mar 23, 2010 5:22 AM

Read only

Subhankar
Active Contributor
0 Likes
1,341

Use my previous post for container creation and for downloading use..

data: l_title type char40,

l_sheet type char12.

clear: v_row.

describe table <i_itab> lines v_row.

v_row = v_row + 1.

  • Populate the column heading

perform sub_pop_col_heading.

concatenate 'Assembly Table' v_char into l_title separated by space.

  • Create document

call method iref_document->create_document

exporting

open_inplace = c_check

document_title = l_title

no_flush = c_check

importing

error = iref_error.

  • Open Spreadsheet interface

call method iref_document->get_spreadsheet_interface

exporting

no_flush = c_check

importing

sheet_interface = iref_spreadsheet

error = iref_error.

  • Get number of sheets

call method iref_spreadsheet->get_sheets

exporting

no_flush = c_check

importing

sheets = i_sheets

error = iref_error.

read table i_sheets into wa_sheets index 1.

if sy-subrc = 0.

l_sheet = wa_sheets-sheet_name.

endif.

  • Select sheet

call method iref_spreadsheet->select_sheet

exporting

name = l_sheet

no_flush = c_check

importing

error = iref_error.

call method iref_spreadsheet->set_selection

exporting

top = 1

left = 1

rows = 1

columns = 1

no_flush = c_check

importing

error = iref_error.

call method iref_spreadsheet->insert_range

exporting

name = 'PRANGE'

rows = v_row

columns = v_col

no_flush = c_check

importing

error = iref_error.

  • Set the format of the cells

call method iref_spreadsheet->set_format

exporting

rangename = 'PRANGE'

typ = 0

currency = 'USD'

no_flush = 'X'

  • decimals = 2

importing

error = iref_error.

  • Get field names

call function 'DP_GET_FIELDS_FROM_TABLE'

tables

data = <i_itab>

fields = i_field_tab.

  • Insert records

call method iref_spreadsheet->insert_one_table

exporting

data_table = <i_itab>

fields_table = i_field_tab

rangename = 'PRANGE'

wholetable = c_check

no_flush = c_check

importing

error = iref_error.

Thanks

subhankar

Read only

Former Member
0 Likes
1,341

Hi Dude,

Thanks for your reply. Will it apply to the excel sheet that will be sent in mail by report execution.

Say suppose if i execute the report and once it is done the output will be mailed to our user id given in the selection screen.

Once you open the excel sheet in your mail, the colum should be adjusted as per the text size.

Is it possible?

Thanks,

Umashankar

Read only

Former Member
0 Likes
1,341

Hi,

You can try using FM:

XXL_FULL_API

ALSM_EXCEL_TO_INTERNAL_TABLE

and also FM:

GUI_DOWNLOAD wherein the filename parameter you can give its value as .XLS.

Hope it helps

Regards

Mansi

Read only

OttoGold
Active Contributor
0 Likes
1,341

Or you can try to follow one of these blogs:

/people/otto.gold/blog/2010/02/09/happy-reporting-with-abap-ole-excel

/people/otto.gold/blog/2010/02/11/happy-reporting-with-excel-ii

Regards Otto

Read only

Former Member
0 Likes
1,341

if use version 4.7 then use OPEN DATASET filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.