Color on excel using ole

Hi!
i want to color(yellow) the last line of an excel.
here is a part of the code :
  DESCRIBE TABLE excel_2 LINES w_lines.
CREATE OBJECT application 'excel.application'.
  SET PROPERTY OF application 'visible' = 1.
  CALL METHOD OF application 'Workbooks' = workbook.
  CALL METHOD OF workbook 'Open'
    EXPORTING
      #1 = pa_file.
  CALL METHOD OF application 'Worksheets' = sheet
    EXPORTING
      #1 = 1.
  SET PROPERTY OF sheet 'Name' = 'Employee Performance'.
  CALL METHOD OF sheet 'Activate'.
  DATA: w_test TYPE string.
  DATA: w_test_lines TYPE string.
  w_test_lines = w_lines.
  CONCATENATE 'A' w_test_lines INTO w_test.
  CONCATENATE w_test ':Z' w_test_lines  INTO w_test.
  CONDENSE w_test NO-GAPS.
*CALL METHOD OF application 'RANGE' = gs_range
*    EXPORTING
*      #1 = 'w_test'.
* SET PROPERTY OF gs_range 'HORIZONTALALIGNMENT' = 1.
*  CALL METHOD OF gs_range 'FONT' = gs_font.
*  SET PROPERTY OF gs_font 'BOLD' = 1.
  CALL METHOD OF application 'RANGE' = gs_range
    EXPORTING
      #1 = 'A1:Z1'.
  SET PROPERTY OF gs_range 'HORIZONTALALIGNMENT' = 1.
  CALL METHOD OF gs_range 'FONT' = gs_font.
  SET PROPERTY OF gs_font 'BOLD' = 1.
  CALL METHOD OF application 'Columns' = h_columns
    EXPORTING
      #1 = 'A:Z'.
  GET PROPERTY OF h_columns 'EntireColumn' = h_entirecol.
  SET PROPERTY OF h_entirecol 'Autofit' = 1.
  CALL METHOD OF sheet 'SAVE'   "'Save'
EXPORTING
  #1 =  pa_file
  #2 = pa_file."filename
  "fileFormat

Check out this code
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
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 UP TO 10 ROWS.
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 'Flug'(001).
  PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
  PERFORM FILL_CELL USING 1 3 1 'Von'(003).
  PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
  PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
  LOOP AT IT_SPFLI.
copy flights to active EXCEL sheet
    H = SY-TABIX + 1.
    PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
    PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
    PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
    PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
    PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
  ENDLOOP.
changes by Kishore  - start
CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
  CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
  PERFORM ERR_HDL.
add a new workbook
  CALL METHOD OF H_MAPL 'Add' = H_MAP  EXPORTING #1 = 2.
  PERFORM ERR_HDL.
tell user what is going on
  SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
  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 'Flug'(001).
  PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
  PERFORM FILL_CELL USING 1 3 1 'Von'(003).
  PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
  PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
  LOOP AT IT_SPFLI.
copy flights to active EXCEL sheet
    H = SY-TABIX + 1.
    PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
    PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
    PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
    PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
    PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
  ENDLOOP.
changes by Kishore  - end
disconnect from Excel
     CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING  #1 = 'C:\SKV.XLS'.
  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 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.
ENDFORM.
*&      Form  ERR_HDL
      outputs OLE error if any                                       *
-->  p1        text
<--  p2        text
FORM ERR_HDL.
IF SY-SUBRC <> 0.
  WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
  STOP.
ENDIF.
ENDFORM.                    " ERR_HDL

Similar Messages

  • 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.

  • 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,
    Seshadri

    Hi 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..

  • How to output a logo stored as standard text to excel using OLE

    Hi Experts,
    I have a requirement to write a program which creates an excel spreadsheet to download data from SAP.  The client would like the spreadsheet formatted with merged cells, background colours, different size fonts and in the top left corner of the spreadsheet to show their logo. 
    They have similar functionality in another report, however, this requires a template (containing all of the formatting) to be stored on the user's PC.  They do not want to have to do this with the new download.
    After checking the many postings on this forum I have worked out how to do most of the requirements, but as yet have still not been able to work out how to populate their logo to the spreadsheet.  They already have their logo stored as standard text (SO10), so would prefer to use this if possible.
    Any advise and/or sample code would ge greatly appreciated.
    Thanks
    Sandra

    Hi Surendra,
    We have the same requirement. We want to do some format changes to "Generic FSG Drill Template". I am able to do few changes. But when we run the report, we are able to see PDF, html output. But 'Exce' report comes with blank. Can you help on this. How were you able to see logo in excel file.
    Can you send the suggestions if any to my mail ([email protected])
    Thanks in advance.
    Thanks,
    Techie.
    Edited by: user1138068 on May 30, 2011 7:04 AM

  • Reports Generation in Microsoft Excel using Forms Server

    How can I generate reports in Microsoft Excel from an web-enabled forms application, as using Dynamic Data Exchange invokes Excel on the Application Server? My work-around was to generate the file on the application server, save it ,exit the Excel application and then display the excel document using Web.Show_Document. Though this method is successful, the processing time is very high.
    null

    Use text_io package of developer to write records to excel using OLE
    Thanks
    null

  • 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

  • To upload excel file directly to the application server using OLE concept

    hi experts
    i have done a coding in OLE to download excel with graph to presentation server, is it possible to upload excel with graph directly to the application server  , the excel should have graph while downloading to presentation server fom app server.
    Moderator message - duplicate post locked
    Edited by: Rob Burbank on Jun 25, 2009 9:49 AM

    HI,
    have a look at tcode cg3z and then FM 'C13Z_FILE_UPLOAD_ASCII'.
    What you can do is, first create the file on presentation server using OLE automation, and then using this FM, write the file to Application server

  • ALV download to Excel onto desktop using OLE concept.

    Hi Experts,
    I requriement is , through my se38 program i need to download report output to excel.
    i did this using OLE concepts code and excel is being downloaded good.
    But problem is all columns data is dumped into First column. But in my ALV i have 20 columns. So i except data in excel sheet to be in 20 columns.
    Below is the OLE code i used
    CREATE OBJECT wa_excel 'EXCEL.APPLICATION'. "Create object for Excel
      SET PROPERTY OF wa_excel  'VISIBLE' = 1. "In background Mode
      CALL METHOD OF wa_excel 'WORKBOOKS' = w_workbook.
      CALL METHOD OF w_workbook 'ADD'. "Create a new Workbook
      SET PROPERTY OF wa_excel 'SheetsInNewWorkbook' = 3. "No of sheets
    * Downloading header details to first sheet
      PERFORM download_sheet TABLES i_final USING 1 'Master Material Details'.
      GET PROPERTY OF wa_excel 'ActiveSheet' = w_worksheet.
    * Protect the first worksheet with a password
      CALL METHOD OF w_worksheet 'PROTECT
        EXPORTING #1 = 'infy@123'.
    * Save the Excel file
      GET PROPERTY OF wa_excel 'ActiveWorkbook' = w_workbook.
      CALL METHOD OF w_workbook 'SAVEAS'
        EXPORTING #1 = p_infile.
      FREE OBJECT: w_worksheet, wa_excel.
    FORM download_sheet TABLES p_tab  USING p_sheet TYPE i   p_name  TYPE string.
      CALL METHOD OF wa_excel 'WORKSHEETS' = w_worksheet
        EXPORTING
        #1 = p_sheet.
      CALL METHOD OF w_worksheet 'ACTIVATE'.
      SET PROPERTY OF w_worksheet 'NAME' = p_name.
      CALL METHOD OF wa_excel 'Range' = w_range
        EXPORTING
        #1 = 'A1'
        #2 = 'D1'.
      CALL METHOD OF w_range 'INTERIOR' = w_int.
      SET PROPERTY OF w_int 'ColorIndex' = 6.
      SET PROPERTY OF w_int 'Pattern' = 1.
    * Initially unlock all the columns( by default all the columns are locked )
      CALL METHOD OF wa_excel 'Columns' = w_columns.
      SET PROPERTY OF w_columns 'Locked' = 0.
    * Locking and formatting first column
      CALL METHOD OF wa_excel 'Columns' = w_columns
       EXPORTING
       #1 = 1.
    * Locking and formatting second column
      CALL METHOD OF wa_excel 'Columns' = w_columns
        EXPORTING
        #2 = 2.
      SET PROPERTY OF w_columns  'Locked' = 2.
      SET PROPERTY OF w_columns  'NumberFormat' = '@'.
    * Export the contents in the internal table to the clipboard
      CALL METHOD cl_gui_frontend_services=>clipboard_export
        IMPORTING
          data                 = p_tab[]
        CHANGING
          rc                   = w_rc
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4.
    * Paste the contents in the clipboard to the worksheet
      CALL METHOD OF w_worksheet 'Paste'.
    * Autofit the columns according to the contents
      CALL METHOD OF wa_excel 'Columns' = w_columns.
      CALL METHOD OF w_columns 'AutoFit'.
      FREE OBJECT: w_columns, w_range.
    Please help me if there is any SET Property of WA_EXCEL with which i can handle ALV data into Diffrenet columns.
    Regards,
    jayant.

    hi nabheet,
    we have implemnted this logic and it is workign fine. Bit it takes long time to download data in Excel sheet. Actually it is happening feild by field.
    Please advice any perfomance tuning to this logic.
    Rgs,
    jayant

  • 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 AM

    Here 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.U

    https://forums.sdn.sap.com/click.jspa?searchID=21931962&messageID=6852860
    hope this helps.

  • 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
    -neha

    Hello 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.

  • Excel output Left justified using OLE

    Hi,
    Can anyone please let me know how to align all the cells in the excel sheet as LEFT JUSTIFIED using OLE? I have few numeric values and by default it will be on the right side, i want to make it left justified.
    Edited by: Pradeep Kumar on Jan 19, 2011 1:36 PM

    Its obvoius that you will always find numeric values of right aligned.
    I had faced a similar kind of issue while downloading PSTLZ  US Postal Codes. You can try this way:
    Place a apostrophe to the field you need to be left aligned
    ' ' ' '           " This  defines your apostrophe
    You can check this in excel. Just place a equal sign and apostrophe infront of the value and press enter. The value will be left aligned.
    Try the same thing in your code.
    It was a very old change for me. Trying to get some sample code snippet for referance.
    Here it goes:
    CONSTANTS: c_prefix VALUE '='.
        CONSTANTS: c1_prefix VALUE ' " '.
        CONCATENATE  c_prefix
                   c1_prefix
                   i_lfa1-pstlz
                   INTO i_lfa1-pstlz
    ~ Last edited for adding the code snippet
    Edited by: K.Manas on Jan 19, 2011 9:35 AM

  • 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?

  • 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 Oomen

    Hi,
    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

  • 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 Sonar

    Excel 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.

Maybe you are looking for