6 Replies Latest reply on Sep 16, 2010 5:43 AM by jennifer lopez

    Not able to change the color of cell text in Seam Excel

    Lavanya k Newbie

      Hi,


      I had created a excel using seam excel support. This is an awesome feature that seam framework provide.


      My excel sheet is creted as desired except I am not able to change the color of any text in


      <e:cell> 



      conditionally. Below is the code snippet that I am using to make it work -



      <e:cell value="#{employee.name}" style="xls-font-size: 8; xls-font-color=#{employee.resigned ? 'black' : 'red' }"/>





      Please suggest if I am wrong somewhere in the usage.


      Thanks.










        • 1. Re: Not able to change the color of cell text in Seam Excel
          Herberson Silva Newbie

          Try create a transient method in Emplyee class that return the color.

          • 2. Re: Not able to change the color of cell text in Seam Excel
            Lavanya k Newbie

            Hi Herberson,


            Thank you for your reply.


            I tried defining a color property and its corresponding getter/setter method in Employee class and tried setting the color, but it did not worked out as desired.


            But If I hard code any color value it works correctly as below-



            <e:cell value="#{employee.name}" style="xls-font-size: 8; xls-font-color='red'"/>



            But I want to set text color conditionally.


            Also, what do you actually mean by 'transient method'?


            Thanks.

            • 3. Re: Not able to change the color of cell text in Seam Excel
              Herberson Silva Newbie

              Transient method is that one marked with @Transient annotation, by doing so you are saying to JPA that the values returned by a method or stored in a attribute isn't persisted in database.


              Knowing that, your Employee class will look like this:


              /* your imports */
              import import javax.persistence.Transient;
              
              @Name("employee")
              @Entity
              public class Employee implements Serializable {
                  /* your implementation */
              
                  @Transient
                  public String getColor() {
                      if (this.resigned) {
                          return "black";
                      } else {
                          return "red";
                      }
                  }
                  
                  @Transient
                  public void setColor() {
                      //nothing to do
                  }
              
                  /* your implementation */
              }
              





              And your <e:cell \> tag will look like this:


              <e:cell value="#{employee.name}" style="xls-font-size: 8; xls-font-color='#{employee.color}'"/>



              It may seem awkward but that is the way I found to address issues like yours in my code.


              Herberson




              • 4. Re: Not able to change the color of cell text in Seam Excel
                Lavanya k Newbie

                Herberson,


                My employee class is not an entity bean, so I think that @Transient is not required for this case.


                I tried the approach that you had suggested, but it is not working for me. Did this practically worked for you?


                Thanks.

                • 5. Re: Not able to change the color of cell text in Seam Excel
                  jennifer lopez Newbie
                  You can change the color of a cell in excel by giving

                  <e:cell value="Hello world" row="7" column="0"
                                      style=" xls-background-color:  gray_25;"/>

                  also you can use the following colors, Please try it.

                  unknown, black, white, default_background1, default_background,
                  palette_black, red, bright_green, blue, yellow, pink, turquoise,
                  dark_red, green, dark_blue, dark_yellow, violet, teal, grey_25_percent,
                  grey_50_percent, periwinkle, plum2, ivory, light_turquoise2, dark_purple,
                  coral, ocean_blue, ice_blue, dark_blue2, pink2, yellow2, turqoise2, violet2,
                  dark_red2, teal2, blue2, sky_blue, light_turquoise, light_green,
                  very_light_yellow, pale_blue, rose, lavender, tan, light_blue, aqua,
                  lime, gold, light_orange, orange, blue_grey, grey_40_percent, dark_teal,
                  sea_green, dark_green, olive_green, brown, plum, indigo, grey_80_percent,
                  automatic, gray_80, gray_50, gray_25]


                  • 6. Re: Not able to change the color of cell text in Seam Excel
                    jennifer lopez Newbie
                    <e:cell value="Hello world" row="7" column="0"
                                              style="xls-font: coral bold 9 Arial; xls-background-color:  gray_25; xls-font-size: 16;xls-border: thin black"/>