This is a migrated thread and some comments may be shown as answers.

Background color for excel cell on Export

1 Answer 446 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 27 Aug 2015, 09:53 AM

Hello there. So I have a gridwhich I can export to Excel.

When doing the export, I'm having two problems.

 This is my function.

 

function excelExport(e) {
       
            var sheet = e.workbook.sheets[0];
 
            for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) {
                var row = sheet.rows[rowIndex];
 
                for (var colIndex = 0; colIndex < (sheet.columns.length-2); colIndex++) {
  
                    if (row.cells[colIndex].value == "Weekend-") {row.cells[colIndex].format = "[Blue];";}
                    if (row.cells[colIndex].value == "Vacation Day-") { row.cells[colIndex].format = "[Yellow];"; }
                    if (row.cells[colIndex].value == "Holiday-") { row.cells[colIndex].format = "[Green];"; }
                    if (row.cells[colIndex].value == "Critical Task-") { row.cells[colIndex].format = "[Red];"; }
 
                }
            }
    }

 

Problem Num1: Is there any other way to choose other colors?... I only found very few so far like these: Green, Red, Blue and Yellow. If I try colors such as Orange, Light Blue, Purple, which are colors that I really need, it doesn't work. Instead of "[ColorName;"], is there another way.

 

Problem Num2: With this format I'm only formatting the text itself, but what I really want is, for example, whenever in the cell there is the "CriticalTask-" value, I want the cell background color to be red.

 

Thanks for the help!

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 27 Aug 2015, 10:54 AM

Hello Carlos,

Instead of setting the format of the cell, you should directly set the background property of the cell in this case.
E.g.

row.cells[colIndex].background = "#ff0000";

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Carlos
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or