Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Setting HSSFColor via RGB Does Not Work #25

Closed
Grandizer opened this issue Sep 8, 2017 · 4 comments
Closed

Setting HSSFColor via RGB Does Not Work #25

Grandizer opened this issue Sep 8, 2017 · 4 comments

Comments

@Grandizer
Copy link

Hello,

With the following code, the 1st way of creating a color works but the two commented out ones do not. Am I doing something wrong?

IWorkbook workbook = new XSSFWorkbook();

var UniversalStyle = workbook.CreateCellStyle();
UniversalStyle.FillForegroundColor = HSSFColor.Automatic.Index;
UniversalStyle.FillPattern = FillPattern.NoFill;

UniversalFont = workbook.CreateFont();
UniversalFont.Color = HSSFColor.Blue.Index;
// UniversalFont.Color = new XSSFColor(new byte[3] { 65, 124, 153 }).Indexed;
// UniversalFont.Color = new XSSFColor(System.DrawingCore.Color.FromArgb(65, 124, 153)).Indexed;
UniversalStyle.SetFont(UniversalFont);

IRow row = sheet1.CreateRow(RowIndex++);
ICell test = row.CreateCell(ColIndex++);
test.CellStyle = UniversalStyle;
test.SetCellType(CellType.String);
test.SetCellValue("This should be Blue-ish");

@yang-xiaodong
Copy link
Member

yang-xiaodong commented Sep 9, 2017

This is not a bug.

Each Microsoft Excel workbook has a palette of 56 colors that you can apply to cells, fonts, gridlines, graphic objects, and fills and lines in a chart.

see:
http://dmcritchie.mvps.org/excel/colors.htm
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/colorindex-property

In NPOI, the color index are from 0x8 to 0x40

image

@Grandizer
Copy link
Author

Understood. Thank you.

@diogoan
Copy link

diogoan commented Sep 6, 2019

Sorry for asking this here (I don't know if this is the proper place to ask questions), but there's no way to set a custom RGB color into an XSSFColor object? We are restricted to the 56 colors of default Excel palette?

@esreeves
Copy link

This seems to be more of a limitation of the library. You are able to set custom colors within excel why are you not able to do it with this library. Maybe this should be reopened and tagged as a feature request?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants