diff --git a/ClosedXML/Excel/Style/Colors/XLColor_Public.cs b/ClosedXML/Excel/Style/Colors/XLColor_Public.cs index 8213608..6feefe3 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 18a7ee1..1542b4d 100644 --- a/ClosedXML_Tests/ClosedXML_Tests.csproj +++ b/ClosedXML_Tests/ClosedXML_Tests.csproj @@ -1,295 +1,297 @@ - - - - Debug - AnyCPU - - - 2.0 - {09B066ED-E4A7-4545-A1A4-FF03DD524BDF} - Library - Properties - ClosedXML_Tests - ClosedXML_Tests - v4.5.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE;$(AppVeyor) - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE;$(AppVeyor) - prompt - 4 - false - - - true - - - ClosedXML.snk - - - - ..\packages\DocumentFormat.OpenXml.2.7.2\lib\net40\DocumentFormat.OpenXml.dll - True - - - - ..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll - True - - - - - 3.5 - - - - - - - - - - - Properties\AssemblyVersionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {BD5E6BFE-E837-4A35-BCA9-39667D873A20} - ClosedXML - - - {03A518D0-1CB7-488E-861C-C4E782B27A46} - ClosedXML_Examples - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - .editorconfig - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + + + 2.0 + {09B066ED-E4A7-4545-A1A4-FF03DD524BDF} + Library + Properties + ClosedXML_Tests + ClosedXML_Tests + v4.5.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE;$(AppVeyor) + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE;$(AppVeyor) + prompt + 4 + false + + + true + + + ClosedXML.snk + + + + ..\packages\DocumentFormat.OpenXml.2.7.2\lib\net40\DocumentFormat.OpenXml.dll + True + + + + ..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll + True + + + + + 3.5 + + + + + + + + + + + Properties\AssemblyVersionInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {BD5E6BFE-E837-4A35-BCA9-39667D873A20} + ClosedXML + + + {03A518D0-1CB7-488E-861C-C4E782B27A46} + ClosedXML_Examples + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .editorconfig + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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