diff --git a/ClosedXML/Excel/Style/Colors/XLColor_Public.cs b/ClosedXML/Excel/Style/Colors/XLColor_Public.cs index 7dcd8e4..9686902 100644 --- a/ClosedXML/Excel/Style/Colors/XLColor_Public.cs +++ b/ClosedXML/Excel/Style/Colors/XLColor_Public.cs @@ -28,6 +28,14 @@ public partial class XLColor : IEquatable { + /// + /// Usually indexed colors are limited to max 63 + /// Index 81 is some special case. + /// Some people claim it's the index for tooltip color. + /// We'll return normal black when index 81 is found. + /// + private const Int32 TOOLTIPCOLORINDEX = 81; + private readonly XLColorType _colorType; private int _hashCode; private readonly Int32 _indexed; @@ -50,7 +58,10 @@ throw new Exception("Cannot convert theme color to Color."); if (_colorType == XLColorType.Indexed) - return IndexedColors[_indexed].Color; + if (_indexed == TOOLTIPCOLORINDEX) + return Color.FromArgb(255, Color.Black); + else + return IndexedColors[_indexed].Color; return _color; } @@ -170,4 +181,4 @@ return !(left == right); } } -} \ No newline at end of file +} diff --git a/ClosedXML_Tests/ClosedXML_Tests.csproj b/ClosedXML_Tests/ClosedXML_Tests.csproj index 1ad18c5..da93d14 100644 --- a/ClosedXML_Tests/ClosedXML_Tests.csproj +++ b/ClosedXML_Tests/ClosedXML_Tests.csproj @@ -77,6 +77,7 @@ + @@ -256,6 +257,7 @@ + diff --git a/ClosedXML_Tests/Excel/Comments/CommentsTests.cs b/ClosedXML_Tests/Excel/Comments/CommentsTests.cs new file mode 100644 index 0000000..1ba4e76 --- /dev/null +++ b/ClosedXML_Tests/Excel/Comments/CommentsTests.cs @@ -0,0 +1,33 @@ +using ClosedXML.Excel; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClosedXML_Tests.Excel.Comments +{ + public class CommentsTests + { + [Test] + public void CanGetColorFromIndex81() + { + using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"Misc\CommentsWithIndexedColor81.xlsx"))) + using (var wb = new XLWorkbook(stream)) + { + var ws = wb.Worksheets.First(); + var c = ws.FirstCellUsed(); + + var xlColor = c.Comment.Style.ColorsAndLines.LineColor; + Assert.AreEqual(XLColorType.Indexed, xlColor.ColorType); + Assert.AreEqual(81, xlColor.Indexed); + + + var color = xlColor.Color.ToHex(); + Assert.AreEqual("FF000000", color); + } + + } + } +} diff --git a/ClosedXML_Tests/Resource/Misc/CommentsWithIndexedColor81.xlsx b/ClosedXML_Tests/Resource/Misc/CommentsWithIndexedColor81.xlsx new file mode 100644 index 0000000..715c073 --- /dev/null +++ b/ClosedXML_Tests/Resource/Misc/CommentsWithIndexedColor81.xlsx Binary files differ