We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to set theme color

Hi,

How to set theme color and tint color on cell .

If theme color index is 8 and tint color value is 0.00003564789.

IRange  oRange;
IWorkBook oworkbook;

oRange.CellStyle.Interior.Gradient.ForeColorObject.SetTheme(8,0.00003564789, oworkbook);

This function is through Exception.

Thanks
Sharad Kumar



7 Replies

AV Abirami Varadharajan Syncfusion Team September 28, 2016 02:12 PM UTC

Hi Sharad, 
  
Thank you for contacting Syncfusion support. 
  
We recommend to set the FillPattern to Gradient before setting theme color to each cell of a range. Kindly refer below code snippet to achieve this. 
  
Code Example: 
            IRange oRange=worksheet.Range["A1:A10"]; 
            Range.CellStyle.Interior.FillPattern = ExcelPattern.Gradient; 
            for (int i = 0; i < oRange.Cells.Length;i++) 
            { 
                oRange.Cells[i].CellStyle.Interior.Gradient.ForeColorObject.SetTheme(8, workbook, 0.00003564789); 
            } 
 Kindly try and let us know if this helps.  
  
Regards, 
Abirami. 



SK Sharad Kumar September 29, 2016 03:39 AM UTC

thanks for replay.

If pattern type is solid .
Range.CellStyle.Interior.FillPattern = ExcelPattern.Solid;

this function through Exception.

I have attach excel file. cell B7,B8,B9,B10 have theme color and tint color.

Cell B7 value is ->
<fi   <       fill>
    -<patternFill patternType="solid">
        <fgColor theme="9" tint="0.39997558519241921"/>
        <bgColor indexed="64"/>
    </patternFill>
</fill>
Kindly provide a code snippet which recover color cell value.


Thanks
Sharad kumar


Attachment: 10colorcelltest_bbec8a0c.rar


SK Sharad Kumar September 29, 2016 03:45 AM UTC

thanks for replay.

If pattern type is solid .
Range.CellStyle.Interior.FillPattern = ExcelPattern.Solid;

this function through Exception.

I have attach excel file. cell B7,B8,B9,B10 have theme color and tint color.

Cell B7 value is ->
        patternType="solid"
        fgColor theme="9" tint="0.39997558519241921"                     //  foreground color
        bgColor indexed="64"                                                          //  background color
Cell B8 value is ->
       patternType="solid"
       fgColor theme="7" tint="0..59999389629810485"
       bgColor indexed="64"

Kindly provide code snippet which recover cell color value.

Thanks
Sharad Kumar

Attachment: 10colorcelltest_74759db6.rar


AV Abirami Varadharajan Syncfusion Team September 30, 2016 12:33 PM UTC

Hi Sharad, 
  
When you try to access the forecolorobject of gradient which has solid Fill pattern will throw an exception. 
  
So, we recommend you to set the theme and tint color of the cell by accessing the Wrapped property of the InteriorWrapper class. Kindly refer the below code example to set the theme and tint color to range B7, B8, B9 and B10. 
  
Code Example: 
worksheet.Range["B7"].CellStyle.Interior.FillPattern = ExcelPattern.Solid; 
(worksheet.Range["B7"].CellStyle.Interior as InteriorWrapper).Wrapped.ColorObject.SetTheme(9, workbook, 0.39997558519241921); 
worksheet.Range["B8"].CellStyle.Interior.FillPattern = ExcelPattern.Solid; 
(worksheet.Range["B8"].CellStyle.Interior as InteriorWrapper).Wrapped.ColorObject.SetTheme(7, workbook, 0.59999389629810485); 
worksheet.Range["B9"].CellStyle.Interior.FillPattern = ExcelPattern.Solid; 
(worksheet.Range["B9"].CellStyle.Interior as InteriorWrapper).Wrapped.ColorObject.SetTheme(0, workbook, -0.14999847407452621); 
worksheet.Range["B10"].CellStyle.Interior.FillPattern = ExcelPattern.Solid; 
(worksheet.Range["B10"].CellStyle.Interior as InteriorWrapper).Wrapped.ColorObject.SetTheme(8, workbook, 0.59999389629810485); 
  
Kindly try this approach and let us know if this help at your end. 
  
Regards, 
Abirami. 



SK Sharad Kumar October 1, 2016 04:51 AM UTC

Thanks for reply.

I am not access to InteriorWrapper class .

       error ->   The type or namespace name "
InteriorWrapper" could not found .


Thanks
sharad kumar





AV Abirami Varadharajan Syncfusion Team October 3, 2016 10:16 AM UTC

Hi Sharad, 
 
We request you to include below namespace to your sample to access InteriorWrapper class. 
 
Code Example: 
using Syncfusion.XlsIO.Implementation; 
 
Kindly try and let us know if this resolves error at your end. 
 
Regards, 
Abirami. 



SK Sharad Kumar October 3, 2016 10:43 AM UTC



Thanks Abirami.



Loader.
Up arrow icon