How to dowload data in particular cell of designed excel sheet

hi everyone
i want to dowload the data in a excel sheet, but this excel sheet is designed in such a format that i have download each field of internal table in a specified cell only , <b>gui_download</b> function module simply download the data in excel sheet by taking the first cell for first field but i dont want that

Hi Neetu,
you can use OLE in that case.
REPORT  ZTEST_EXCEL             .
INCLUDE ole2incl.
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),
last_name(10),
END OF itab1.
START-OF-SELECTION.
itab1-first_name = '123445'.
itab1-last_name = 'tesst'.
append itab1.
clear itab1.
itab1-first_name = '123446'.
itab1-last_name = 'tesst'.
append itab1.
clear itab1.
  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'.
  LOOP AT itab1.
    index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
    CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
    SET PROPERTY OF cells 'Value' = itab1-first_name.
        index = index + 1. " 1 - column name
    CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
    SET PROPERTY OF cells 'Value' = itab1-last_name.
  ENDLOOP.
* Save excel speadsheet to particular filename
  CALL METHOD OF sheet 'SaveAs'
                 EXPORTING #1 = 'c:tempexceldoc1.xls'     "filename
                            #2 = 1.                          "fileFormat
Regards
vijay

Similar Messages

  • How to transfer data more than 255 char from excel sheet to internal table.

    Hello Experts,
    I have a requirement where i have a text field in the excel sheet of more than 255 char and need to be updated in the text element. To do that i need to transfer the excel sheet data to an internal table where one of the field is more than 255 char.
    in the standard function module it works only upto 255 char. Can you help me if we have some other way to get more than 255 char in the internal table from excel sheet.
    Thanks in Advance.
    BR,
    RaJ.

    Using .xls, it is not possible transfer data more than 255 characters from excel sheet. However if the excel sheet is saved as Comma Delimited format or Tab Delimited format, then using GUI_DOWNLOAD function module data more than 255 characters can be transferred.
    File name should be : .csv (Comma Delimited format)  or .txt (Tab Delimited format)
    File Type would still remain 'ASC' while calling function module GUI_DOWNLOAD
    Also In the internal table declare the field type as String or LCHAR.
    Eg:
    TYPES: begin of ty_file,
            col_a TYPE string,
          end of ty_file.
    DATA: i_file type standard table
                   of ty_file
                 with header line
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      =  'C:\test.csv'
      TABLES
        DATA_TAB                      = i_file

  • How to group data and assign cell names using Excel templates

    Hi all,
    reading the article "Real Excel Templates 1.5" on the Tim Dexter's Blog, I found that I need hierarchical data for Excel templates. So only in this way I can group my data.
    My hierarchy is composed by 3 levels:
    lev 1 DESTINATION: is the higher level that groups SERVICES and COUNTRY
    lev 2 SERVICES: is the level that groups the countries
    lev 3 COUNTRY: is the lowest level with the COUNTRY, CALLS and CALLS_MINUTES details
    An example of my hierarchy is this:
    lev 1 INTERNATIONAL
    lev 2 INTERNATIONAL FIXED
    lev 3 Albania 90 438,15
    lev 3 Armenia 1 16,95
    lev 2 INTERNATIONAL MOBILE
    lev 3 Albania Mobile 161 603,35
    lev 3 Australia Mobile 6 34,38
    lev 1 NATIONAL
    lev 2 HELLAS LOCAL
    lev 3 Hellas Local 186,369 707940,6
    lev 2 HELLAS MOBILE
    lev 3 Hellas Mobile Cosmote 31,33 43856,97
    lev 3 Hellas Mobile Q-Telecom 2,398 4343,78
    lev 2 HELLAS NATIONAL
    lev 3 Hellas Long Distance 649 1499,55
    lev 1 INTERNET
    lev 2 INTERNET CALLS
    lev 3 Cosmoline @Free 79 2871,3
    So, my data template is the following (with exactly the hierarchy I want for my data):
    <dataTemplate name="emp" description="destinations" dataSourceRef="GINO_DB">
         <dataQuery>
              <sqlStatement name="Q1">
                   <![CDATA[SELECT 1 TOTAL_CALLS, 2 TOTAL_CALLS_MIN from dual ]]>
              </sqlStatement>
              <sqlStatement name="Q2">
                   <![CDATA[SELECT dest.ID_DESTINATION, dest.DESC_DEST from ale.AAA_DESTINATION dest order by dest.ID_DESTINATION ]]>
              </sqlStatement>
              <sqlStatement name="Q3">
                   <![CDATA[SELECT ser.ID_SERVICE,
    ser.ID_DEST,
    ser.DESC_SERVICE,
    count.ID_COUNTRY,
    count.ID_SERV,
    count.COUNTRY,
    count.CALLS,
    count.CALLS_MIN
    from ale.AAA_SERVICE ser, ale.AAA_COUNTRY count
    where ser.ID_SERVICE= count.ID_SERV
    and ID_DEST = :ID_DESTINATION
    order by ser.ID_SERVICE ]]>
              </sqlStatement>
         </dataQuery>
         <dataStructure>
              <group name="G_TOT" source="Q1">
                   <element name="TOTAL_CALLS" value="G_COUNTRY.CALLS" function="SUM()"/>
                   <element name="TOTAL_CALLS_MIN" value="G_COUNTRY.CALLS_MIN" function="SUM()"/>
                   <group name="G_DEST" source="Q2">
                        <element name="DESC_DEST" value="DESC_DEST"/>
                        <element name="DEST_CALLS_SUBTOTAL" value="G_COUNTRY.CALLS" function="SUM()"/>
                        <element name="DEST_CALLS_MIN_SUBTOTAL" value="G_COUNTRY.CALLS_MIN" function="SUM()"/>
                        <group name="G_SERV" source="Q3">
                             <element name="DESC_SERVICE" value="DESC_SERVICE"/>
                             <element name="SERV_CALLS_SUBTOTAL" value="G_COUNTRY.CALLS" function="SUM()"/>
                             <element name="SERV_CALLS_MIN_SUBTOTAL" value="G_COUNTRY.CALLS_MIN" function="SUM()"/>
                             <group name="G_COUNTRY" source="Q3">
                                  <element name="COUNTRY" value="COUNTRY"/>
                                  <element name="CALLS" value="CALLS"/>
                                  <element name="CALLS_MIN" value="CALLS_MIN"/>
                             </group>
                        </group>
                   </group>
              </group>
         </dataStructure>
    </dataTemplate>
    Not considering the CALLS and CALLS_MIN details (I focused only on the COUNTRY which is as the same level), with this data template, making tests on my excel template, I noticed that I can group ONLY two nested levels using the format XDO_GROUP_?group_name?
    XDO_GROUP_?G_DEST?
    XDO_GROUP_?G_SERV?
    or
    XDO_GROUP_?G_DEST?
    XDO_GROUP_?G_COUNTRY?
    or
    XDO_GROUP_?G_SERV?
    XDO_GROUP_?G_COUNTRY
    If I try to group all the three level together in this order
    XDO_GROUP_?G_DEST?
    XDO_GROUP_?G_SERV?
    XDO_GROUP_?G_COUNTRY
    I don't have the output I would like to have.....
    Practically, in my excel I have 3 rows with the following labels
    DESTINATION (called XDO_?DESC_DEST? - =Sheet1!$A$3
    SERVICE (called XDO_?DESC_SERVICE? - =Sheet1!$A$4
    COUNTRY (called XDO_?COUNTRY? - =Sheet1!$A$5)
    where
    XDO_GROUP_?G_DEST? (=Sheet1!$A$3:$B$5)
    XDO_GROUP_?G_SERV? (=Sheet1!$A$4:$B$5)
    XDO_GROUP_?G_COUNTRY     (=Sheet1!$A$5:$B$5)
    I noticed that if I don't use the last one (XDO_GROUP_?G_COUNTRY), my output is correct even if I don't have more than one country for each service....As soon as I put XDO_GROUP_?G_COUNTRY....I loose all the 2nd level and the most of times the 3rd level too....
    So...I think that the problem is how I choose the excel cells when I assign the XDO_GROUP_?group_name?
    Anybody had made some tests, or can help me ???? I'm becoming crazy.....
    Any help will be appreciated
    Thanks in advance
    Alex

    But how can I use tags XDO_GROUP_?? to group data correctly using hierarchial xml, I don't want to use flat XML.
    Yep, I using Template Builder in Excel to run reports localy, and output is wrong
    It's seems that groups couldn't define the level of nesting, I think...
    How can I write it in XDO_METADATA sheet?
    Though I have hierarchial XML and groups should define nesting level correctly.
    I have no clue.....

  • How to read data from different tabs of an excel sheet?

    Hello everybody:
    I try to read an specific sheet from excel workbook with multiple sheets, but I can't obtain any soluction. Any have a example ABAP code for the specific question?
    Regards,
    Piero Cimule Troise,

    Piero,
    Have a look into this link
    http://searchsap.techtarget.com/tip/1,289483,sid21_gci868246,00.html?FromTaxonomy=/pr/283958

  • How should restrict data for particular month?

    Hi Experts,
    How should retrieve data for particular month without where condition.

    Hi,
    You must be having Month Object right in your Webi?
    User will be given opportunity to Select his/her required [Month]
    Create variable as =Userresponse("Enter value for Month")same text as you are giving in the Prompt text....Name it as [UMonth]
    Go to analysis tab..Filter..Add filter...[Month]=[UMonth]
    always this report will run for the month user require

  • How to get(copy) the contents i.e the cell of an excel sheet to other excel

    How to get(copy) the contents i.e the cells of an excel sheet to another excel sheet.
    I can read the contents i.e the text in the cells and able to display it in the Java console
    i want these contents to be copied to another excel sheet with the cells data.
    I am using Java Swing for the UI, POI framework for the excel work.
    Please anyone suggest some code to this requirement.

    [spreadsheets with poi|http://poi.apache.org/spreadsheet/converting.html] Hi
    on the poi apache site there's a number of good examples...
    I started with poi only a week ago, but just from reading these examples
    (especially SS Usermodel code) i managed all i needed to know (so far).
    kind regards
    BB
    Edited by: BugBunny on Feb 22, 2010 4:36 AM

  • How to synchronize a cell in form with a cell in MS excel sheet

    dear all
    I can successfuly export data to excell using the ole2 package. But the problem is that exporting data from A datablock in a form to Excel sheet is not enough.
    I need to automaticaly copy updates occures on the datablock to its equilivant in the excel sheet. In other words , i need to synchronize my datablock items with facing cells in the excel sheet,so the cells'values in excel sheet automatiacly changes to be the values in the datablock items
    please help

    Dear all
    I can successfuly export data to excell using the ole2 package. But the problem is that exporting data from A datablock in a form to Excel sheet is not enough.
    I need to automaticaly copy updates occures on the datablock to its equilivant in the excel sheet. In other words , I need to synchronize my datablock items with facing cells in the excel sheet,so the cells'values in excel sheet automatiacly changes to be the values in the datablock items
    I searched the web several times . Some people adviced me to use "Apache-jakarta-poi" . It is a pure java code. But my knoledge in java is limited.I asked on Oracle forums -
    how to synchronize a cell in form with a cell in MS excel sheet - but no one can help
    I tried the oracle forms demo "OLEEXCEL.fmb" . But this form is not working correct .
    I need to embed ole2 in my form that holds excel sheet and passes values from text items to the excel sheet.
    My last try is that I did the following :
    1- in the main canvas i insert the OLE2 control
    2- Right Click and choose insert
    3- from the dialog i chosed Excel Sheet
    4- I placed a button on my canvas then i on the button I write this code
    declare
    worksheet ole2.obj_type;
    cell ole2.obj_type;
    args ole2.list_type;
    begin
    forms_ole2.activate_server('block1.excel_sheet');
    worksheet := forms_ole2.get_interface_pointer('block1.excel');
    args := ole2.create_arglist;
    ole2.add_arg(args,1) -- column1
    ole2.add_arg(args,1) -- cell1
    cell := ole2.invoke_obj(worksheet,'cell',args);
    ole2.destroy_arglist(args);
    ole2.set_property('cell','value',:text1);
    ole2.release_obj(cell);
    ole2.release_obj(worksheet);
    end;
    I get this error ora-305500
    and when i debug , the code stop in this line : cell := ole2.invoke_obj(worksheet,'cell',args);
    please help

  • How to extract the data from module pool program to Excel Sheet?

    Hi Guys
            I am having a requirement to transfer the data from Module pool screen to excel sheet directly.
            This is an urgent requirement.
            So plz reply me with some coding examples.
            I will give points for that.

    This report extract excel file. From that concept you can easily extract data from module pool program also by coding in PAI of the screen.
    REPORT ztest1 .
    * 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-DATUM+6(2) '_' SY-DATUM+4(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

  • How to create Links in a cell  to other Excel docs Cell  in Planning layout

    Hi All,
    I have a requirement to replace an existing forecasting process using normal Excel with BPS with Excel in place. One difficulty I came across is that the existing Excel input template has cells with links to many other excel files so users does not to open all other Excel documents and copy and paste the figures in.
    I am stuck on replicate this function in BPS as I cannot create links to to other  Excel directly in a cell in BPS Excel layout. My initial idea is to create a Macro to copy the data across but in deeper thought this might not be the best solution as the number of excel link can be a lot and the name and location of these files might change quite frequently and I cannot hard code it in the macro..
    Any ideas?
    Thanks.

    Hi Marc,
    The reason to use BPS is once the data is in the layout, we need to run the data in a  true forecast / simulation model (i.e. compare actuals, copy data between differnt planning versions, Foreign Exchange rate planning , allocation, revaluation, etc...) on a different hierarchy level.
    The problem is the starting point data is scattered in lots of other Excel file from local drives from different users. I guess this is the same reason why the csv file upload technique exist, (i.e. to load data to the layout )but in my case the data location needed to be very dynamic and comes from large / different source of data.
    I have now developed a solution to reference data from cells in different Excel sheet to the layout. Once set up, it should be able to save users significant amount of time to bring the base data into the layout, especially if their data is source from many ither Excel files.
    Regards,
    Danny

  • How to handle merge cells in the excel sheet while uploading

    Hi guys,
    I have a requirement where i need to upload the excel sheet. The data is given below.
    field1     field2     field3     field4
    a     x     1     1
              2     2
              3     3
         y1     4     4
         y2     5     5
         y3          6
    The output must be
    a     x     1     1
    a     x     2     2
    a     x     3     3
    a     y1     4     4
    a     y2     5     5
    a     y3     5     6
    Here the field1 column is merged.
    Please let me know if you guys have sample code to handle the merge cells in the excel sheet, that would be of gereat help.
    Regards,
    Karthik

    Hi guys,
    I have a requirement where i need to upload the excel sheet. The data is given below.
    field1     field2     field3     field4
    a     x     1     1
              2     2
              3     3
         y1     4     4
         y2     5     5
         y3          6
    The output must be
    a     x     1     1
    a     x     2     2
    a     x     3     3
    a     y1     4     4
    a     y2     5     5
    a     y3     5     6
    Here the field1 column is merged.
    Please let me know if you guys have sample code to handle the merge cells in the excel sheet, that would be of gereat help.
    Regards,
    Karthik

  • Reading data in a tab in an excel sheet

    Hi,
    I would like to read the data in an excel sheet and upload into an internal table for processing. I was able to do it using function module ALSM_EXCEL_TO_INTERNAL_TABLE but I am not able to read a particular tab. My excel sheet has tabls like A, B, C and D and I want to read only tab C. But currently, it reads data in  tab A.
    regards,
    Srini.

    Pls check this and review it once. it works for 2 excel sheets in single excel file to read. Pls reward me if its helpful.  Thanks !
       FUNCTION z_uploading_from_2sheets.
    *"*"Local Interface:
    *"  IMPORTING
    *"     REFERENCE(FILE_NAME) TYPE  RLGRAP-FILENAME
    *"     REFERENCE(START_ROW_SHEET1) TYPE  I
    *"     REFERENCE(START_COLUMN_SHEET1) TYPE  I
    *"     REFERENCE(START_ROW_SHEET2) TYPE  I
    *"     REFERENCE(START_COLUMN_SHEET2) TYPE  I
    *"     REFERENCE(END_ROW_SHEET1) TYPE  I
    *"     REFERENCE(END_COLUMN_SHEET1) TYPE  I
    *"     REFERENCE(END_ROW_SHEET2) TYPE  I
    *"     REFERENCE(END_COLUMN_SHEET2) TYPE  I
    *"  TABLES
    *"      IT_DATA1 STRUCTURE  ALSMEX_TABLINE
    *"      ALSMEX_TABLINE STRUCTURE  ALSMEX_TABLINE
    *"  EXCEPTIONS
    *"      INCONSISTENT_PARAMETERS
    *"      UPLOAD_OLE
      TYPES: ty_t_sender(1500) TYPE c.
      DATA: excel_tab TYPE TABLE OF ty_s_senderline,
      excel_tab1 TYPE TABLE OF ty_s_senderline.
      DATA: ld_separator TYPE c.
      DATA: application TYPE ole2_object,
      workbook TYPE ole2_object,
      sheet TYPE ole2_object,
      range TYPE ole2_object,
      worksheet TYPE ole2_object.
      DATA: h_cell TYPE ole2_object,
      h_cell1 TYPE ole2_object.
      DATA: ld_rc TYPE i.
      DATA: it_data TYPE STANDARD TABLE OF  alsmex_tabline.
    *MESSAGE DEFINATION
      DEFINE m_message.
    *Function Module To Upload Data From
    *Excel File Into Two Internal Tables
    *© 2005 SAP AG 6
        case sy-subrc.
          when 0.
          when 1.
            message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          when others. raise upload_ole.
        endcase.
      END-OF-DEFINITION.
    *PARAMETER CHECK.
      IF start_row_sheet1 > end_row_sheet1.
        RAISE inconsistent_parameters.
      ENDIF.
      IF start_column_sheet1 > end_column_sheet1.
        RAISE inconsistent_parameters.
      ENDIF.
      IF start_row_sheet2 > end_row_sheet2.
        RAISE inconsistent_parameters.
    *Function Module To Upload Data From Excel File Into Two Internal Tables
      ENDIF.
      IF start_column_sheet2 > end_column_sheet2.
        RAISE inconsistent_parameters.
      ENDIF.
      CLASS cl_abap_char_utilities DEFINITION LOAD.
      ld_separator = cl_abap_char_utilities=>horizontal_tab.
    *OPENING EXCEL FILE
      IF application-header = space OR application-handle = -1.
        CREATE OBJECT application 'Excel.Application'.
        m_message.
      ENDIF.
      CALL METHOD OF
          application
          'Workbooks' = workbook.
      m_message.
      CALL METHOD OF
          application
          'Workbooks' = workbook.
      m_message.
      CALL METHOD OF
          workbook
          'Open'
        EXPORTING
          #1       = file_name.
      m_message.
      CALL METHOD OF
          application
          'Worksheets' = sheet
        EXPORTING
          #1           = 1.
    *Function Module To Upload Data From Excel File Into Two Internal Tables
      m_message.
      CALL METHOD OF
          application
          'Worksheets' = sheet
        EXPORTING
          #1           = 1.
      m_message.
      CALL METHOD OF
          sheet
          'Activate'.
      m_message.
      GET PROPERTY OF application 'ACTIVESHEET' = sheet.
      m_message.
    *MARKING OF WHOLE SPREADSHEET
      CALL METHOD OF
          sheet
          'Cells' = h_cell
        EXPORTING
          #1      = start_row_sheet1
          #2      = start_column_sheet1.
      m_message.
      CALL METHOD OF
          sheet
          'Cells' = h_cell1
        EXPORTING
          #1      = end_row_sheet1
          #2      = end_column_sheet1.
      m_message.
      CALL METHOD OF
          sheet
          'RANGE' = range
        EXPORTING
          #1      = h_cell
          #2      = h_cell1.
      m_message.
      CALL METHOD OF
          range
          'SELECT'.
      m_message.
    *Function Module To Upload Data From Excel File Into Two Internal Tables
    *Copy marked area (SHEET1) into Clippboard
      CALL METHOD OF
          range
          'COPY'.
      m_message.
    *Read clipboard into ABAP
      CALL METHOD cl_gui_frontend_services=>clipboard_import
        IMPORTING
          data                 = excel_tab
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4.
      IF sy-subrc <> 0.
        MESSAGE a037(alsmex).
      ENDIF.
      PERFORM separated_to_intern_convert TABLES excel_tab it_data
      USING ld_separator.
      APPEND LINES OF it_data TO it_data1.
    *Function Module To Upload Data From Excel File Into Two Internal Tables
    *Clear the clipboard
      REFRESH excel_tab.
      CALL METHOD cl_gui_frontend_services=>clipboard_export
        IMPORTING
          data                 = excel_tab
        CHANGING
          rc                   = ld_rc
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4.
    *Working in Second Excel Work Sheet
      CALL METHOD OF
          application
          'Worksheets' = sheet
        EXPORTING
          #1           = 2.
      m_message.
      CALL METHOD OF
          sheet
          'Activate'.
      m_message.
    *Function Module To Upload Data From Excel File Into Two Internal Tables
      GET PROPERTY OF application 'ACTIVESHEET' = sheet.
      m_message.
    *Mark Sheet2
      CALL METHOD OF
          sheet
          'Cells' = h_cell
        EXPORTING
          #1      = start_row_sheet2
          #2      = start_column_sheet2.
      m_message.
      CALL METHOD OF
          sheet
          'Cells' = h_cell1
        EXPORTING
          #1      = end_row_sheet2
          #2      = end_column_sheet2.
      m_message.
      CALL METHOD OF
          sheet
          'RANGE' = range
        EXPORTING
          #1      = h_cell
          #2      = h_cell1.
      m_message.
      CALL METHOD OF
          range
          'SELECT'.
      m_message.
    *Copy Marked Area (Sheet2) into Clippboard
      CALL METHOD OF
          range
          'COPY'.
      m_message.
    *Function Module To Upload Data From Excel File Into Two Internal Tables
    *Read Clipboard into ABAP
      CALL METHOD cl_gui_frontend_services=>clipboard_import
        IMPORTING
          data                 = excel_tab1
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4.
      IF sy-subrc <> 0.
        MESSAGE a037(alsmex).
      ENDIF.
    *PERFORM separated_to_intern_convert TABLES excel_tab1 IT_DATA2
      PERFORM separated_to_intern_convert TABLES excel_tab1 it_data
      USING ld_separator.
    *Clear Clipboard.
      REFRESH: excel_tab1.
      APPEND LINES OF it_data TO it_data1.
      CALL METHOD cl_gui_frontend_services=>clipboard_export
    *Function Module To Upload Data From Excel File Into Two Internal Tables
      IMPORTING
      data = excel_tab1
      CHANGING
      rc = ld_rc
      EXCEPTIONS
      cntl_error = 1
      error_no_gui = 2
      not_supported_by_gui = 3
      OTHERS = 4
    *Leaving Application
      CALL METHOD OF
          application
          'QUIT'.
      m_message.
    * >>>>> Begin of change note 575877
    * to kill the Excel process it's necessary to free all used objects
      FREE OBJECT h_cell.       m_message.
      FREE OBJECT h_cell1.      m_message.
      FREE OBJECT range.        m_message.
      FREE OBJECT worksheet.    m_message.
      FREE OBJECT workbook.     m_message.
      FREE OBJECT application.  m_message.
    * <<<<< End of change note 575877
    ENDFUNCTION.

  • Write data of a table to an excel sheet

    Hi
    How i can write data of a table to an excel sheet?
    regard
    deemy

    Search this forum for 1.2 Jiga-examples...

  • How to get the password of a password protected Excel Sheet using java/jxl

    Hi ,
    how to get the password of a password protected Excel Sheet using java / jxl program.
    plz any one help me .
    Ramesh P
    [email protected]

    If they've implemented the password system correctly there probably isn't a way of getting the password at all.

  • How to download data into one cell of excel in different lines

    Hi All,
    My Report downloads data from R/3 to excel. Now one particular field contains multiple lines, which i needs to download into different lines into that particular cell(of excel). how can i do this.
    I found one method for this and that is cl_abap_char_utilities=>newline.But this is in abap version 6.0.
    But i am working in version 4.6c. do we have any method or anything that meets my requirement in 4.6c.
    Please let me know.
    Thanx in Advance
    Subhani.

    why do you split them to the internal table ,then download it?
    Is you special field long text?
    If is ,you can use FM READ_TEXT to put it into an internal table ,then download it.

  • How to dowload data

    I download data from database via a HTTPServlet.
    Since the download SQL query delivers data only after 10 min, I have the problem that the download popup appears also in 10 min ( this is by Firefox ). How could I force that the download popup appers immediate ? I cannot let the user to wait 10 min - he should get the popup immediate, and the progress of the download should be as the database delivers the data.

    Hi Neetu,
    you can use OLE in that case.
    REPORT  ZTEST_EXCEL             .
    INCLUDE ole2incl.
    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),
    last_name(10),
    END OF itab1.
    START-OF-SELECTION.
    itab1-first_name = '123445'.
    itab1-last_name = 'tesst'.
    append itab1.
    clear itab1.
    itab1-first_name = '123446'.
    itab1-last_name = 'tesst'.
    append itab1.
    clear itab1.
      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'.
      LOOP AT itab1.
        index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
        CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
        SET PROPERTY OF cells 'Value' = itab1-first_name.
            index = index + 1. " 1 - column name
        CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
        SET PROPERTY OF cells 'Value' = itab1-last_name.
      ENDLOOP.
    * Save excel speadsheet to particular filename
      CALL METHOD OF sheet 'SaveAs'
                     EXPORTING #1 = 'c:tempexceldoc1.xls'     "filename
                                #2 = 1.                          "fileFormat
    Regards
    vijay

Maybe you are looking for