1
+ var ExcelExport = function ( ) {
2
+
3
+
4
+
5
+ } ;
6
+
7
+ ExcelExport . prototype . exportTableHTML = ( function ( ) {
8
+ var uri = 'data:application/vnd.ms-excel;base64,'
9
+ , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
10
+ , base64 = function ( s ) { return window . btoa ( unescape ( encodeURIComponent ( s ) ) ) }
11
+ , format = function ( s , c ) { return s . replace ( / { ( \w + ) } / g, function ( m , p ) { return c [ p ] ; } ) } ;
12
+ return function ( tableHTML , name ) {
13
+ var ctx = { worksheet : name || 'Worksheet' , table : tableHTML } ;
14
+ console . log ( uri + base64 ( format ( template , ctx ) ) ) ;
15
+ window . location . href = uri + base64 ( format ( template , ctx ) )
16
+ }
17
+ } ) ( ) ;
18
+
19
+ ExcelExport . prototype . exportXLS = function ( ) {
20
+
21
+ var lpt = document . getElementsByClassName ( "lpt" ) [ 0 ] ,
22
+ bodyHTML = lpt . getElementsByClassName ( "lpt-tableBlock" ) [ 0 ]
23
+ . getElementsByTagName ( "table" ) [ 0 ] . innerHTML ,
24
+ topHTML = lpt . getElementsByClassName ( "lpt-topHeader" ) [ 0 ]
25
+ . getElementsByTagName ( "table" ) [ 0 ] . innerHTML . replace ( / < t r > / , "<tr><th colspan='2'></th>" ) ,
26
+ leftHTML = lpt . getElementsByClassName ( "lpt-leftHeader" ) [ 0 ]
27
+ . getElementsByTagName ( "thead" ) [ 0 ] . innerHTML ,
28
+ trs = leftHTML . match ( "<tr>(.*)</tr>" ) [ 1 ] . split ( "</tr><tr>" ) ,
29
+ i = 0 ;
30
+
31
+ bodyHTML = bodyHTML . replace ( / < t r > / g, function ( ) {
32
+ return "<tr>" + trs [ i ++ ] ;
33
+ } ) ;
34
+
35
+ console . log ( topHTML + bodyHTML ) ;
36
+
37
+ this . exportTableHTML ( topHTML + bodyHTML , "test" ) ;
38
+
39
+ } ;
0 commit comments