Repository navigation
Expand file tree
/
Copy pathexportToExcel.js
More file actions
49 lines (40 loc) · 2 KB
/
Copy pathexportToExcel.js
File metadata and controls
49 lines (40 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function myFnExcelReport(iframeId)
{
//Thanks to: https://stackoverflow.com/a/24081343/2547429
var tab_text="<table border='2px'><tr bgcolor='#87AFC6'>";
var textRange; var j=0;
tab = $('.oe_timesheet_weekly_date_head').closest('table')[0];//document.getElementById('headerTable'); // id of table
for(j = 0 ; j < tab.rows.length ; j++)
{
tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
//tab_text=tab_text+"</tr>";
}
tab_text=tab_text+"</table>";
tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");//remove if u want links in your table
tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in your table
tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
{
document.getElementById(iframeId).document.open("txt/html","replace");
document.getElementById(iframeId).document.write(tab_text);
document.getElementById(iframeId).document.close();
document.getElementById(iframeId).focus();
sa=document.getElementById(iframeId).document.execCommand("SaveAs",true,"horasERP.xls");
}
else //other browser not tested on IE 11
sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
return (sa);
}
(function AddNeededElements(){
var iFrameName='myExcelExportIFrameName';
var iFrame = document.createElement("iframe");
iFrame.setAttribute("id",iFrameName);
iFrame.setAttribute("style","display:none");
var btnExport = document.createElement("button");
btnExport.setAttribute("onclick","myFnExcelReport('"+iFrameName+"');");
btnExport.innerHTML = "Exportar a Excel";
document.body.appendChild(iFrame);
document.getElementsByClassName("oe_form_group ")[0].appendChild(btnExport);
})();