HTML TableÀ» ¿¢¼¿·Î ³»º¸³»±â : Export to excel sheet on client side
HTML TableÀ» ¿¢¼¿·Î ÀúÀåÇϱâ : Export to excel sheet on client side
1. <A> ¿¤¸®¸ÕÆ®ÀÇ download ¼Ó¼ºÀ» ÀÌ¿ëÇÏ¿© ÀúÀåÇϱâ.
2. <A> ¿¤¸®¸ÕÆ®ÀÇ download¼Ó¼º°ú URL¿¡ dataŸÀÔÀ» »ç¿ëÇϱâ, ¿¢¼¿ ÆÄÀÏ À̸§ ÁöÁ¤Çϱâ.
3. jquery.battatech.excelexport ¶óÀ̺귯¸®¸¦ »ç¿ëÇϱâ.
4. jquery.battatech.excelexport ¶óÀ̺귯¸®¸¦ »ç¿ëÇÏ¿© ÆÄÀÏÀ̸§ ÁöÁ¤Çϱâ.
5. jquery.battatech.excelexport ¶óÀ̺귯¸®¸¦ »ç¿ëÇÏ¿© ÆÄÀÏÀ̸§ ÁöÁ¤Çϱâ2.
1. <A> ¿¤¸®¸ÕÆ®ÀÇ download ¼Ó¼ºÀ» ÀÌ¿ëÇÏ¿© ÀúÀåÇϱâ.
<!DOCTYPE html> <html lang="en"> <head> <meta name="Author" content="serpiko@hanmail.net" /> <meta name="description" content="http://serpiko.tistory.com" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <!--<meta name="viewport" content="width=device-width, initial-scale=1">--> <meta name="format-detection" content="telephone=no" /> <link rel="styleesheet" type="text/css" href="" /> <link rel="shortcut icon" href="" /> <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> <title>Document</title> <style> * { box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; } table{ width: 650px; text-align: center; border: 1px solid black; } </style> </head> <body> <div id="wrap"> <table id='tblExport'> <thead> <tr> <th>No</th> <th>Title</th> <th>Type</th> <th>Author</th> <th>URL</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>SAP : Study And Programming</td> <td>Blog</td> <td style='background-color: LightBlue;'>Serpiko</td> <td>http://serpiko.tistory.com/</td> </tr> <tr> <td>2</td> <td>Twitter</td> <td>SNS</td> <td>Obvious, LLC</td> <td>https://www.twitter.com/</td> </tr> <tr> <td>3</td> <td>Instagram</td> <td>SNS</td> <td>Kevin Systrom, Mike Krieger</td> <td>https://instagram.com/</td> </tr> </tbody> </table> <button id='btnExport' type='button'>Export</button> </div> <script> $(document).ready(function(){ $('#btnExport').click(function(){ var link = document.createElement('a'); link.download = "myFirstExample.xls"; link.href = 'data:,' + $('#tblExport').text(); link.click(); }); }); </script> </body> </html>
[ code ]
<!DOCTYPE html> <html lang="en"> <head> <meta name="Author" content="serpiko@hanmail.net" /> <meta name="description" content="http://serpiko.tistory.com" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <!--<meta name="viewport" content="width=device-width, initial-scale=1">--> <meta name="format-detection" content="telephone=no" /> <link rel="styleesheet" type="text/css" href="" /> <link rel="shortcut icon" href="" /> <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> <title>Document</title> <style> * { box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; } table{ width: 650px; text-align: center; border: 1px solid black; } </style> </head> <body> <div id="wrap"> <table id='tblExport'> <thead> <tr> <th>No</th> <th>Title</th> <th>Type</th> <th>Author</th> <th>URL</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>SAP : Study And Programming</td> <td>Blog</td> <td style='background-color: LightBlue;'>Serpiko</td> <td>http://serpiko.tistory.com/</td> </tr> <tr> <td>2</td> <td>Twitter</td> <td>SNS</td> <td>Obvious, LLC</td> <td>https://www.twitter.com/</td> </tr> <tr> <td>3</td> <td>Instagram</td> <td>SNS</td> <td>Kevin Systrom, Mike Krieger</td> <td>https://instagram.com/</td> </tr> </tbody> </table> <button id='btnExport' type='button'>Export</button> </div> <script> $(document).ready(function(){ function itoStr($num) { $num < 10 ? $num = '0'+$num : $num; return $num.toString(); } var btn = $('#btnExport'); var tbl = 'tblExport'; btn.click(function(e){ var dt = new Date(); var year = itoStr( dt.getFullYear() ); var month = itoStr( dt.getMonth() + 1 ); var day = itoStr( dt.getDate() ); var hour = itoStr( dt.getHours() ); var mins = itoStr( dt.getMinutes() ); var postfix = year + month + day + "_" + hour + mins; var fileName = "MyTable_"+ postfix + ".xls"; var a = document.createElement('a'); var data_type = 'data:application/vnd.ms-excel'; var table_div = document.getElementById( tbl ); var table_html = table_div.outerHTML.replace(/ /g, '%20'); a.href = data_type + ', ' + table_html; a.download = fileName; a.click(); e.preventDefault(); }); }); </script> </body> </html>
[ Á÷Á¢ º¸±â ¡é http://www.serpiko.meximas.com/JAVASCRIPT/excel/02_dataAndAuse.html ]
[°á°ú ȸé ]
À§¿¡ »ìÆ캸¾Ò´ø °Í °ú ´Ù¸£°Ô Å×À̺íÀÇ ÇüŸ¦ À¯ÁöÇϸç, ÆÄÀÏÀ̸§µµ ÁöÁ¤ÇØ ÁÙ ¼ö ÀÖ´Ù.
±×·¯³ª ÀÚ¼¼È÷ º¸¸é ¿¢¼¿ ƯÀ¯ÀÇ ±×¸®µå°¡ º¸ÀÌÁö ¾Ê´Â´Ù.
3. jquery.battatech.excelexport ¶óÀ̺귯¸®¸¦ »ç¿ëÇϱâ.
1,2 ÀÇ ´ÜÁ¡À» ¸ðµÎ ÇØ°áÇØ ÁÙ jquery.battatech.excelexport ¶óÀ̺귯¸®¸¦ ¼Ò°³ÇÑ´Ù.
´Ü¼øÈ÷ TABLE element¸»°íµµ XML, JSON µîÀ» °°ÀÌ Áö¿øÇÑ´Ù.
´Ù¿î·Îµå https://github.com/battatech/battatech_excelexport
jquery.techbytarun.excelexportjs.min.js
jquery.techbytarun.excelexportjs.js
°³¿ä : http://battatech.com/blog/how-to-export-to-excel-sheet-on-client-side
±âº»»ç¿ë¹ýÀº ´ÙÀ½°ú °°´Ù.
[ code ]
<!DOCTYPE html> <html lang="en"> <head> <meta name="Author" content="serpiko@hanmail.net" /> <meta name="description" content="http://serpiko.tistory.com" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <!--<meta name="viewport" content="width=device-width, initial-scale=1">--> <meta name="format-detection" content="telephone=no" /> <link rel="styleesheet" type="text/css" href="" /> <link rel="shortcut icon" href="" /> <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> <script type="text/javascript" src="js/jquery.battatech.excelexport.js"></script> <title>Document</title> <style> * { box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; } table{ width: 650px; text-align: center; border: 1px solid black; } </style> </head> <body> <div id="wrap"> <table id='tblExport'> <thead> <tr> <th>No</th> <th>Title</th> <th>Type</th> <th>Author</th> <th>URL</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>SAP : Study And Programming</td> <td>Blog</td> <td style='background-color: LightBlue;'>Serpiko</td> <td>http://serpiko.tistory.com/</td> </tr> <tr> <td>2</td> <td>Twitter</td> <td>SNS</td> <td>Obvious, LLC</td> <td>https://www.twitter.com/</td> </tr> <tr> <td>3</td> <td>Instagram</td> <td>SNS</td> <td>Kevin Systrom, Mike Krieger</td> <td>https://instagram.com/</td> </tr> </tbody> </table> <button id='btnExport' type='button'>Export</button> </div> <script type="text/javascript"> $(document).ready(function () { $("#btnExport").click(function () { $("#tblExport").excelexportjs({ containerid: "tblExport" , datatype: 'table' }); }); }); </script> </body> </html>
15 ~ 16 : ¿¢¼¿ ¶óÀ̺귯¸®¸¦ ºÒ·¯¿À±â Àü¿¡ ¹Ýµå½Ã Á¦ÀÌÄõ¸® ¿£ÁøÀÌ ¸ÕÀú È£ÃâµÇ¾î¾ß ÇÑ´Ù.
33 : Table¿¡ ID¸¦ ÁöÁ¤ÇØ ÁÖ°í
68 : Button ¿¡ ID¸¦ ÁöÁ¤ÇØ ÁØ´Ù.
73 : ¹öÆ°À» Ŭ¸¯Çϸé battatech_excelexport °´Ã¼¿¡ Á¢±ÙÇÏ¿© containerid´Â Å×À̺íÀ̸§, datatypeÀº table·Î ÁöÁ¤ÇØ ÁØ´Ù.
[ Á÷Á¢ º¸±â ¡é http://www.serpiko.meximas.com/JAVASCRIPT/excel/03_libTable.html ]
[ °á°ú È®ÀÎ ]
µåµð¾î ¸»²ûÇÏ°Ô ÀÌ»ó¾øÀÌ ´Ù Ãâ·ÂµÈ´Ù. ±×·¯³ª ÆÄÀϸíÀ» ÁöÁ¤ÇÏÁö ¾Ê¾Ò±â ¶§¹®¿¡ "´Ù¿î·Îµå.xls"·Î µÇ¾îÀÖ´Ù.
4. jquery.battatech.excelexport ¶óÀ̺귯¸®¸¦ »ç¿ëÇÏ¿© ÆÄÀÏÀ̸§ ÁöÁ¤Çϱâ.
jquery.battatech.excelexport ¶óÀ̺귯¸®¿¡¼ ÆÄÀϸíÀ» ÁöÁ¤ÇÏ´Â ¹æ¹ýÀº ´ÙÀ½°ú °°´Ù.
<!DOCTYPE html> <html lang="en"> <head> <meta name="Author" content="serpiko@hanmail.net" /> <meta name="description" content="http://serpiko.tistory.com" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <!--<meta name="viewport" content="width=device-width, initial-scale=1">--> <meta name="format-detection" content="telephone=no" /> <link rel="styleesheet" type="text/css" href="" /> <link rel="shortcut icon" href="" /> <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> <script type="text/javascript" src="js/jquery.battatech.excelexport.js"></script> <title>Document</title> <style> * { box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; } table{ width: 650px; text-align: center; border: 1px solid black; } </style> </head> <body> <div id="wrap"> <table id='tblExport'> <thead> <tr> <th>No</th> <th>Title</th> <th>Type</th> <th>Author</th> <th>URL</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>SAP : Study And Programming</td> <td>Blog</td> <td style='background-color: LightBlue;'>Serpiko</td> <td>http://serpiko.tistory.com/</td> </tr> <tr> <td>2</td> <td>Twitter</td> <td>SNS</td> <td>Obvious, LLC</td> <td>https://www.twitter.com/</td> </tr> <tr> <td>3</td> <td>Instagram</td> <td>SNS</td> <td>Kevin Systrom, Mike Krieger</td> <td>https://instagram.com/</td> </tr> </tbody> </table> <a id="btnExport" href="#" download="">Export</a> </div> <script type="text/javascript"> $(document).ready(function () { $("#btnExport").on('click', function () { var uri = $("#tblExport").excelexportjs({ containerid: "tblExport" , datatype: 'table' , returnUri: true }); $(this).attr('download', 'ExportToExcel.xls').attr('href', uri).attr('target', '_blank'); }); }); </script> </body> </html>
68 : À§¿¡¼ ½è´ø ¹æ½Ä°ú ´Ù¸£°Ô button element°¡ ¾Æ´Ï¶ó <a> element¸¦ »ç¿ëÇÑ´Ù.
77 : battatech_excelexport°´Ã¼ÀÇ ¸â¹öº¯¼öÀÎ returnUri°¡ ±âº»°ªÀÌ false·Î µÇ¾îÀִµ¥ true·Î ¹Ù²Ù¾îÁØ´Ù.
Ãâó: https://serpiko.tistory.com/581 [»ðSAP(Study And Programming) Áú ºí·Î±×. byÇãÁ¤Áø]