10-30-2007 10:41 AM
Hi Friends,
When I am writing report in OLE( excel ), some of the fields which are having leading zeros automatically deleted . It shoud not happen . I have to display leading zeros also.
Please tell me which class and method to do this ...
Thanks ,
Varma
10-30-2007 10:46 AM
Hi,
Try adding the character ' (single quote) before the actual value. Excel then treats the value as-is whithout conversion.
Hope this helps (please reward me if it does).
Regards, Joerg
10-30-2007 10:55 AM
Joerg
You are right ...But it will display as some warning message . Client don't want that ...I tried with Different classes and methods also. Might be the way I am writing code could be wrong . If I get class and method how to write code for that can you help me in this ??
Thanks in adv
Varma
10-30-2007 11:02 AM
Hi Varma,
What kind of warnigs do you get?
Also, there might be another way. Use the clipboard to transfer the data from SAP to EXCEL. This works quite well. Use the class method cl_gui_frontend_services=>clipboard_export and provide the data as an internal table of string separated by tab characters.
Or you can use GUI_DOWNLOAD to create a CSV file and open it in EXCEL...
Regards, Joerg
10-30-2007 10:59 AM
Use OLE itself to set the formatting of the cell (or column itself) to character type
* character type for columns
data: h_columns TYPE ole2_object,
h_cell TYPE ole2_object.
CALL METHOD OF excel 'Columns' = h_columns
EXPORTING
#1 = 'F:K'.
set property of h_columns 'NumberFormat' = '@'.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = 14
#2 = 7.
SET PROPERTY OF h_cell 'Value' = '0001'.
10-30-2007 11:02 AM
In the above case, I have set the formatting of columns F to K as Text type
To do the same thing in excel itself, Right click on the Column -> format cells -> click on Text, then click on OK