|Home • Trainings •Quiz • Tips • Tutorials • Functional • Cert Q's • Interview Q's • Jobs • Testimonials • Advertise • Contact Us|
Downloading report output to Excel using OLE
In this scenario we want some columns to be merged in our excel output.
i.e. (column from A1 to E1,
column from B1 to E1, etc..)
Now, for this first we select the range of cells. And then merge the
range of cells.
CALL METHOD OF gh_excel ‘RANGE’ = gh_rang NO FLUSH
EXPORTING #1 = ‘A1’
CALL METHOD OF gh_range ‘SELECT’ NO FLUSH.
PROPERTY OF gh_range ‘MERGE’ = 1 no flush.
Now format the excel according to the requirement.
To set the width of the column according to the text.
CALL METHOD OF application 'COLUMNS' = COLUMN.
To delete some line from the excel, then can call this method,
CALL METHOD OF gh_excel 'ROWS' = row
Free object row.
To change the format of some cells in excels.
For doing this first set the ranges of the cell we want to format and
then change the format of these cells.
e.g. this will set last 1st row 4th
CALL METHOD OF gh_excel 'Cells' = wf_cell_from1
last 3rd row 4th column.
CALL METHOD OF gh_excel 'Cells' = wf_cell_to1
the range here,
Format the range of cells here
have grid lines in our excel output.
For this first set the ranges of the column.
CALL METHOD OF gh_excel ‘RANGE’ = gh_range
EXPORTING #1 = ‘A1’
“starting from column A
#2 = ‘M’.
“up to column M
set the style of all the border position.
Left edge border, set the line style to 1.
CALL METHOD OF
gh_range ‘Borders’ = gh_borders
EXPORTING #1 = 7.
PROPERTY OF gh_borders 'LineStyle'= 1.
we can call this method for other positions.
right edge border, export with 10.
top edge border, export with 8.
bottom edge border, export with 9.
inside vertical border, export with 11.
inside horizontal border, export with 12.
will set the grid lines in excel like this,
Suppose we want to change
the color and width of any particular column.
METHOD OF gh_excel ‘Cells’ = e_cell
#1 = 1
#2 = 3
PROPERTY OF e_cell 'Interior' = e_color.
PROPERTY OF e_color 'ColorIndex' = 35.
PROPERTY OF e_cell 'ColumnWidth' = 20.
for different colors.
At last free all the reserved OLE objects.
i.e. Free object column.
CALL METHOD OF sheet 'SaveAs'
EXPORTING #1 = 'c:\your_excel.xls' "name of excel
#2 = 1. "file format
CALL METHOD OF sheet 'QUIT'.
This closes the Excel document
SET PROPERTY OF application 'visible' = 0.
It will close visible excel window and data is lost if not saved.
Now our data get saved into excel naming ‘your_excel’.
For the excel downloaded, click here.
Please send us your feedback/suggestions at webmaster@SAPTechnical.COM
©2006-2007 SAPTechnical.COM. All rights reserved.
product names are trademarks of their respective companies. SAPTechnical.COM
is in no way affiliated with SAP AG.
Graphic Design by Round the Bend Wizards