Background color for excel cell on Export

2 posts, 0 answers
  1. Carlos
    Carlos avatar
    1 posts
    Member since:
    Aug 2015

    Posted 27 Aug 2015 Link to this post

    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!

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2288 posts

    Posted 27 Aug 2015 Link to this post

    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
Back to Top