<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>이름</th>
<th>직위</th>
<th>지역</th>
</tr>
</thead>
<tbody>
<tr>
<td>홍길동</td>
<td>부장</td>
<td>인천</td>
</tr>
<tr>
<td>김원희</td>
<td>과장</td>
<td>서울</td>
</tr>
<tr>
<td>김길자</td>
<td>대리</td>
<td>대전</td>
</tr>
<tr>
<td>김길동</td>
<td>대리</td>
<td>인천</td>
</tr>
</tbody>
</table>
<link rel="stylesheet" href="/post_inc/datatables/jquery.dataTables.min.css">
<link rel="stylesheet" href="/post_inc/datatables/buttons.dataTables.min.css">
<script src="/post_inc/datatables/jquery.dataTables.1.10.20.min.js"></script>
<script src="/post_inc/datatables/dataTables.buttons.min.js"></script>
<script src="/post_inc/datatables/jszip.min.js"></script>
<script src="/post_inc/datatables/buttons.html5.min.js"></script>
<script type="text/javascript">
$(function(){
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
{
extend: 'excel'
,text: '엑셀출력'
,filename: '엑셀파일명'
,title: '엑셀파일 안에 쓰일 제목'
// customize 옵션으로 excel를 수정하는게가능하다.
,customize: function(xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row', sheet).each( function (k,v) {
// A열중에서 text가 '김원희'일 경우 style 20이, 해당 열의 B,C에 적용됨
if ( $('c[r^="A"]', this).text() == '김원희' ) {
$('c[r^="B"], c[r^="C"]', this).attr( 's', '20' );
}
});
$('row c[r^="C"]', sheet).each( function () {
// C열 중에서 인천은 style 39 를 적용
if ( $('is t', this).text() == '인천' ) {
$(this).attr( 's', '39' );
}
});
// A열의 1번째행의 제목을 수정하는 부분
$('c[r=A1] t', sheet).text( '제목 바꿔 치기' );
// A열의 2행, B열의 2행, C열의 2행을 수정하는 방법
$('c[r=A2]', sheet).attr( 's', '17' );
$('c[r=B2]', sheet).attr( 's', '7' );
$('c[r=C2]', sheet).attr( 's', '36' );
}
},
]
});
})
</script>
이름 | 직위 | 지역 |
---|---|---|
홍길동 | 부장 | 인천 |
김원희 | 과장 | 서울 |
김길자 | 대리 | 대전 |
김길동 | 대리 | 인천 |
Styles:
0
- Normal text1
- White text2
- Bold3
- Italic4
- Underline5
- Normal text, grey background6
- White text, grey background7
- Bold, grey background8
- Italic, grey background9
- Underline, grey background10
- Normal text, red background11
- White text, red background12
- Bold, red background13
- Italic, red background14
- Underline, red background15
- Normal text, green background16
- White text, green background17
- Bold, green background18
- Italic, green background19
- Underline, green background20
- Normal text, blue background21
- White text, blue background22
- Bold, blue background23
- Italic, blue background24
- Underline, blue background25
- Normal text, thin black border26
- White text, thin black border27
- Bold, thin black border28
- Italic, thin black border29
- Underline, thin black border30
- Normal text, grey background, thin black border31
- White text, grey background, thin black border32
- Bold, grey background, thin black border33
- Italic, grey background, thin black border34
- Underline, grey background, thin black border35
- Normal text, red background, thin black border36
- White text, red background, thin black border37
- Bold, red background, thin black border38
- Italic, red background, thin black border39
- Underline, red background, thin black border40
- Normal text, green background, thin black border41
- White text, green background, thin black border42
- Bold, green background, thin black border43
- Italic, green background, thin black border44
- Underline, green background, thin black border45
- Normal text, blue background, thin black border46
- White text, blue background, thin black border47
- Bold, blue background, thin black border48
- Italic, blue background, thin black border49
- Underline, blue background, thin black border50
- Left aligned text (since 1.2.2)51
- Centred text (since 1.2.2)52
- Right aligned text (since 1.2.2)53
- Justified text (since 1.2.2)54
- Text rotated 90° (since 1.2.2)55
- Wrapped text (since 1.2.2)56
- Percentage integer value (automatically detected and used by buttons - since 1.2.3)57
- Dollar currency values (automatically detected and used by buttons - since 1.2.3)58
- Pound currency values (automatically detected and used by buttons - since 1.2.3)59
- Euro currency values (automatically detected and used by buttons - since 1.2.3)60
- Percentage with 1 decimal place (automatically detected and used by buttons - since 1.2.3)61
- Negative numbers indicated by brackets (automatically detected and used by buttons - since 1.2.3)62
- Negative numbers indicated by brackets - 2 decimal places (automatically detected and used by buttons - since 1.2.3)63
- Numbers with thousand separators (automatically detected and used by buttons - since 1.2.3)64
- Numbers with thousand separators - 2 decimal places (automatically detected and used by buttons - since 1.2.3)65
- Numbers without thousand separators (automatically detected and used by buttons - since 1.2.4)66
- Numbers without thousand separators - 2 decimal places (automatically detected and used by buttons - since 1.2.4)Notes: