Skip to Content
author's profile photo Former Member
Former Member

BSP and Excel

Hi All,

I have a specific requirement ....

I want to display data that is in an internal table on to thye Browser using BSP. I have done it using PDF format using Smartforms, but Excel..I am not sure..

Can anyone help....



Add a comment
10|10000 characters needed characters exceeded

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 31, 2004 at 04:29 PM

    Hello Suresh,

    I've not tried anything with excel and BSP's before but I do remember reading about here in fact quite often. You should try a search in this forum for "Excel" here is what it returned for me, perhaps these will help you get started enough that you might be able to post a specific problem you are having later...



    As for displaying a table in a BSP whether it is internal or not defiently check out the tableView.bsp example in se80 (BSP Application for HTMLB) then check out Brian McKellar's WebLog <a href="/people/brian.mckellar/blog/2003/10/31/bsp-programming-htmlb-tableview-iterator">BSP Programming: HTMLB TableView Iterator</a>

    Once you've started and come across a snag or otherwise strange problem give a shout back and I'm sure you'll be able to catch a few people online who are happy to give a hand.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2004 at 06:54 AM

    Hi Suresh,

    you can upload the data from the Excel into BSP application in the following ways.

    1. In the application use file upload to upload the file.

    2. caputure the content and length



    request = runtime->server->request

    name = 'fileUpload'

    id = 'xx').

    name = data->file_name.

    content = data->file_content.

    length = data->file_length.

    content_type = data->file_content_type.

    3. Then read the data using the class


    conv = CL_ABAP_CONV_IN_CE=>CREATE( input = CONTENT ).

    conv->READ( importing data = Variable len = length ).

    Hope this solves your purpose.



    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Suresh,

      I tried executing your code to transfer an internal table to Excel, But i am getting some runtime Error as:

      Following error text processed in system:

      An exception with the type CX_SY_REF_IS_INITIAL occurred, but was neither handled locally, nor declared in a RAISING clause

      Please help me how to correct this error.

      Thanks ...

  • Posted on Sep 20, 2004 at 09:47 AM


    in my opinion it is much easier to call excel as a control. You have only to supply the data via cs format.

    This snippet should work:

        <TITLE>Web-Based Excel Data</TITLE>
    <SCRIPT language=JavaScript type=text/javascript>
    // ***************************************************** EXCEL RUNTIME
    //   before submitting the form save the user input
    //   from sheet to the form (hidden) fields
      // class InputRange - constructor
      function InputRange(layout_id, sheet,top,left,bottom,right,isText) {
      //  set local variables
    = layout_id;
     = top;
          this.left    = left;
          this.bottom  = bottom;
          this.right   = right;
          this.sheet   = sheet;
          this.isText  = isText;
   = inputRange_store; // methods
      function inputRange_store() {
        var theForm = document.forms("bspform");
        with (this) {
          var fname = name + "-" + top + "-" + left + "-" + bottom + "-" + right;
          if (isText) {
            // we must resolve non formated values. The only posibility is via loop:
            var tsv = ""; // tab separated values
            for (var row = top; row <= bottom; row++)
              for (var col = left; col <= right; col++)
                tsv += sheet.Cells(row,col) + "t";
            theForm.elements(fname).value = tsv;
          else {
            // work throwgh clipboard (Microsoft doesn't provide other method to read range)
            theForm.elements(fname).value = clipboardData.getData("Text");
      // endclass InputRange
      // ARRAY that holds inputRanges descriptions
      var inputCollection = new Array();
      // loops over the inputCollection (if it contains input any entry)
      function processLayoutInput() {
        if (inputCollection.length) {
          // remember the text from clipboard
          var clipBoardStorage = clipboardData.getData("Text");
          for (var i = 0; i < inputCollection.length; i++) {
    // *********************************************** end of excel runtime
    <BODY >
      <OBJECT id=Layout_1 
              style="WIDTH: 1200px; HEIGHT: 700px" 
              classid=CLSID:0002E510-0000-0000-C000-000000000046><PARAM NAME="DisplayTitleBar" VALUE="false"><PARAM NAME="HTMLData" VALUE=" 
    "></OBJECT></TD></TR></TBODY></TABLE><!-- non visual code for layout Layout_1 --><INPUT 
                            type=hidden name=Layout_1-detail> <!-- detail selection --><INPUT type=hidden 
                            name=Layout_1-detail_size> <INPUT type=hidden 
                            name=Layout_1-5-2-8-8> <INPUT type=hidden 
                            name=Layout_1-10-2-17-8> <INPUT type=hidden 
                            name=Layout_1-19-2-26-8> <INPUT type=hidden 
                            name=Layout_1-29-2-34-8> <INPUT type=hidden 
                            name=Layout_1-38-2-38-8> <INPUT type=hidden 
                            <SCRIPT language=JavaScript type=text/javascript>
      layout_sheet = document.all( "Layout_1" );
      layout_sheet.ActiveSheet.Protection.Enabled = false;
    // ****************************************************** remember input ranges
        inputRange = new InputRange("Layout_1",layout_sheet,5 ,2 ,8 ,8 ,false);
        inputCollection = inputCollection.concat(inputRange);
        inputRange = new InputRange("Layout_1",layout_sheet,10 ,2 ,17 ,8 ,false);
        inputCollection = inputCollection.concat(inputRange);
        inputRange = new InputRange("Layout_1",layout_sheet,19 ,2 ,26 ,8 ,false);
        inputCollection = inputCollection.concat(inputRange);
        inputRange = new InputRange("Layout_1",layout_sheet,29 ,2 ,34 ,8 ,false);
        inputCollection = inputCollection.concat(inputRange);
        inputRange = new InputRange("Layout_1",layout_sheet,38 ,2 ,38 ,8 ,false);
        inputCollection = inputCollection.concat(inputRange);
        inputRange = new InputRange("Layout_1",layout_sheet,40 ,2 ,50 ,8 ,false);
        inputCollection = inputCollection.concat(inputRange);
    // ******************************************************* set content
        range = layout_sheet.Range(layout_sheet.Cells(3 ,1 ),layout_sheet.Cells(3 , 8 ));
        content_csv = "';'column 1;'column 2;'column 3;'column 4;'column 5;'column 6;'column 7" ;
        range.ParseText(content_csv, ";");
        range = layout_sheet.Range(layout_sheet.Cells(5 ,1 ),layout_sheet.Cells(10 , 8 ));
        content_csv = "'row 1;10;20;20;40;80;160;320n'row 2;180,000;0;0;0;0;0;0n'row 3;0;0;0;0;0;0;0n'row 
    4;0;0;0;0;0;0;0n'Sum;180,000;0;0;0;0;0;0n'" ;
        range.ParseText(content_csv, ";");
    // ******************************************************* set format
        range = layout_sheet.Range(layout_sheet.Cells(5 ,1 ), layout_sheet.Cells(10 , 1 ));  //
          range.NumberFormat  = "@";  //
        range = layout_sheet.Range(layout_sheet.Cells(5 ,2 ), layout_sheet.Cells(10 , 8 ));  //
          range.NumberFormat  = "#,##0.";  //
        range = layout_sheet.Range(layout_sheet.Cells(3 ,1 ), layout_sheet.Cells(3 , 1 ));   //
          range.Font.Color =  4276545 ;  //
          range.Font.Size  =  12 ;  //
          range.Font.Bold  =  1 ;  //
          range.Interior.Color = 16051415 ;  //
        range = layout_sheet.Range(layout_sheet.Cells(3 ,2 ), layout_sheet.Cells(3 , 8 ));   //
          range.Font.Color =  4276545 ;  //
          range.Font.Size  =  12 ;  //
          range.Font.Bold  =  1 ;  //
          range.Interior.Color = 16051415 ;  //
        range = layout_sheet.Range(layout_sheet.Cells(5 ,1 ), layout_sheet.Cells(10 , 1 ));   //
          range.Font.Color =  4276545 ;  //
          range.Font.Size  =  9 ;  //
          range.Interior.Color = 16051415 ;  //
        range = layout_sheet.Range(layout_sheet.Cells(5 ,2 ), layout_sheet.Cells(8 , 8 ));   //
          range.Font.Color =  4276545 ;  //
          range.Font.Size  =  9 ;  //
          range.Interior.Color = 16777215 ;  //
          range.Locked         = 0 ;  //
        range = layout_sheet.Range(layout_sheet.Cells(9 ,2 ), layout_sheet.Cells(9 , 8 ));   //
          range.Font.Color =  4276545 ;  //
          range.Font.Size  =  9 ;  //
          range.Interior.Color = 16051415 ;  //
        layout_sheet.Cells.AutoFitColumns();  //
      layout_sheet.ActiveSheet.Protection.Enabled = true;
    // -->

    Hope this helps also :-).

    Best regards,


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Just a note, I was able to get the sample to return data.

      I had to change the following statement in the processLayoutInput() function:

      Changed to:

      (Note: Change the ℹ️ above to use square brackets []. Forum interpreted the -square-i-square as italics)

      I also had to change the name of the hidden fields to use '_' instead of '-'; Page Attributes didn't like the '-'.

      Just added processLayoutInput as the "onSubmit" for the Form, and got the data back.

  • Posted on Sep 21, 2004 at 09:10 PM

    Hello Brian,

    yes, there is a cut&paste error. I have this copied from my bsp-application. The original is some larger and longer and i want only to show the way. Interested guys can get the whole documentation from the microsoft developer network.

    Like this way you can also deal with word. Powerpoint is much more difficult and not really interesting.

    My first approach was to load the data via vba into excel standalone, but that's more work than this.

    If i have some time, i create a weblog. But before, i want to capsulate this in a own extension. I have also some other funny things.

    Best regards,


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 24, 2004 at 09:52 AM

    hello togehter,

    i wil post a complete example within a weblog at the next time.

    Three remarks:

    1) You can find the documentation on

    2) You can also automate word, if you want.

    3) You can also automate excel in a separate window.

    An impressive example:



    <INPUT id=button1 name=button1 type=button value=Button>


    sub button1_onclick()

    ' Launch Excel

    dim app

    set app = createobject("Excel.Application")

    ' Make it visible

    app.Visible = true

    ' Add a new workbook

    dim wb

    set wb = app.workbooks.add

    ' Fill array of values first...

    dim arr(19,9)

    for i = 1 to 10

    for j = 1 to 10

    arr(i-1,j-1) = i*j



    ' Declare a range object to hold our data

    dim rng

    set rng = wb.Activesheet.Range("A1").Resize(20,10)

    ' Now assign them all in one shot...

    rng.value = arr

    ' Give the user control of Excel

    app.UserControl = true

    end sub




    Best regards,


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 27, 2004 at 02:17 PM

    Hello to all,

    sorry for the long message, but I think there is maybe someone out there who might bee interestet...

    Excel (from version 2000) supports HTML as a native file format. Here you find a reference:

    Using this file fomat it’s easy to let a View build an Excel-File for you:

    Set the views mime type to: application/

    Layout (not a running example, just some snippets):

    <%@page language="abap"%>
       DATA: dataref   TYPE REF TO DATA,
             wa_field  LIKE LINE OF it_field,
             f_type(1) TYPE C,
             wa_ref    TYPE REF TO DATA.
       FIELD-SYMBOLS: <fs>          TYPE ANY,
                      <fs_wa_data>  TYPE ANY,
                      <fs_data_tab> TYPE STANDARD TABLE.
       ASSIGN (data_tab) TO <fs_data_tab>.
       CREATE DATA wa_ref LIKE LINE OF <fs_data_tab>.
       ASSIGN wa_ref->* TO <fs_wa_data>.
       " Erstellungsdatum ermitteln
       DATA: date_created TYPE STRING,
             s_tst        TYPE timestamp,
             c_tst(15)    TYPE C.
       GET TIME STAMP FIELD s_tst.
       c_tst = s_tst.
       CONCATENATE c_tst(4) '-' c_tst+4(2) '-' c_tst+6(2) 'T' c_tst+8(2) ':' c_tst+10(2) ':' c_tst+12(2) 'Z' INTO date_created.
       DATA: wa LIKE LINE OF model->detail_list_all.
       FIELD-SYMBOLS <wa> LIKE LINE OF model->detail_list_all.
    <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="">
    <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
    <meta name=ProgId content=Excel.Sheet>
    <meta name=Generator content="Microsoft Excel 9">
      <o:LastAuthor>Thilo Klopfer</o:LastAuthor>
      <o:Company>Excel via View</o:Company>
    	{margin:.98in .79in .98in .79in;
    	mso-protection:locked visible;
    	mso-protection:locked visible;
    	font-family:Arial, sans-serif;
    <body link=blue vlink=purple>
    <table x:str border=0 cellpadding=0 cellspacing=0 width=400 style='border-collapse:collapse;table-layout:fixed;width:300pt'>
     <%-- Spaltenbreiten einstellen --%>
     <col style='mso-width-source:userset;mso-width-alt:800'>
     <% LOOP AT it_field INTO wa_field. %>
            <col style='mso-width-source:userset;mso-width-alt:<%=wa_field-width%>'>
     <% ENDLOOP. %>
     <%-- Spaltenüberschriften --%>
     <tr height=17 style='height:12.75pt'>
         <% LOOP AT it_field INTO wa_field.
             IF wa_field-header IS INITIAL.
                 " Header über DDIC ermitteln
                 CONCATENATE '<fs_wa_data>-' wa_field-name INTO wa_field-name.
                 ASSIGN (wa_field-name) TO <fs>.
                 GET REFERENCE OF <fs> INTO dataref. %>
                 <td class=Hd<%=lmr%>><%=runtime->ddic_utils->get_field_label( data_object_ref = dataref )%></td>
             <% ELSE.     " Header wurde in der Tabelle übergeben    %>
                 <td class=Hd<%=lmr%>><%=wa_field-header%></td>
             <% ENDIF.
         ENDLOOP. %>
     <%-- Datentabelle verarbeiten --%>
     <% LOOP AT <fs_data_tab> ASSIGNING <fs_wa_data>. %>
         <tr height=17 style='height:12.75pt'>
    <%       LOOP AT it_field INTO wa_field.
                 CONCATENATE '<fs_wa_data>-' wa_field-name INTO wa_field-name.
                 ASSIGN (wa_field-name) TO <fs>.
                 DESCRIBE FIELD <fs> TYPE f_type.
                 IF f_type = 'P' OR f_type = 'I' OR f_type = 'N' OR f_type = 'b'. %>
                     <td class="Dat" x:num style='<%=wa_field-style%>'><%=application->excel_to_string( <fs> )%></td>
    <%           ELSEIF f_type = 'D'. %>
                     <td class="Dat" x:num style='mso-number-format:"Short Date";<%=wa_field-style%>'><%=application->excel_to_string( <fs> )%></td>
    <%           ELSEIF f_type = 'T'. %>
                     <td class="Dat" x:num style='mso-number-format:"hh:mm:ss";<%=wa_field-style%>'><%=application->excel_to_string( <fs> )%></td>
    <%           ELSE. %>
                     <td class="Dat" style='<%=wa_field-style%>'><%=<fs>%></td>
    <%           ENDIF.
             ENDLOOP. %>
     <% ENDLOOP. %>

    In ON_HANDLE_EVENT I call a method which is calling the view, generates the Excel-File an stores the output in ICM-Cache:

      DATA: view            TYPE REF TO if_bsp_page.
      DATA: cached_response TYPE REF TO if_http_response.
      DATA: guid            TYPE guid_32.
      DATA: lt_fields TYPE /sie/ad_z0mxls_field_t,
            l_field   TYPE /sie/ad_z0mxls_field_s,
            l_esn     TYPE /sie/ad_z0mesns_s,
            l_file    TYPE string,
            l_string  TYPE string,
            l_out     TYPE REF TO if_bsp_writer.
      view = create_view( view_name = 'xls_download.xls' ).
    * Die bisher aufgebaute Seite löschen, sie wird ersetzt
      l_out = view->get_out( ).
      l_out->clear( ).
      view->set_attribute( name = 'model' value  = model ).
      view->set_attribute( name = 'worksheet' value  = 'Worksheet Name' ).
      view->set_attribute( name = 'title'   value  = 'Excel Title' ).
      view->set_attribute( name = 'subject' value  = 'Subject' ).
      view->set_attribute( name = 'data_tab' value = 'MODEL->DATA_LIST' ).
      " Felder, die exportiert werden sollen
      l_field-name = 'Z0MEPNR'.            l_field-width = '3291'. l_field-header = ''.  APPEND l_field TO lt_fields.
      l_field-name = 'Z0MEPMATFLD'.        l_field-width = '5376'. l_field-header = ''.  APPEND l_field TO lt_fields.
      l_field-name = 'Z0MCOBEZ'.           l_field-width = '7314'. l_field-header = 'Mat-Grp'. APPEND l_field TO 
      l_field-name = 'Z0MEPRESP'.          l_field-width = '3840'. l_field-header = ''.  APPEND l_field TO lt_fields.
      view->set_attribute( name = 'it_field' value = lt_fields ).
      call_view( view ).
    * Ausgabe der Exceltabelle aus dem ICM-Cache
      l_out = view->get_out( ).
      l_string = l_out->get_content( ). "Seiteninhalt übernehmen
      CREATE OBJECT cached_response TYPE cl_http_response EXPORTING add_c_msg = 1.
      cached_response->set_cdata( l_string ).
      cached_response->set_header_field( name  = if_http_header_fields=>content_type
                                         value = 'application/' ).
      cached_response->set_status( code = 200 reason = 'OK' ).
      cached_response->server_cache_expire_rel( expires_rel = 180 ).
          ev_guid_32 = guid.
      CONCATENATE runtime->application_url '/' guid INTO display_url.
      cl_http_server=>server_cache_upload( url      = display_url
                                           response = cached_response ).
      " Der Excel-Output von oben muss gelöscht werden
      l_out->clear( ).

    In the Excel-View above, you can do almost everything (Formulars, Layout, Conditional Formatting, …)Excel can do. And you don't need ActiveX in the clients browser. If you don't want to read the reference from Micorsoft, try this:

    - Build your table in Excel.

    - Save as HTML

    - look what Excel wrote in the .htm file.

    Have Fun (reading the german remarks)


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 27, 2004 at 08:06 PM

    All of this is becoming very interesting. Looking into my crystal ball, I can see that we have now two very good ideas for extended weblogging. What is nice about a weblog with a well polished text, is that it is a self contained, which can include text, source, images, links. Any takers? (Unfortunately SDN is not giving out points anymore, but we still have open slots on our wall of fame!)

    Add a comment
    10|10000 characters needed characters exceeded

    • Anubhav Jain Durairaj Athavan Raja

      Hi All,

      I am using the code from the weblog for downloading data from internal table to excel through BSP application (MVC):

      Suppose ITAB is my internal table:

      data: output TYPE string ,

      app_type TYPE string ,

      l_xstring TYPE xstring.

      CONSTANTS: crlf TYPE string VALUE cl_abap_char_utilities=>cr_lf,

      tab TYPE string VALUE


      if itab is NOT INITIAL .

      loop at itab_final INTO wa .

      concatenate output wa-field1





      INTO output SEPARATED BY TAB .



      *end of addition.

      app_type = 'APPLICATION/MSEXCEL;charset=utf-16le'.



      text = output

      mimetype = 'APPLICATION/MSEXCEL;charset=utf-16le'


      buffer = l_xstring.

      Add the Byte Order Mark - UTF-16 Little Endian

      CONCATENATE cl_abap_char_utilities=>byte_order_mark_little


      INTO l_xstring IN BYTE MODE.

      CALL METHOD cl_bsp_utility=>download


      object_s = l_xstring

      content_type = app_type

      content_disposition = 'attachment;filename=webforms.xls'

      response = response

      navigation = navigation.

      endif .

      Now when the excel sheet opens , the first column is coming blank.

      I mean the first field of internal table ITAB is coming from column B of excel sheet.

      Has anyone come across same problem?


Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.