본문 바로가기

엉터리 개발 이야기/개인프로젝트

Datatables excel export 예제(cell style 설정)

반응형
"dom": 'Bfrtip',
"buttons": [{
extend: 'excelHtml5',
customize: function (xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
var sSh = xlsx.xl['styles.xml'];
var lastXfIndex = $('cellXfs xf', sSh).length - 1;
// Loop over the cells in column `C`

var s4 = '<fill xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><patternFill xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" patternType="solid"><fgColor rgb="ff0000"/><bgColor rgb="ff0000"/></patternFill></fill>';
sSh.childNodes[0].childNodes[2].innerHTML += s4;

var s1 = '<xf numFmtId="300" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>';
var s2 = '<xf numFmtId="0" fontId="2" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">' +
'<alignment horizontal="center"/></xf>';
var s3 = '<xf numFmtId="0" fontId="0" fillId="6" borderId="0" applyFont="0" applyFill="1" applyBorder="0" xfId="0" applyAlignment="0" />';
//sSh.childNodes[0].childNodes[0].innerHTML += n1;
sSh.childNodes[0].childNodes[5].innerHTML += s1 + s2 + s3;

var fourDecPlaces = lastXfIndex + 3;
var greyBoldCentered = lastXfIndex + 2;


$('row:not(:first, :nth-child(2))', sheet).each(function () {
if( parseInt($('c[r^="J"]', this).text()) >= 2 ) {
$('c', this).each(function() {
$(this).attr('s', fourDecPlaces);
});
}
});
}
}]


Cell Style 설정

반응형

'엉터리 개발 이야기 > 개인프로젝트' 카테고리의 다른 글

제휴사 컬럼 정보  (0) 2018.12.05
[datatables] column background color  (0) 2018.12.05
Sequelize Association  (0) 2018.12.03
MariaDB time zone 설정확인...  (0) 2018.12.02
datatables 참고  (0) 2018.11.29