테이블을 엑셀로 내보내기(Table To Excel)
활용예제
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko">
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
<head>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="jquery.battatech.excelexport.js"></script>
</head>
<body>
<div>
<table id="myTable">
<thead>
<tr>
<th>num</th>
<th>Color</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Red</td>
<td>Chanchan</td>
</tr>
<tr>
<td>2</td>
<td>Blue</td>
<td>Marco</td>
</tr>
<tr>
<td>3</td>
<td>Green</td>
<td>Gone</td>
</tr>
<tr>
<td>4</td>
<td>Black</td>
<td>Teach.d</td>
</tr>
<tr>
<td>5</td>
<td>White</td>
<td>Mock</td>
</tr>
</tbody>
</table>
</div>
<div>
<a id="export" href="" download="" target="_blank">Table To Excel</button>
</div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function () {
$("#export").click(function () {
var uri = $("#myTable").battatech_excelexport({
containerid: "myTable",
// 테이블 아이디
datatype: 'table',
// 데이터 타입 설정
returnUri: true
// URI return 여부
});
$(this).attr('download', 'sample.xls').attr('href', uri);
// 파일이름, URI 설정
});
});
</script>
JQuery Library 다운로드
- https://github.com/battatech/battatech_excelexport
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko">
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
<head>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="jquery.battatech.excelexport.js"></script>
</head>
<body>
<div>
<table id="myTable">
<thead>
<tr>
<th>num</th>
<th>Color</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Red</td>
<td>Chanchan</td>
</tr>
<tr>
<td>2</td>
<td>Blue</td>
<td>Marco</td>
</tr>
<tr>
<td>3</td>
<td>Green</td>
<td>Gone</td>
</tr>
<tr>
<td>4</td>
<td>Black</td>
<td>Teach.d</td>
</tr>
<tr>
<td>5</td>
<td>White</td>
<td>Mock</td>
</tr>
</tbody>
</table>
</div>
<div>
<a id="export" href="" download="" target="_blank">Table To Excel</button>
</div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function () {
$("#export").click(function () {
var uri = $("#myTable").battatech_excelexport({
containerid: "myTable",
// 테이블 아이디
datatype: 'table',
// 데이터 타입 설정
returnUri: true
// URI return 여부
});
$(this).attr('download', 'sample.xls').attr('href', uri);
// 파일이름, URI 설정
});
});
</script>
- https://github.com/battatech/battatech_excelexport
안녕하세요~ 깃헙에 "jquery.battatech.excelexport.js" 파일이 없는데요~
답글삭제안녕하세요~ 소스 잘봣습니다 궁금한점이 하나 있는데 내보내고 엑셀로 파일열때 암호를 걸고 싶은데 방법이 혹시 있을까요?
답글삭제