Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Link to Content's target Space :

http://wiki.sdn.sap.com/wiki/display/CRM/CRM+Web+Client+UI+Framework

Applies to:

CRM 6.0/7.0

Summary

Download data from web ui to Excel and Powerpoint presentation with formatting options using ActiveXObjects and Javascript.
As an alternative for an Excel Export that doesn't require ActiveX check out WebClient UI Export to Spreadsheet with abap2xlsx

Author(s):  

   
Company:     Accenture
Created on:    May'11 - 2010
Author(s) Bio

       Arun Kumar is a CRM developer working with Accenture India.

      Exporting data to a file from web ui is already available in CRM but it is limited to certain file types. For example data cannot be downloaded to an Excel file or Powerpoint  presentation. The 'Export to Excel' button available in tableview tag downloads the file as an XML spreadsheet and not to an Excel file.

     This wiki explains how to download data to an Excel file and Powerpoint presentation using ActiveXObjects in Javascript. We do not use SICF service or any handler class.

     I have created a value node and populated some data and displayed it in a Table View and added a  button 'Download to Excel' which triggeres the Javascript function 'download()'  onclientclick. The entire download function is written in the page layout.

( Note: I was not able to save the wiki with standard scripting  and activex keywords. So i have added the coding as image as per the advice from SDN support)
 

Download to Excel function:

Create an Excel workbook using acitvexobject and get the reference in a variable 'Excel'. ( I have used AXO to refer active x objects. I cant use the original keyword. )

Excel = new AXO("Excel.Application"); 

Add Workbooks to the file. The object reference is passed to a variable'Workbook'.

Workbook = Excel.Workbooks.Add();

This reference variable 'Workbook' has a list of properties and methods that can be used to format the Excel file further. These are available in the Microsoft msdn library.
Now we can directly add values to the Excel sheet that is active in the Excel workbook.     

Workbook.ActiveSheet.Cells(1,1).Value = "Hello";          

This statement writes the value 'Hello' to cell 1:1 of the first sheet in the Excel file.

Adding background color to a range of cells, 

Workbook.ActiveSheet.Range("A1:F1").Interior.ColorIndex = 43;

 This statement adds color from cell A1 to F1. 

All formatting options including adding formula to a cell, condition formatting, inserting images etc., can be done using ActiveXObjects.

Finally the Excel file must be made visible.   

Excel.Visible = "true";

The file can be saved directly to the user desktop.    

Workbook.SaveAs( <filename>);

Download to PPT

Create a powerpoint application using AXO.

var myApp = new AXO("PowerPoint.Application");

Add Presentations to the application and slides to the presentation. Once the clides are created, add tables to populate the data.

var presentation = myApp.Presentations.Add();
      presentation.Slides.Add(1,12);
      presentation.Slides(1).Shapes.AddTable(7, 6, 60, 120, 600, 316);

Data can be populated to table cells by referring to the cell location.

presentation.Slides(1).Shapes(1).Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "Product ID";

Finally the presentation is made visible.

myApp.Visible = true;

Tableview:


Downloaded Excel file:

 

Coding:

 

 

 

 

Thanks & Regards,

Arun Kumar 

6 Comments

  1. Former Member

    Hi Arun,

    I got the similar kind of requirement for downloading the data into Excel from UI. I did the same steps but when i had clicked on the button in which excel download has to be done, nothing is happening. Could you please let me know any more steps required inorder to trigger the logic behind the button.

    If you dont mind, could you please provide your mail id so that i can explain more by giving screenshots.

    Thanks & Regards,

    Uday

  2. Hi Uday,

    I think the approach shown by Arun could be problematic in a environment where you can't use Microsoft Internet Explorer. A better idea if you need nicely formatted Excel files is the abap2xlsx project available at https://cw.sdn.sap.com/cw/groups/abap2xlsx. A standard solution for Excel downloads is the Excel download available in all table views.

    Best regards
    Gregor

  3. Hi Gregor,

    The abap2xlsx project downloads the file in .xlsx format (Open XML Format Spreadsheet file) and not in an Excel format. .Xlsx file is similar to a zipped file package of XML spreadsheets. And the standard 'Export to Excel' available is table view, DOWNLOADS XML FILES and not Excel files. The 'Export to Excel' event handler class is CL_CHTMLB_CONFIG_TAB_EXCEL_EXP.   

    Hi Uday,

    My mail id is available in my business card.

    Regards,

    Arun

  4. Hi Arun,

    as there are free converters for older Excel Version to read the XLSX format I don't see a problems here. The Export to excel works also fine in Excel 2003.

    Best regards
    Gregor

  5. Hi Arun,

    I am also using the same code what you suggested . But nothing is happening and i am getting java script error as mentioned below.

    1. I tried to get your email id through your business card but i am not able to see it. Could you please send me your email id.

    You can send it on my email id kapilkumar.nitj@gmail.com

    2. Also can you please tell is there any special setup needed for active x object.

    Please provide me your valuable inputs for this requirement. I will really appreciate your help.

    syntax error.

    1. BSPWDAPPLICATION.DO

    2. OBJECTEXPECTED

    EVENT.JS

    Thanks & Regards,

    Kapil Kumar

  6. Hi Arun,

     

    I followed exactly as mentioned above. But when i click on the button nothing is happening.

    can you please help

    In your business card i couldn't find your email id