Excel export with background
Excel export with background
tianchao
Posts: 7Questions: 4Answers: 0
1,隔行变色:
$(document).ready(function() {
$('#example').DataTable({
dom: 'Bfrtip',
buttons: [{
extend: 'excelHtml5',
customize: function ( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row', sheet).each(function(x) {
if(x %2 == 0){
if ($('c[r=A'+x+'] t', sheet)) {
$('row:nth-child('+x+') c', sheet).attr('s', '30');
}
}
});
}
}]
});
});
2,某一个单元格包含特定字符串
$(document).ready(function() {
$('#example').DataTable({
dom: 'Bfrtip',
buttons: [{
extend: 'excelHtml5',
customize: function ( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row', sheet).each(function(x) {
if ($('c[r=C'+x+'] t', sheet).text().indexOf('Edin') !=-1) {
$('row:nth-child('+x+') c', sheet).attr('s', '10');
}
});
}
}]
});
});
3,特定行变色
$(document).ready(function() {
$('#example').DataTable({
dom: 'Bfrtip',
buttons: [{
extend: 'excelHtml5',
customize: function ( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row', sheet).each(function(x) {
if (x ==1 || x==2 || x==3) {
$('row:nth-child('+x+') c', sheet).attr('s', '10');
}
else if(x ==7 || x==8 || x==9){
$('row:nth-child('+x+') c', sheet).attr('s', '39');
}
});
}
}]
});
});
Replies
Does this relate to your other thread? And does my reply there resolve your issue?
Colin
this is my answer, I solved this problem,thx Colin