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

GUI_DOWNLOAD - Column Width

Former Member
0 Likes
3,004

Hi all,

I have a requirement to use gui download but im having problem in its column width, i want the excel to have a column width same as the title of the column, is this possible (to have different column width in the output excel file)

Thanks.

5 REPLIES 5
Read only

Former Member
0 Likes
1,453

question is not clear!!

Read only

Former Member
0 Likes
1,453

Hi,

You can try this,may be it work...

1) To change the column width of one particular cell

CREATE OBJECT h_excel 'EXCEL.APPLICATION' NO FLUSH.

SET PROPERTY OF h_excel 'Visible' = 1.

CALL METHOD OF h_excel 'Cells' = h_zl EXPORTING #1 = 1 #2 = 1. "Here we are changing 1st R 1st C

SET PROPERTY OF h_zl 'Columnwidth' = .. "your data

2)To change the column width of range of cells

CALL METHOD OF h_excel 'Cells' = h_zl1 EXPORTING #1 = 1 #2 = 1."1st row 1st column

CALL METHOD OF h_excel 'Cells' = h_zl2 EXPORTING #1 = 100 #2 = 1. "100th row first column

CALL METHOD OF h_excel 'Range' = h_range

EXPORTING #1 = h_zl1 #2 = h_zl2. "This mmeans that first column of 100 records

SET PROPERTY OF h_range 'Columnwidth' = ..

3.

DATA: H_COLUMNS TYPE OLE2_OBJECT.

CALL METHOD OF EXCEL 'Columns' = H_COLUMNS

EXPORTING

#1 = 'A:E'. " which columns you want to choose

SET PROPERTY OF h_columns 'ColumnWidth' = 17.

Read only

Former Member
0 Likes
1,453

Hi,

Refer the below mentioned sample code:






INCLUDE ole2incl.                       "include used for providing classes used for using create object for creating application and worksheets
DATA: application TYPE ole2_object,
       workbook TYPE ole2_object,
       sheet TYPE ole2_object,
       cells TYPE ole2_object.
CONSTANTS: row_max TYPE i VALUE 256.
DATA index TYPE i.

*DATA: BEGIN OF itab1 OCCURS 0, first_name(10), END OF itab1.
*DATA: BEGIN OF itab2 OCCURS 0, last_name(10), END OF itab2.
DATA: BEGIN OF itab3 OCCURS 0, formula(50), END OF itab3.
*


TABLES: vbap,mara.


TYPES: BEGIN OF itab,
       lifnr TYPE lfa1-lifnr,
       land1 TYPE lfa1-land1,
*       name1 TYPE lfa1-name1,
*       ort01 TYPE lfa1-ort01,
       END OF itab.



DATA: BEGIN OF itab2 OCCURS 0,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
END OF itab2.
 data : v_row type sy-tabix.

DATA: itab1 TYPE STANDARD TABLE OF itab WITH HEADER LINE.

DATA: IT_XLSTAB TYPE STANDARD TABLE OF ITAB ,
      WA_XLSTAB LIKE LINE OF IT_XLSTAB.

START-OF-SELECTION.

  SELECT lifnr land1 fROM lfa1  INTO CORRESPONDING FIELDS OF TABLE itab1 UP TO 5 ROWS.


  SELECT matnr
  ersda
  ernam
  FROM mara
  INTO CORRESPONDING FIELDS OF
  TABLE itab2 UP TO 5 ROWS.



************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.

  CREATE OBJECT application 'excel.application'.
  SET PROPERTY OF application 'visible' = 1.
  CALL METHOD OF application 'Workbooks' = workbook.
  CALL METHOD OF workbook 'Add'.

* Create first Excel Sheet
  CALL METHOD OF application 'Worksheets' = sheet
                               EXPORTING #1 = 1.
  CALL METHOD OF sheet 'Activate'.
  SET PROPERTY OF sheet 'Name' = 'Sheet1'.
  clear v_row.
  LOOP AT itab1.
     v_row = sy-tabix.
      perform fill_cell  using  v_row 1  itab1-lifnr.
      perform fill_cell  using  v_row 2 itab1-land1.
  ENDLOOP.

* Create second Excel sheet
  CALL METHOD OF application 'Worksheets' = sheet
                               EXPORTING #1 = 2.
  SET PROPERTY OF sheet 'Name' = 'Sheet2'.
  CALL METHOD OF sheet 'Activate'.
  clear v_row.
  LOOP AT itab2.
     v_row = sy-tabix.

      perform fill_cell using  v_row 1 itab2-matnr.
      perform fill_cell using  v_row 2 itab2-ersda.
      perform fill_cell using  v_row 3 itab2-ernam.

  ENDLOOP.


* Save excel speadsheet to particular filename
  CALL METHOD OF sheet 'SaveAs'
                  EXPORTING #1 = 'c:\temp\excelgeet.xls'     "filename
                            #2 = 1.                          "fileFormat

*  Closes excel window, data is lost if not saved
  SET PROPERTY OF application 'visible' = 0.

*  call method of sheet 'CLOSE'
*
*  EXPORTING #1 = 'YES'.


*&---------------------------------------------------------------------*
*& both the below coding closes the apllication permanently from the task manager also.
*&---------------------------------------------------------------------*

SET PROPERTY OF application 'DisplayAlerts' = 0.
   free OBJECT application.


**  call method of application 'QUIT'.
**
**  FREE OBJECT: APPLICATION,
**               SHEET.

*&---------------------------------------------------------------------*
*&      Form  fill_cell
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_1      text
*      -->P_V_COL  text
*      -->P_ITAB1_LIFNR  text
*----------------------------------------------------------------------*
form fill_cell  using row  col val.

    CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = row  #2 = col.
    SET PROPERTY OF cells 'Value' = val.


endform.                    " fill_cell


Hope it helps

Regards

Mansi

Read only

Former Member
0 Likes
1,453

For Vishnu Paval:

I have this kind of data in internal table:

001 002 003 004

with this title in their header:

Title1 Title2 Title3 Title4

After Gui dowload i'm required to have a excel file with this output:

Title1 Title2 Title3 Title4

001 002 003 004

I want to know if its possible to set each of the column size according to my header width.

Read only

0 Likes
1,453

Hi,

You can set specific output length for your columns via wa_fieldcat-outputlen or by setting the lwa_layout-colwidth_optimize to 'X' so that the system automatically adjusts the widht of your column depemding on the data .

Regards.