Regading Excel Creation using OLE
hi friends,
i got a new requirement where i have to create the Excel document using OLE. one more thing is some cells has to be filled with some colour and in some cells the text has to come in Vertical manner, this text is used for Header purpose.
please help me urgently...
Suitable Answers will get more points..........
Hello,
Also take a look at this code
*& Report ZKRIS_OLE3_PALETTE
*& Displays the full OLE color range in excel
REPORT ZKRIS_OLE3_PALETTE.
TYPE-POOLS ole2 .
DATA: count TYPE i,
count_real TYPE i,
application TYPE ole2_object,
workbook TYPE ole2_object,
excel TYPE ole2_object,
sheet TYPE ole2_object,
cells TYPE ole2_object.
CONSTANTS: row_max TYPE i VALUE 256. " change to 16384 for excel 2007
DATA index TYPE i.
DATA:
h_cell TYPE ole2_object, " cell
h_f TYPE ole2_object, " font
h_int TYPE ole2_object,
h_width TYPE ole2_object,
h_columns TYPE ole2_object,
h_rows TYPE ole2_object,
h_font TYPE ole2_object,
h_entirecol TYPE ole2_object.
DATA: h_range TYPE ole2_object.
DATA: h_merge TYPE ole2_object.
CREATE OBJECT excel 'EXCEL.APPLICATION'.
IF sy-subrc NE 0.
WRITE: / 'No EXCEL creation possible'.
STOP.
ENDIF.
SET PROPERTY OF excel 'DisplayAlerts' = 0.
CALL METHOD OF excel 'WORKBOOKS' = workbook .
SET PROPERTY OF excel 'VISIBLE' = 1.
* creating workbook
SET PROPERTY OF excel 'SheetsInNewWorkbook' = 1.
CALL METHOD OF workbook 'ADD'.
CALL METHOD OF excel 'WORKSHEETS' = sheet
EXPORTING
#1 = 1.
SET PROPERTY OF sheet 'NAME' = 'Color Palette'.
CALL METHOD OF sheet 'ACTIVATE'.
DATA: col TYPE i VALUE 1,
row TYPE i VALUE 2,
col1 TYPE i VALUE 2,
col_real TYPE i VALUE 1.
row = 1.
col = 3.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF h_cell 'Value' = 'No.'.
col = col + 1.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF h_cell 'Value' = 'Background'.
col = col + 1.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF h_cell 'Value' = 'Foreground with white background'.
col = col + 1.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF h_cell 'Value' = 'Foreground with black background'.
CALL METHOD OF excel 'Rows' = h_rows
EXPORTING
#1 = '2:2'.
SET PROPERTY OF h_rows 'WrapText' = 1.
col = 9.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF h_cell 'Value' = 'No.'.
col = col + 1.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF h_cell 'Value' = 'Background'.
col = col + 1.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF h_cell 'Value' = 'Foreground with white background'.
SET PROPERTY OF h_cell 'Bold' = 1.
col = col + 1.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF h_cell 'Value' = 'Foreground with black background'.
CALL METHOD OF excel 'Rows' = h_rows
EXPORTING
#1 = '1:1'.
SET PROPERTY OF h_rows 'WrapText' = 1.
GET PROPERTY OF h_rows 'Font' = h_font.
SET PROPERTY OF h_font 'Bold' = 1.
count = 1.
count_real = count.
row = 2.
col = 3.
DO 56 TIMES.
PERFORM write_num_and_color.
ENDDO.
* autofit
CALL METHOD OF excel 'Columns' = h_columns
EXPORTING
#1 = 'C:L'.
GET PROPERTY OF h_columns 'EntireColumn' = h_entirecol.
SET PROPERTY OF h_entirecol 'Autofit' = 1.
* write palette on lhs
*range
CALL METHOD OF excel 'Range' = h_range
EXPORTING
#1 = 'A2'
#2 = 'A20'.
CALL METHOD OF h_range 'Merge' = h_merge .
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = 2
#2 = 1.
SET PROPERTY OF h_cell 'Value' = 'Palette'.
SET PROPERTY OF h_cell 'Orientation' = 90. "angled.
SET PROPERTY OF h_cell 'HorizontalAlignment' = 3. "center align
GET PROPERTY OF h_cell 'Font' = h_f.
SET PROPERTY OF h_f 'Bold' = 1. "bold
SET PROPERTY OF h_f 'Name' = 'Comic Sans MS'.
SET PROPERTY OF h_f 'Size' = '14'.
SET PROPERTY OF h_cell 'VerticalAlignment' = 2. "center align
* autofit
CALL METHOD OF excel 'Columns' = h_columns
EXPORTING
#1 = 'A:A'.
GET PROPERTY OF h_columns 'EntireColumn' = h_entirecol.
SET PROPERTY OF h_columns 'ColumnWidth' = 4.
*& Form write_num_and_color
* text
FORM write_num_and_color.
index = row_max * ( row - 1 ) + col.
CALL METHOD OF sheet 'Cells' = cells
EXPORTING
#1 = index.
SET PROPERTY OF cells 'Value' = count_real.
col = col + 1.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
GET PROPERTY OF h_cell 'Interior' = h_int.
SET PROPERTY OF h_int 'ColorIndex' = count_real.
col = col + 1.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF h_cell 'Value' = 'Sample Text'.
GET PROPERTY OF h_cell 'Font' = h_f.
SET PROPERTY OF h_f 'ColorIndex' = count_real.
col = col + 1.
CALL METHOD OF excel 'Cells' = h_cell
EXPORTING
#1 = row
#2 = col.
GET PROPERTY OF h_cell 'Interior' = h_int.
SET PROPERTY OF h_int 'ColorIndex' = 1.
SET PROPERTY OF h_cell 'Value' = 'Sample Text'.
GET PROPERTY OF h_cell 'Font' = h_f.
SET PROPERTY OF h_f 'ColorIndex' = count_real.
row = row + 1.
col = col - 3.
count = count + 1.
IF count = 29.
count = 1.
row = 2.
col = col + 6.
ENDIF.
count_real = count_real + 1.
ENDFORM. "write_num_and_color
Similar Messages
-
Data download to multiple sheets in Excel without using OLE
Hi,
Please let me know if it is possible to download data to multiple sheets in excel without using OLE method
I am in SRM system and the OLE methods are not working
Please share some sample code or reference links if any
Thanks
SekharJ
Edited by: SekharJ on Sep 8, 2009 8:43 AMHere is my code
LOOP AT it_final INTO wa_final.
AT FIRST.
l_ixml = cl_ixml=>create( ).
l_document = l_ixml->create_document( ).
l_element_flights = l_document->create_simple_element(
name = 'PO_Details'
parent = l_document ).
ENDAT.
l_element_airline = l_document->create_simple_element(
name = 'PO'
parent = l_element_flights ).
l_value = wa_final-object_id.
l_rc = l_element_airline->set_attribute( name = 'Objectid' value =
l_value ).
l_value = wa_final-description.
l_rc = l_element_airline->set_attribute( name = 'Description' value =
l_value ).
l_value = wa_final-number_int.
l_rc = l_element_airline->set_attribute( name = 'Item' value =
l_value ).
l_value = wa_final-description1.
l_rc = l_element_airline->set_attribute( name = 'Description1' value =
l_value ).
l_value = wa_final-quantity.
l_rc = l_element_airline->set_attribute( name = 'Quantity' value =
l_value ).
l_value = wa_final-capex.
l_rc = l_element_airline->set_attribute( name = 'Capex' value =
l_value ).
l_value = wa_final-ser_num.
l_rc = l_element_airline->set_attribute( name = 'SerialNo' value =
l_value ).
l_value = wa_final-plant.
l_rc = l_element_airline->set_attribute( name = 'Plant' value =
l_value ).
l_value = wa_final-loc.
l_rc = l_element_airline->set_attribute( name = 'Location' value =
l_value ).
l_value = wa_final-bundle.
l_rc = l_element_airline->set_attribute( name = 'Bundle' value =
l_value ).
ENDLOOP.
l_streamfactory = l_ixml->create_stream_factory( ).
l_ostream = l_streamfactory->create_ostream_itable( table =
l_xml_table ).
l_renderer = l_ixml->create_renderer( ostream = l_ostream
document = l_document ).
l_rc = l_renderer->render( ).
l_xml_size = l_ostream->get_num_written_raw( ).
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = l_xml_size
filename = 'c:\temp\flights.xlsx'
filetype = 'BIN'
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 24.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Edited by: SekharJ on Sep 8, 2009 12:04 PM
Edited by: SekharJ on Sep 8, 2009 12:15 PM -
I have a problem in formatting cells in Excel while using OLE method.
Hi All,
I have a problem in formatting cells in Excel while using OLE method.
My requirement is to have certain fields of a cell as text and amount fields should be in number format.
How to format a cell in Excel in OLE method of downloading data to excel.
For example I have plant field whose value is 0002 in internal table while coming to excel it is showing as 2 .
I want that field to be shown as 0002.(text format)
Material field whose value in internal table is 000000000000000051 is shown as 51 which has to be shown as
000000000000000051.(text format).
Amount field should be in number format so that totalling is possible .
So I need some cells in text format and some in number format.
Please suggest a sloution.
Thanks in advance,
Regards,
vidyulatha.Uhttps://forums.sdn.sap.com/click.jspa?searchID=21931962&messageID=6852860
hope this helps. -
Is it possible to create Excel Sheet using OLE automation in App server
Hi,
Is it possible to create Excel Sheet using OLE automation in Application server(Open Dataset)
Thanks in advance...Unless your application server is on Windows OS, or it is connected to a Windows server by RFC. What is the requirement exactly, I don't understand?
-
Call Excel SpreadSheet using OLE and set format = text
Hi All,
I am working on an object, where I need to call Excel SpreadSheet using OLE.
In SpreadSheet, I need to show data as text (Without Excel Internal Modifications).
i.e
if i pass 03/2007 as month in excel, it should show 01/2007 not jan-07.
I am trying to use the code as below.
call method of cell 'SET_FORMAT' = text.
set property of text 'CATEGORY' = 4.
this code is not giving me desired output.
Is there any other method i can call? or property I can set?
can somebody pls send me a document with list of all formattiong methods and properties. I will really appreciate the help.
Regards,
HardikHi, you should concatenate the character ( ' ) into your text, example
CONCATENATE '''' text INTO text.
Then print the variable Text into excel and you will see the format as Text,
Thanks and regards.
David Carballido
PD: Sry for my bad English -
Prevent copy of excel cells using OLE
Hi All,
I have protected my excel worksheet. But the cells can be copied. I want to prevent this copy of cells using OLE.
I have gone through the EXCEL proerties. But dont know how to exact use them?
Thanks in Advance
-nehaHello Neha,
I don't think CutCopyMode is the correct answer
Try the below code. It prevents the selection of cells, hence preventing copying.
REPORT zkris_ole_protectsheet.
* Start of Selection *
START-OF-SELECTION.
TYPE-POOLS ole2 .
DATA:
workbook TYPE ole2_object,
excel TYPE ole2_object,
sheet TYPE ole2_object,
cells TYPE ole2_object.
CREATE OBJECT excel 'EXCEL.APPLICATION'.
IF sy-subrc NE 0.
WRITE: / 'No EXCEL creation possible'.
STOP.
ENDIF.
SET PROPERTY OF excel 'DisplayAlerts' = 0.
CALL METHOD OF excel 'WORKBOOKS' = workbook .
SET PROPERTY OF excel 'VISIBLE' = 1.
* creating workbook
SET PROPERTY OF excel 'SheetsInNewWorkbook' = 1.
CALL METHOD OF workbook 'ADD'.
CALL METHOD OF excel 'WORKSHEETS' = sheet
EXPORTING
#1 = 1.
* naming and activating the index sheet
SET PROPERTY OF sheet 'NAME' = 'Index'.
CALL METHOD OF sheet 'ACTIVATE'.
CALL METHOD OF sheet 'Cells' = cells
EXPORTING
#1 = 3
#2 = 3.
SET PROPERTY OF cells 'Value' = 'You cannot select me'.
CALL METHOD OF sheet 'PROTECT'
EXPORTING
#1 = 'pass' " Password
#2 = 1 " Protect Drawing Objects
#3 = 1 " Protect Contents
#4 = 1." Protect Scenarios
SET PROPERTY OF sheet 'EnableSelection' = -4142. -
To Display Logo on all the pages of Excel Sheet using OLE
Dear friends,
I have developed one report using OLE which display output in Excel. I have display logo using OLE.
I am able to display logo on first page of excel sheet. but I am not able to display it on all the pages.
Need your help. Please, suggest any good solution.
Thanks & Regards,
Sandip SonarExcel repeats only HEADER and FOOTER information on every page. The data on cell is relevant only for that page.
If you want to print something on every page in Excel, you will have to include it on HEADER/FOOTER section of the excel file.
To check this, go to excel, on meny go to File->PageSetup. Then select Header/Footer Tab... select Custom Header or custom footer.
Whatever you inset here (including image) will be printed on every page of Excel. Don't know OLE property to set this but I feel something should be available to set custom header footer for your file. -
Setting the aixs minimum in excel chart using OLE.
Hi All,
The problem am facing is that say if all the values in the chart data range is high then excel adjusts itself so that the axis minimum doesn't start from zero. But i need the axis to always start from zero. How do i set this using OLE?Hi
Here is ur expected coding...
REPORT ZCREATEEXCEL.
TYPE-POOLS OLE2.
DATA: EXCEL TYPE OLE2_OBJECT,
WORKBOOKS TYPE OLE2_OBJECT,
WORKBOOK TYPE OLE2_OBJECT.
DATA: FILENAME LIKE RLGRAP-FILENAME.
START THE EXCEL APPLICATION
CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.
PERFORM ERR_HDL.
PUT EXCEL IN FRONT
SET PROPERTY OF EXCEL 'VISIBLE' = 1.
PERFORM ERR_HDL.
INFORM USER OF THE CURRENT STATUS
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = 0
TEXT = TEXT-I08
EXCEPTIONS
OTHERS = 1.
CREATE AN EXCEL WORKBOOK OBJECT
CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOKS.
PERFORM ERR_HDL.
CALL METHOD OF WORKBOOKS 'ADD' = WORKBOOK.
PERFORM ERR_HDL.
EXCEL FILENAME
CONCATENATE SY-REPID '_' SY-DATUM6(2) '_' SY-DATUM4(2) '_'
SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.
CALL METHOD OF WORKBOOK 'SAVEAS' EXPORTING #1 = FILENAME.
FORM ERR_HDL.
IF SY-SUBRC <> 0.
WRITE: / 'OLE ERROR: RETURN CODE ='(I10), SY-SUBRC.
STOP.
ENDIF.
ENDFORM.
Reward if usefull -
Problem in excel download using OLE concept
Hi ,
i am trying to create two sheets using OLE concept.
i am able to create the excel successfully but i can't save it .
i have one problem .
GET PROPERTY OF excel 'ActiveSheet' = sheet.
CALL METHOD OF sheet 'FILESAVEAS' EXPORTING #1 = w_filename1.
IF sy-subrc eq 0.
the sy-subrc value comes as 2.
i am passing 'C:\SKD.XLS' to w_filename.
is anything wrong.
how can check this method and it's exceptions.i am getting the file name from user input using the method
*"Calling method for getting file name as saved by the user.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = w_title
CHANGING
filename = w_filnam
path = w_path
fullpath = w_filename1
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
w_filename1 is of sting type .
i am passing the full path to it .
please let me i am doing anything wrong . -
Hi All,
Can any one help me to create an multiple excel sheet in an work book using OLE. I want to create more than 3 sheets in excel, which is default sheets in excel when we one excel.Hi,
Check the below sample code.
Here I'm downloading the same table twice into 2 different sheets for example purpose.
TYPE-POOLS ole2.
DATA: wf_cell_from TYPE ole2_object,
wf_cell_from1 TYPE ole2_object,
wf_cell_to TYPE ole2_object,
wf_cell_to1 TYPE ole2_object,
wf_excel TYPE ole2_object, " Excel object
wf_mapl TYPE ole2_object, " list of workbooks
wf_map TYPE ole2_object, " workbook
wf_worksheet TYPE ole2_object, " Worksheet
wf_cell TYPE ole2_object, " Cell Range
wf_cell1 TYPE ole2_object,
wf_range TYPE ole2_object, " Range of cells to be formatted
wf_range2 TYPE ole2_object,
wf_column1 TYPE ole2_object. " Column to be Autofit
DATA: BEGIN OF t_hex,
l_tab TYPE x,
END OF t_hex.
DATA: wf_deli(1) TYPE c, "delimiter
wf_action TYPE i,
wf_file TYPE string,
wf_path TYPE string,
wf_fullpath TYPE string.
TYPES: t_data1(1500) TYPE c,
int_ty TYPE TABLE OF t_data1. "line type internal table
*All the data was prepared as line type internal tables for faster
*download
DATA: int_matl TYPE int_ty ,
int_matl1 TYPE int_ty ,
wa_matl TYPE t_data1.
TYPES: BEGIN OF ty_mara,
matnr TYPE matnr,
mtart TYPE mtart,
matkl TYPE matkl,
meins TYPE meins,
END OF ty_mara.
DATA: int_mara TYPE STANDARD TABLE OF ty_mara,
wa_mara TYPE ty_mara.
FIELD-SYMBOLS: <fs> .
DATA: wc_sheets LIKE sy-index. "no.of sheets
DATA: it_tabemp TYPE filetable,
gd_subrcemp TYPE i.
CONSTANTS wl_c09(2) TYPE n VALUE 09.
CLEAR wc_sheets.
DEFINE ole_check_error.
if &1 ne 0.
message e001(zz) with &1.
exit.
endif.
END-OF-DEFINITION.
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
PARAMETERS: p_file LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK block1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
REFRESH: it_tabemp.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = 'Select File'
* default_extension = 'xls'
default_file_name = 'Material Details'
* with_encoding =
file_filter = '*.xls'
initial_directory = 'C:\'
prompt_on_overwrite = ' '
CHANGING
filename = wf_file
path = wf_path
fullpath = wf_fullpath
user_action = wf_action
* file_encoding =
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF wf_action EQ 9.
MESSAGE 'No File have been Selected' TYPE 'S'.
ELSE.
p_file = wf_fullpath.
PERFORM create_excel.
ENDIF.
*& Form create_excel
* text
FORM create_excel.
LOOP AT it_tabemp INTO p_file.
ENDLOOP.
* START THE EXCEL APPLICATION
CREATE OBJECT wf_excel 'EXCEL.APPLICATION'.
PERFORM err_hdl.
* PUT EXCEL IN FRONT
SET PROPERTY OF wf_excel 'VISIBLE' = 1.
PERFORM err_hdl.
* CREATE AN EXCEL WORKBOOK OBJECT
CALL METHOD OF wf_excel 'WORKBOOKS' = wf_mapl.
PERFORM err_hdl.
SET PROPERTY OF wf_excel 'SheetsInNewWorkbook' = 3. "no of sheets
PERFORM err_hdl.
CALL METHOD OF wf_mapl 'ADD' = wf_map.
PERFORM err_hdl.
*Assign the Delimiter to field symbol.
ASSIGN wf_deli TO <fs> TYPE 'X'.
t_hex-l_tab = wl_c09.
<fs> = t_hex-l_tab.
CLEAR int_matl.
REFRESH int_matl.
SELECT matnr
mtart
matkl
meins
FROM mara
INTO CORRESPONDING FIELDS OF TABLE int_mara.
*first the headings will be displayed in the excel sheet
CONCATENATE 'Material Number'
'Material type'
'Material Group'
'Base Unit of Measure'
INTO wa_matl
SEPARATED BY wf_deli.
APPEND wa_matl TO int_matl.
LOOP AT int_mara INTO wa_mara.
CONCATENATE wa_mara-matnr
wa_mara-mtart
wa_mara-matkl
wa_mara-meins
INTO wa_matl
SEPARATED BY wf_deli.
APPEND wa_matl TO int_matl.
CLEAR wa_matl.
ENDLOOP.
*Copyng thae same contents to another table to display in
*new sheet
MOVE int_matl TO int_matl1.
PERFORM f_material_details
TABLES int_matl
USING 1.
PERFORM f_material_details
TABLES int_matl
USING 2.
GET PROPERTY OF wf_excel 'ActiveSheet' = wf_map.
GET PROPERTY OF wf_excel 'ActiveWorkbook' = wf_mapl.
CALL FUNCTION 'FLUSH'
EXCEPTIONS
cntl_system_error = 1
cntl_error = 2
OTHERS = 3.
IF sy-subrc = 0.
CALL METHOD OF wf_map 'SAVEAS'
EXPORTING #1 = p_file.
ENDIF.
CALL METHOD OF wf_mapl 'CLOSE'.
CALL METHOD OF wf_excel 'QUIT'.
FREE OBJECT wf_mapl.
FREE OBJECT wf_map.
FREE OBJECT wf_excel.
ENDFORM. "create_excel
*& Form ERR_HDL
* text
FORM err_hdl.
IF sy-subrc <> 0.
WRITE: / 'OLE ERROR: RETURN CODE ='(i10), sy-subrc.
STOP.
ENDIF.
ENDFORM. "ERR_HDL
*-- End of Program
*& Form f_material_details
* text
* --> p1 text
* <-- p2 text
FORM f_material_details
TABLES lint_matl
USING l_sheet_no TYPE i.
DATA: lv_lines TYPE i,
lv_sheet_name(50) TYPE c.
wc_sheets = l_sheet_no.
CASE l_sheet_no.
WHEN 1.
lv_sheet_name = 'Material_sheet1'.
WHEN 2.
lv_sheet_name = 'Material_sheet2'.
ENDCASE.
*-- activating the worksheet and giving a name to it
CALL METHOD OF wf_excel 'WORKSHEETS' = wf_worksheet
EXPORTING
#1 = wc_sheets.
CALL METHOD OF wf_worksheet 'ACTIVATE'.
SET PROPERTY OF wf_worksheet 'NAME' = lv_sheet_name.
*--formatting the cells
CALL METHOD OF wf_excel 'Cells' = wf_cell_from
EXPORTING
#1 = 1
#2 = 1.
DESCRIBE TABLE lint_matl LINES lv_lines.
CALL METHOD OF wf_excel 'Cells' = wf_cell_to
EXPORTING
#1 = lv_lines
#2 = 4.
*--range of cells to be formatted (in this case 1 to 4)
CALL METHOD OF wf_excel 'Range' = wf_cell
EXPORTING
#1 = wf_cell_from
#2 = wf_cell_to.
*--formatting the cells
CALL METHOD OF wf_excel 'Cells' = wf_cell_from1
EXPORTING
#1 = 1
#2 = 1.
DESCRIBE TABLE lint_matl LINES lv_lines.
CALL METHOD OF wf_excel 'Cells' = wf_cell_to1
EXPORTING
#1 = lv_lines
#2 = 1.
CALL METHOD OF wf_excel 'Range' = wf_cell1 " Cell range for first
" column(Material)
EXPORTING
#1 = wf_cell_from1
#2 = wf_cell_to1.
SET PROPERTY OF wf_cell1 'NumberFormat' = '@' . "To disply zeros
"in Material number
DATA l_rc TYPE i.
*DATA download into excel first sheet
CALL METHOD cl_gui_frontend_services=>clipboard_export
IMPORTING
data = lint_matl[]
CHANGING
rc = l_rc
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
OTHERS = 4.
CALL METHOD OF wf_worksheet 'Paste'.
CALL METHOD OF wf_excel 'Columns' = wf_column1.
CALL METHOD OF wf_column1 'Autofit'.
FREE OBJECT wf_column1.
ENDFORM. " f_material_details
Regards,
Manoj Kumar P
Edited by: Manoj Kumar on Mar 5, 2009 11:25 AM -
Downlaod to Excel sheet using ole
hi,
I am using ole2 method for downloading data into Excel.In the excel all the character fields are left aligned and all the numeric fields are right aligned .
I want all my data to be left aligned ,pls let me know how it can be done thru the program.
Thnx
Bhanu.Hello Bhanu,
There are a couple of little tricks to get everything to appear left aligned
1. There is an object 'HorizontalAlignment' which needs to be set to 'xlLeft' to force excel to display numbers left aligned - though i have never used it, so i cannot guide you more on this
2. If you simply append an apostrophe to your field before passing it to excel, the data will appear left aligned and the apostrophe will not show in the excel sheet (it will only show in the formula bar)
to append the apostrophe, first ensure that your field is one character longer than it was earlier (to fit in the apostrophe)
then use this code
concatenate '''' fieldname into fieldname.
the '''' is the escape sequence for apostrophe -
Creating Excel Using OLE through ABAP
Hi Experts,
Can anyone help me in running an abap program to give an Excel file using OLE..
Regards,
SeshadriHi Seshadri,
Here is ur expected coding...
REPORT ZCREATEEXCEL.
TYPE-POOLS OLE2.
DATA: EXCEL TYPE OLE2_OBJECT,
WORKBOOKS TYPE OLE2_OBJECT,
WORKBOOK TYPE OLE2_OBJECT.
DATA: FILENAME LIKE RLGRAP-FILENAME.
START THE EXCEL APPLICATION
CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.
PERFORM ERR_HDL.
PUT EXCEL IN FRONT
SET PROPERTY OF EXCEL 'VISIBLE' = 1.
PERFORM ERR_HDL.
INFORM USER OF THE CURRENT STATUS
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = 0
TEXT = TEXT-I08
EXCEPTIONS
OTHERS = 1.
CREATE AN EXCEL WORKBOOK OBJECT
CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOKS.
PERFORM ERR_HDL.
CALL METHOD OF WORKBOOKS 'ADD' = WORKBOOK.
PERFORM ERR_HDL.
EXCEL FILENAME
CONCATENATE SY-REPID '_' SY-DATUM6(2) '_' SY-DATUM4(2) '_'
SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.
CALL METHOD OF WORKBOOK 'SAVEAS' EXPORTING #1 = FILENAME.
FORM ERR_HDL.
IF SY-SUBRC <> 0.
WRITE: / 'OLE ERROR: RETURN CODE ='(I10), SY-SUBRC.
STOP.
ENDIF.
ENDFORM.
hope it helps.. -
Excel from abap using OLE, trying to make an excel cell-property currency
Hello everyone,
I have build an abap application which generates a price list as a MS Excel file using OLE techniques (ole2incl).
One small thing in the excel file is lacking and I hope some one can help me out:
I want to give certain cells in excel the "cell property - currency", so that excel shows the amounts as currency values.
Has anyone done or seen that before?
Thanks a lot in advance.
Kind regard, Archie OomenHi,
I am having a similiar problem trying to fix the CELL format as TEXT.
No matter how I try, it often ends up as 'GENERAL.
Have you resolved your issue?
Prehaps, you could share it if you had already rectify your problem.
Thanks a lot -
OLE objects and OO methods - Error using OLE automation
Hi,
I'm developing an class to read/write excel sheets and i'm getting an error on the OLE method that is:
on this instruction
call method of l_obj_excel 'WORKBOOKS' = l_workb_col.
i got a dump that give me the following error UC_OBJECTS_NOT_CONVERTIBLE
The strange is that i've got the same code running on reports and it works fine only when passing it to a oo method i get that dump.
Thzs in advanced to all
Best regards
Jaimehi check this..
Report ZMULTICOLOR_TEST no standard page heading.
this report demonstrates how to send some ABAP data to an
EXCEL sheet using OLE automation.
include ole2incl.
handles for OLE objects
data: h_excel type ole2_object, " Excel object
h_mapl type ole2_object, " list of workbooks
h_map type ole2_object, " workbook
h_zl type ole2_object, " cell
h_f type ole2_object, " font
h_c type ole2_object. " color
DATA: FILENAME LIKE RLGRAP-FILENAME.
tables: spfli.
data h type i.
table of flights
data: it_spfli like spfli occurs 10 with header line.
*& Event START-OF-SELECTION
start-of-selection.
read flights
select * from spfli into table it_spfli.
display header
uline (61).
write: / sy-vline no-gap,
(3) 'Flg'(001) color col_heading no-gap, sy-vline no-gap,
(4) 'Nr'(002) color col_heading no-gap, sy-vline no-gap,
(20) 'Von'(003) color col_heading no-gap, sy-vline no-gap,
(20) 'Nach'(004) color col_heading no-gap, sy-vline no-gap,
(8) 'Zeit'(005) color col_heading no-gap, sy-vline no-gap.
uline /(61).
display flights
loop at it_spfli.
write: / sy-vline no-gap,
it_spfli-carrid color col_key no-gap, sy-vline no-gap,
it_spfli-connid color col_normal no-gap, sy-vline no-gap,
it_spfli-cityfrom color col_normal no-gap, sy-vline no-gap,
it_spfli-cityto color col_normal no-gap, sy-vline no-gap,
it_spfli-deptime color col_normal no-gap, sy-vline no-gap.
endloop.
uline /(61).
tell user what is going on
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
PERCENTAGE = 0
text = text-007
exceptions
others = 1.
start Excel
create object h_excel 'EXCEL.APPLICATION'.
PERFORM ERR_HDL.
set property of h_excel 'Visible' = 1.
CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls' .
PERFORM ERR_HDL.
tell user what is going on
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
PERCENTAGE = 0
text = text-008
exceptions
others = 1.
get list of workbooks, initially empty
call method of h_excel 'Workbooks' = h_mapl.
perform err_hdl.
add a new workbook
call method of h_mapl 'Add' = h_map.
perform err_hdl.
tell user what is going on
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
PERCENTAGE = 0
text = text-009
exceptions
others = 1.
output column headings to active Excel sheet
perform fill_cell using 1 1 1 200 'Carrier id'(001).
perform fill_cell using 1 2 1 200 'Connection id'(002).
perform fill_cell using 1 3 1 200 'City from'(003).
perform fill_cell using 1 4 1 200 'City to'(004).
perform fill_cell using 1 5 1 200 'Dep. Time'(005).
loop at it_spfli.
copy flights to active EXCEL sheet
h = sy-tabix + 1.
if it_spfli-carrid cs 'AA'.
perform fill_cell using h 1 0 000255000 it_spfli-carrid.
elseif it_spfli-carrid cs 'AZ'.
perform fill_cell using h 1 0 168000000 it_spfli-carrid.
elseif it_spfli-carrid cs 'JL'.
perform fill_cell using h 1 0 168168000 it_spfli-carrid.
elseif it_spfli-carrid cs 'LH'.
perform fill_cell using h 1 0 111111111 it_spfli-carrid.
elseif it_spfli-carrid cs 'SQ'.
perform fill_cell using h 1 0 100100100 it_spfli-carrid.
else.
perform fill_cell using h 1 0 000145000 it_spfli-carrid.
endif.
if it_spfli-connid lt 400.
perform fill_cell using h 2 0 255000255 it_spfli-connid.
elseif it_spfli-connid lt 800.
perform fill_cell using h 2 0 077099088 it_spfli-connid.
else.
perform fill_cell using h 2 0 246156138 it_spfli-connid.
endif.
if it_spfli-cityfrom cp 'S*'.
perform fill_cell using h 3 0 155155155 it_spfli-cityfrom.
elseif it_spfli-cityfrom cp 'N*'.
perform fill_cell using h 3 0 189111222 it_spfli-cityfrom.
else.
perform fill_cell using h 3 0 111230222 it_spfli-cityfrom.
endif.
if it_spfli-cityto cp 'S*'.
perform fill_cell using h 4 0 200200200 it_spfli-cityto.
elseif it_spfli-cityto cp 'N*'.
perform fill_cell using h 4 0 000111222 it_spfli-cityto.
else.
perform fill_cell using h 4 0 130230230 it_spfli-cityto.
endif.
if it_spfli-deptime lt '020000'.
perform fill_cell using h 5 0 145145145 it_spfli-deptime.
elseif it_spfli-deptime lt '120000' .
perform fill_cell using h 5 0 015215205 it_spfli-deptime.
elseif it_spfli-deptime lt '180000' .
perform fill_cell using h 5 0 000215205 it_spfli-deptime.
else.
perform fill_cell using h 5 0 115115105 it_spfli-deptime.
endif.
endloop.
EXCEL FILENAME
CONCATENATE SY-REPID '_' SY-DATUM6(2) '_' SY-DATUM4(2) '_'
SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.
CALL METHOD OF H_MAP 'SAVEAS' EXPORTING #1 = FILENAME.
free object h_excel.
perform err_hdl.
FORM FILL_CELL *
sets cell at coordinates i,j to value val boldtype bold *
form fill_cell using i j bold col val.
call method of h_excel 'Cells' = h_zl
exporting
#1 = i
#2 = j.
perform err_hdl.
set property of h_zl 'Value' = val .
perform err_hdl.
get property of h_zl 'Font' = h_f.
perform err_hdl.
set property of h_f 'Bold' = bold .
perform err_hdl.
set property of h_f 'Color' = col.
perform err_hdl.
endform. "FILL_CELL
*& Form ERR_HDL
outputs OLE error if any *
--> p1 text
<-- p2 text
form err_hdl.
if sy-subrc <> 0.
write: / 'OLE-Automation Error:'(010), sy-subrc.
stop.
endif.
endform. " ERR_HDL
regards,
venkat -
Populating graph in excel using ole
Hi All,
I am able to populate the graph from abap into excel using OLE.
But I am not able to take x-axis and y-axis according to my requirement, its taking by its own as default. please see the below code:
<b>CALL METHOD OF GS_EXCEL 'Cells' = GS_CELL1
EXPORTING
#1 = GV_LINE_CNTR
#2 = 1.
CALL METHOD OF GS_EXCEL 'Cells' = GS_CELL2
EXPORTING
#1 = GV_LINNO1
#2 = GV_COLNO.
CALL METHOD OF GS_EXCEL 'Range' = GS_CELLS
EXPORTING
#1 = GS_CELL1
#2 = GS_CELL2.
CALL METHOD OF GS_CELLS 'Select' .
GET PROPERTY OF GS_APPLICATION 'Charts' = GS_CHARTS .
CALL METHOD OF GS_CHARTS 'Add' = GS_CHART .
CALL METHOD OF GS_CHART 'Activate' .
SET PROPERTY OF GS_CHART 'ChartType' = '93' .</b>Now I want to give my own range. But i am not able to.
I am also not able to give labels of x-axis and y-axis.
Please help, its very urgent............Hello,
try this code. It creates macro as a file, and than uses that macro to show the chart
Regards,
Naimesh
REPORT ZTEST_NP .
INCLUDE OLE2INCL. " OLE objects include
*export data variables
DATA: H_EXCEL TYPE OLE2_OBJECT, " Excel object
WORKBOOKS TYPE OLE2_OBJECT, " list of workbooks
THIS_WORKBOOK TYPE OLE2_OBJECT, " workbook
CELL TYPE OLE2_OBJECT, " cell
BOOK_FONT TYPE OLE2_OBJECT. " font
*chart creation DATA: variables
DATA: MODULE TYPE OLE2_OBJECT, "macro
NEWMODULE TYPE OLE2_OBJECT. "macrotab with VB source code
INternal tableTABLES: no_table.
DATA H TYPE I.
table that contains Visual Basic source code
DATA: BEGIN OF MACROFILE OCCURS 0,
LINE(80) ,
END OF MACROFILE.
*Internal table with Months and related Profits
DATA: BEGIN OF NO_TABLE OCCURS 10, "Internal table with no's
MONTH(8) TYPE C,
PROFIT(8) TYPE C,
END OF NO_TABLE.
*Months added to table as well as Profits
NO_TABLE-MONTH = 'June'.
NO_TABLE-PROFIT = '1000'. APPEND NO_TABLE. "Update table
NO_TABLE-MONTH = 'July'.
NO_TABLE-PROFIT = '4000'. APPEND NO_TABLE. "Update table
NO_TABLE-MONTH = 'August'.
NO_TABLE-PROFIT = '3000'. APPEND NO_TABLE. "Update table
NO_TABLE-MONTH = 'September'.
NO_TABLE-PROFIT = '7000'. APPEND NO_TABLE. "Update table
NO_TABLE-MONTH = 'October'.
NO_TABLE-PROFIT = '7000'. APPEND NO_TABLE. "Update table
NO_TABLE-MONTH = 'November'.
NO_TABLE-PROFIT = '6000'. APPEND NO_TABLE. "Update table
CALL METHOD OF THIS_WORKBOOK 'InsertFile'
EXPORTING #1 = 'C:\VBsource.tmp'.
*********Fill makro table with VB source code************************
the macro's name is draw_graph
MACROFILE-LINE = 'sub draw_graph()'. APPEND MACROFILE.
MACROFILE-LINE = 'Range("a1:a1").Font.Bold = True'.APPEND macrofile.
MACROFILE-LINE =
'Range("a1:a1").Value = "Net Profits for last few months.
"'. APPEND macrofile. "Bold heading at top of sheet.
MACROFILE-LINE = 'Range("A2:B7").Select'. APPEND macrofile.
MACROFILE-LINE = 'charts.add'. APPEND MACROFILE.
MACROFILE-LINE = 'activechart.charttype = xllinemarkersStacked
'. APPEND macrofile.
MACROFILE-LINE =
'Activechart.setsourcedata source:=sheets("Sheet1").range("A2:B7") ,
PLOTBY:= XLROWS'. APPEND macrofile.
MACROFILE-LINE = 'activechart.location where:=xllocationasobject, name:=
"sheet1"'. APPEND macrofile.
MACROFILE-LINE = 'With ActiveChart'. APPEND MACROFILE.
MACROFILE-LINE = '.hasLegend = false '. APPEND MACROFILE.
MACROFILE-LINE = ' .Axes(xlValue, xlPrimary).HasTitle = True'.
APPEND MACROFILE.
MACROFILE-LINE = '.axes(xlvalue, xlprimary).axistitle.characters.text =
"Net Profit ($)"'.
APPEND MACROFILE.
MACROFILE-LINE = 'End With'. APPEND MACROFILE.
MACROFILE-LINE = 'msgbox ("Chart completed!")'. APPEND macrofile.
MACROFILE-LINE = 'end sub '. APPEND MACROFILE.
*******************vb source code end********************************
***********create file with visual basic source code *******************
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = 'c:\VBsource.tmp' "directory with temporary file
FILETYPE = 'ASC'
TABLES
DATA_TAB = MACROFILE
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
**********create file with visual basic source code end**************
**write info to screen (ABAP)
LOOP AT NO_TABLE.
WRITE: / SY-VLINE NO-GAP,
NO_TABLE-MONTH COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
NO_TABLE-PROFIT COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
ENDLOOP.
ULINE (61).
**********************START THE EXCEL APPLICATION*********************
CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'. "type of application
PERFORM CHECK_ERRORS.
SET PROPERTY OF H_EXCEL 'Visible' = 1.
PERFORM CHECK_ERRORS.
CALL METHOD OF H_EXCEL 'Workbooks' = WORKBOOKS.
PERFORM CHECK_ERRORS.
create a new workbook
CALL METHOD OF WORKBOOKS 'Add' = THIS_WORKBOOK.
PERFORM CHECK_ERRORS.
***********fill the Excel table with data*****************************
PERFORM FILL_EXC_TAB USING 1 1 1 'Profits:'(001). "initial heading
LOOP AT NO_TABLE.
H = SY-TABIX + 1.
PERFORM FILL_EXC_TAB USING H 1 0 NO_TABLE-MONTH.
ENDLOOP.
LOOP AT NO_TABLE.
H = SY-TABIX + 1.
PERFORM FILL_EXC_TAB USING H 2 0 NO_TABLE-PROFIT.
ENDLOOP.
***********fill the Excel table with data end*************************
************DRAW the CHART using the values exported *******************
CALL METHOD OF H_EXCEL 'Modules' = MODULE.
PERFORM CHECK_ERRORS.
CALL METHOD OF MODULE 'Add' = NEWMODULE. " the macro
PERFORM CHECK_ERRORS.
CALL METHOD OF NEWMODULE 'Activate'.
PERFORM CHECK_ERRORS.
get source code from temporary file
CALL METHOD OF NEWMODULE 'InsertFile' EXPORTING #1 = 'C:\VBsource.tmp'.
PERFORM CHECK_ERRORS.
executing VBA program code -> macro name = "draw_graph"
CALL METHOD OF H_EXCEL 'Run' EXPORTING #1 = 'draw_graph'.
PERFORM CHECK_ERRORS.
FREE OBJECT H_EXCEL. "free up memory
PERFORM CHECK_ERRORS.
FORM FILL_EXC_TAB USING I J BOLD VAL.
CALL METHOD OF H_EXCEL 'Cells' = CELL EXPORTING #1 = I #2 = J.
PERFORM CHECK_ERRORS.
SET PROPERTY OF CELL 'Value' = VAL .
PERFORM CHECK_ERRORS.
GET PROPERTY OF CELL 'Font' = BOOK_FONT.
PERFORM CHECK_ERRORS.
SET PROPERTY OF BOOK_FONT 'Bold' = BOLD .
PERFORM CHECK_ERRORS.
ENDFORM.
error handling subroutine
FORM CHECK_ERRORS.
IF SY-SUBRC NE 0.
WRITE: / 'OLE error:'(010), SY-SUBRC.
STOP.
ENDIF.
ENDFORM.
Maybe you are looking for
-
How can i disable Illustrator from changing my language / keyboard layout.
I have an azerty laptop and a qwerty external keyboard. Switching from any application to illustrator changes the language and therefore also my keyboard layout. No other application does this.
-
My apple id has been disabled how i can enable it??
my apples id has been disbled how i can enable it ?
-
Delivery date in WCEM Quotation
Hi All. We have implemented WCEM , Is there a way to show the requested delivery date in WCEM ? Detailed explanation : We create quotations in CRM which are displayed in WCEM -> My Account -> Quotations . we enter the expected delivery date in Quotat
-
I can´t install Photoshop Elements 10 correctly
I have a big Problem. I will install Photoshop Elements 10 on my Windows 7 PC. the installation aborts before it is finished. What can i do? Please helpe me. Thank you
-
Where is 64-bit version of reset ulitity?
Bought a used - but in working condition iPod Shuffle 2nd Gen. Tried to charge/sync it and got a dialog box - not recognized by iTunes. Not showing up under Devices in iTunes. Directed me to iPod reset ut ility setup, which will not dowload - its fo