i am able to export excel but not cell color in excel.
i am able to export excel but not cell color in excel.
honeynokia
Posts: 3Questions: 1Answers: 0
buttons: [{
extend: 'excelHtml5',
text: "",
tag: 'span',
className: 'bi bi-filetype-exe',
title: 'market period',
titleAttr: 'Export all visible requests in Excel',
customize: function ( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
// Map used to map column index to Excel index
var excelMap = {
0: 'A',
1: 'B',
2: 'C',
3: 'D',
4: 'E',
5: 'F',
6: 'G',
7: 'H',
8: 'I',
9: 'J',
10: 'K',
11: 'L',
12: 'M',
};
var count = 0;
var skippedHeader = false;
$('row', sheet).each( function () {
var row = this;
if (skippedHeader) {
// var colour = $('tbody tr:eq('+parseInt(count)+') td:eq(2)').css('background-color');
// Output first row
if (count === 0) {
console.log(this);
}
for (td=0; td<13; td++) {
// Output cell contents for first row
if (count === 0) {
$('row:first c', sheet).attr('s', '42');
console.log($('c[r^="' + excelMap[td] + '"]', row).text());
}
var colour = $(otable.cell(':eq('+count+')',td).node()).css('background-color');
if (colour === 'rgb(255, 0, 0)' || colour === 'red') {
$('c[r^="' + excelMap[td] + '"]', row).attr( 's', '35' );
}
else if (colour === 'rgb(0, 128, 0)' || colour === 'green') {
$('c[r^="' + excelMap[td] + '"]', row).attr( 's', '40' );
}
}
count++;
}
else {
skippedHeader = true;
}
});
}
}]
Answers
if (colour === 'rgb(255, 0, 0)' || colour === 'red') {
$('c[r^="' + excelMap[td] + '"]', row).attr( 's', '35' );
}
else if (colour === 'rgb(0, 128, 0)' || colour === 'green') {
$('c[r^="' + excelMap[td] + '"]', row).attr( 's', '40' );
}
why these lines are not working
Possibly the if statements are never true so the styling is never applied. Without being able to debug the code with your data and table config it will be hard to say what the problem might be.
Have you performed debugging of the if statements to see if
colour
matches any of the conditions?If you still need help please post a link to your page or a test case replicating the issues so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Its working with Datatable but not with datatable
Um - I'm not sure what the difference is? If you are talking about Javascript variables, then neither are shown in your code above.
I think Kevin was quite clear in his request for a test case. Please link to a page showing the issue if we are to be able to offer any help.
Allan