Hi Folks,
My requirement is to download excel from sap crm web ui to local pc.I have tried writing the below code in .htm page of my search view. But the onclientClick event is not working. Please help :-
<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<%@extension name="thtmlb" prefix="thtmlb" %>
<%@extension name="chtmlb" prefix="chtmlb" %>
<%@extension name="bsp" prefix="bsp" %>
<%
TYPES: BEGIN OF ty_data,
equipment TYPE zserial_no1, "Unit Number
unit_type TYPE zunit_type1, "Unit type
lease_no TYPE zlease_no, "Lease
city TYPE zloc_offhire, "Offhire Loc
depot TYPE char40, "Depot name
in_date(10) TYPE c, "Offhire date
dn_number TYPE crmt_object_id_db, "Dn Ref
ra_number TYPE char35, "Auth'n No
currency TYPE bea_doc_currency, "Currency
amt_char TYPE string, "Curr. Value
exe_rate TYPE char15, "Exchange rate
usdvalue TYPE string, "Amount (USD)
headno_ext TYPE bea_headno_ext, "Invoice#
bill_date(10) TYPE c, "Invoice Date
customer TYPE zcust_no, "Account #
net_value TYPE bea_net_value,
tax_value TYPE bea_net_value,
exchange_rate TYPE zbea_exchange_rate,
END OF ty_data.
DATA : lv_count type i,
ls_data TYPE ty_data,
it_data TYPE STANDARD TABLE OF ty_data.
%>
<thtmlb:searchArea>
<thtmlb:searchTagArea>
<thtmlb:advancedSearch id = "AdvancedOrderSearch"
fieldMetadata = "<%= controller->get_dquery_definitions( ) %>"
header = "<%= REPAIROUTSRCH->get_param_struct_name( ) %>"
fieldNames = "<%= controller->get_possible_fields( ) %>"
values = "//REPAIROUTSRCH/parameters"
showMaxHits = "FALSE"
ajaxDeltaHandling = "false"
onEnter = "EXECUTE" />
</thtmlb:searchTagArea>
<thtmlb:searchButtonsArea>
<thtmlb:button design = "EMPHASIZED"
id = "EXECUTE_BTN"
onClick = "EXECUTE"
text = "Execute" />
<thtmlb:button design = "EMPHASIZED"
id = "Exceldwn"
enabled = "TRUE"
text = "Download to Excel"
onClientClick = "javascript:dwnToExcel();"/>
</thtmlb:searchButtonsArea>
</thtmlb:searchArea>
<script language="javascript">
<%--var button = document.getElementById("Exceldwn");
button.focus();
button.click();--%>
function dwnToExcel()
{
alert("function called");
var Excel,Workbook;
var count=1;
Excel =new ActiveXObject("Excel.Appliaction");
Workbook = Excel.Workbooks.Add();
Workbook.ActiveSheet.Cells(1,1).Value = "Unit Number";
Workbook.ActiveSheet.Cells(1,2).Value = "Unit type";
Workbook.ActiveSheet.Cells(1,3).Value = "Lease";
Workbook.ActiveSheet.Cells(1,4).Value = "Offhire Loc";
Workbook.ActiveSheet.Cells(1,5).Value = "Depot name";
Workbook.ActiveSheet.Cells(1,6).Value = "Offhire date";
Workbook.ActiveSheet.Cells(1,7).Value = "Dn Ref";
Workbook.ActiveSheet.Cells(1,8).Value = "Auth No";
Workbook.ActiveSheet.Cells(1,9).Value = "Currency";
Workbook.ActiveSheet.Cells(1,10).Value = "Curr. Value";
Workbook.ActiveSheet.Cells(1,11).Value = "Exchange rate";
Workbook.ActiveSheet.Cells(1,12).Value = "Amount (USD)";
Workbook.ActiveSheet.Cells(1,13).Value = "Invoice#";
Workbook.ActiveSheet.Cells(1,14).Value = "Invoice Date";
Workbook.ActiveSheet.Cells(1,15).Value = " Account #";
Workbook.ActiveSheet.Range("A1:F1").Interior.ColorIndex = 43;
Workbook.ActiveSheet.Range("A1:F15").Borders(7).LineStyle = 2;
Workbook.ActiveSheet.Range("A1:F15").Borders(8).LineStyle = 2;
Workbook.ActiveSheet.Range("A1:F15").Borders(9).LineStyle = 2;
Workbook.ActiveSheet.Range("A1:F15").Borders(10).LineStyle = 2;
Workbook.ActiveSheet.Range("A1:F15").Font.Size = 10;
<%
it_data = zl_zrepair__repairoutputs_impl=>gt_excel_data.
LOOP AT it_data INTO ls_data.
lv_count = sy-index .
%>
count = "<%= lv_count %>";
Workbook.ActiveSheet.Cells(count,1).Value = "<%= ls_data-equipment %>";
Workbook.ActiveSheet.Cells(count,2).Value = "<%= ls_data-unit_type %>";
Workbook.ActiveSheet.Cells(count,3).Value = "<%= ls_data-lease_no %>";
Workbook.ActiveSheet.Cells(count,4).Value = "<%= ls_data-city %>";
Workbook.ActiveSheet.Cells(count,5).Value = "<%= ls_data-depot %>";
Workbook.ActiveSheet.Cells(count,6).Value = "<%= ls_data-in_date %>";
Workbook.ActiveSheet.Cells(count,7).Value = "<%= ls_data-dn_number %>";
Workbook.ActiveSheet.Cells(count,8).Value = "<%= ls_data-ra_number %>";
Workbook.ActiveSheet.Cells(count,9).Value = "<%= ls_data-currency %>";
Workbook.ActiveSheet.Cells(count,10).Value = "<%= ls_data-amt_char %>";
Workbook.ActiveSheet.Cells(count,11).Value = "<%= ls_data-exe_rate %>";
Workbook.ActiveSheet.Cells(count,12).Value = "<%= ls_data-usdvalue %>";
Workbook.ActiveSheet.Cells(count,13).Value = "<%= ls_data-headno_ext %>";
Workbook.ActiveSheet.Cells(count,14).Value = "<%= ls_data-bill_date %>";
Workbook.ActiveSheet.Cells(count,15).Value = "<%= ls_data-customer %>";
<%
ENDLOOP.
%>
Excel.Visible = "true";
Workbook.SaveAs( <demo> );
}
</script>
Regards
Nagendra.