How to determine a color for the background

5 Answers 21 Views
SpreadStreamProcessing
Herb
Top achievements
Rank 1
Herb asked on 31 May 2021, 01:43 PM

I'm working with SpreadStreamProcessing. I want to set the background color for each of the cells in a specific row.

Created an excel mockup and like the "Blue, Accent 5, Lighter 40%". How can I find the RGB code for this?

Also is there somewhere one can find a color converter to RGB or visa versa?

5 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 07 Jun 2021, 07:07 AM

Hello Herb,

I am aware that you are using SpreadStreamProcessing. However, I cannot suggest a solution to it and this is why I have logged a feature request for this. Please note that the color is not stored in the file as an RGB value. The suggestion in my previous post gets the color from the theme and each theme is stored in our library. The themes are not stored in the file as well. 

Let me know if I can assist you further.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Herb
Top achievements
Rank 1
commented on 07 Jun 2021, 02:31 PM

Ok. Will monitor your link to new request.
0
Dimitar
Telerik team
answered on 01 Jun 2021, 10:56 AM

Hello Herb,

Is this a custom or a predefined style? If it is a predefined style you can get it from styles collection by name. For example: 

var style1 = workbook.CellStyles.GetByName("20% - Accent6");

You can view all available style names with the following code:

foreach (var item in workbook.CellStyles)
{
    Console.WriteLine(item.Name);
}

If your template document contains custom styles, you need to manually create them and add them to the styles collection:

SpreadCellStyle style = workbook.CellStyles.Add("MyStyle");
style.Underline = SpreadUnderlineType.DoubleAccounting;
style.VerticalAlignment = SpreadVerticalAlignment.Top;

Then you can use the style with the following code:

cell.SetFormat(new SpreadCellFormat()
{
    CellStyle = style1,
    HorizontalAlignment = SpreadHorizontalAlignment.Center,
    VerticalAlignment = SpreadVerticalAlignment.Center
});

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Herb
Top achievements
Rank 1
commented on 02 Jun 2021, 02:46 PM

Hello Dimitar, Your answer "var color = new SpreadThemableColor(SpreadThemeColorType.Accent5, SpreadColorShadeType.Shade3);" was what I was looking for. But your "foreach (var item in workbook.CellStyles)" did not answer the question about how to find color to RGB.
0
Dimitar
Telerik team
answered on 01 Jun 2021, 11:23 AM

Hello Herb, 

I forgot to mention that there is one more way to set this color manually. For example, you can use the following code to set the fill: 

var color = new SpreadThemableColor(SpreadThemeColorType.Accent5, SpreadColorShadeType.Shade3);
cell.SetFormat(new SpreadCellFormat()
{
    //CellStyle = style1,
    Fill = SpreadPatternFill.CreateSolidFill(color),
    HorizontalAlignment = SpreadHorizontalAlignment.Center,
    VerticalAlignment = SpreadVerticalAlignment.Center
});

Let me know if I can assist you further.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Dimitar
Telerik team
answered on 03 Jun 2021, 12:30 PM

Hi Herb,

I have further investigated this and currently, it is not possible to get the color. The color comes from the theme and is not stored in the style. I have logged a feature request that will allow you to achieve this with our API. You can track its progress, subscribe to status changes, and add your comment to it here. I have updated your Telerik points as well. 

Let me know if I can assist you further.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Herb
Top achievements
Rank 1
commented on 03 Jun 2021, 01:20 PM

So you know of no color convert to RGB that can be used to find a color I would like to use?
0
Dimitar
Telerik team
answered on 04 Jun 2021, 08:51 AM

Hi Herb,

There is a way with the SpreadProcessing (not SpreadStreamProcessing) if this is suitable for you. For example, you can use the following approaches to get the color from the default theme (or other themes by specifying the name):

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    Workbook workbook = new Workbook();
    ThemableColor themableColor = new ThemableColor(ThemeColorType.Accent5, ColorShadeType.Shade3);
    Color actualColor = themableColor.GetActualValue(workbook.Theme);

    var schemes = PredefinedThemeSchemes.ColorSchemes;
    var colorScheme = schemes.Where(x => x.Name == "Office").FirstOrDefault();
    ThemeFontScheme fontScheme = new ThemeFontScheme(
    "Mine",
    "Times New Roman",  // latinMajor 
    "Arial");           // latinMinor 
    var theme = new DocumentTheme("custom", colorScheme, fontScheme);

    Color actualColor2 = themableColor.GetActualValue(theme);
}

Let me know if I can assist you further.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Herb
Top achievements
Rank 1
commented on 04 Jun 2021, 01:33 PM

As I'm using Telerik.Documents.SpreadsheetStreaming reference in my major project I need another method to get color RGB value or find how to set it. Using Telerik.Documents.SpreadsheetStreaming, can I set the color in an Excel file then read what that RGB value is? So I can added that RGB code in my project?
Tags
SpreadStreamProcessing
Asked by
Herb
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or