diff --git a/ClosedXML/Excel/Caching/XLRepositoryBase.cs b/ClosedXML/Excel/Caching/XLRepositoryBase.cs index cdf3487..c8c4583 100644 --- a/ClosedXML/Excel/Caching/XLRepositoryBase.cs +++ b/ClosedXML/Excel/Caching/XLRepositoryBase.cs @@ -20,11 +20,11 @@ private readonly ConcurrentDictionary _storage; private readonly Func _createNew; - public XLRepositoryBase(Func createNew) : this(createNew, EqualityComparer.Default) + protected XLRepositoryBase(Func createNew) : this(createNew, EqualityComparer.Default) { } - public XLRepositoryBase(Func createNew, IEqualityComparer comparer) + protected XLRepositoryBase(Func createNew, IEqualityComparer comparer) { _storage = new ConcurrentDictionary(CONCURRENCY_LEVEL, INITIAL_CAPACITY, comparer); _createNew = createNew; diff --git a/ClosedXML/Excel/Style/XLAlignmentKey.cs b/ClosedXML/Excel/Style/XLAlignmentKey.cs index d1ec061..5367ec6 100644 --- a/ClosedXML/Excel/Style/XLAlignmentKey.cs +++ b/ClosedXML/Excel/Style/XLAlignmentKey.cs @@ -62,6 +62,15 @@ return hashCode; } + public override string ToString() + { + return + $"{Horizontal} {Vertical} {ReadingOrder} Indent: {Indent} RelativeIndent: {RelativeIndent} TextRotation: {TextRotation} " + + (WrapText ? "WrapText" : "") + + (JustifyLastLine ? "JustifyLastLine" : "") + + (TopToBottom ? "TopToBottom" : ""); + } + public static bool operator ==(XLAlignmentKey left, XLAlignmentKey right) => left.Equals(right); public static bool operator !=(XLAlignmentKey left, XLAlignmentKey right) => !(left.Equals(right)); diff --git a/ClosedXML/Excel/Style/XLBorderKey.cs b/ClosedXML/Excel/Style/XLBorderKey.cs index 33761f9..b1fc5eb 100644 --- a/ClosedXML/Excel/Style/XLBorderKey.cs +++ b/ClosedXML/Excel/Style/XLBorderKey.cs @@ -82,6 +82,14 @@ return base.Equals(obj); } + public override string ToString() + { + return $"{LeftBorder} {LeftBorderColor} {RightBorder} {RightBorderColor} {TopBorder} {TopBorderColor} " + + $"{BottomBorder} {BottomBorderColor} {DiagonalBorder} {DiagonalBorderColor} " + + (DiagonalUp ? "DiagonalUp" : "") + + (DiagonalDown ? "DiagonalDown" : ""); + } + public static bool operator ==(XLBorderKey left, XLBorderKey right) => left.Equals(right); public static bool operator !=(XLBorderKey left, XLBorderKey right) => !(left.Equals(right)); diff --git a/ClosedXML/Excel/Style/XLColorKey.cs b/ClosedXML/Excel/Style/XLColorKey.cs index dad43c5..a195739 100644 --- a/ClosedXML/Excel/Style/XLColorKey.cs +++ b/ClosedXML/Excel/Style/XLColorKey.cs @@ -54,6 +54,21 @@ return base.Equals(obj); } + public override string ToString() + { + switch (ColorType) + { + case XLColorType.Color: + return Color.ToString(); + case XLColorType.Theme: + return $"{ThemeColor} ({ThemeTint})"; + case XLColorType.Indexed: + return $"Indexed: {Indexed}"; + default: + return base.ToString(); + } + } + public static bool operator ==(XLColorKey left, XLColorKey right) => left.Equals(right); public static bool operator !=(XLColorKey left, XLColorKey right) => !(left.Equals(right)); diff --git a/ClosedXML/Excel/Style/XLFillKey.cs b/ClosedXML/Excel/Style/XLFillKey.cs index 6714735..bb7c930 100644 --- a/ClosedXML/Excel/Style/XLFillKey.cs +++ b/ClosedXML/Excel/Style/XLFillKey.cs @@ -35,6 +35,11 @@ return base.Equals(obj); } + public override string ToString() + { + return $"{PatternType} {BackgroundColor}/{PatternColor}"; + } + public static bool operator ==(XLFillKey left, XLFillKey right) => left.Equals(right); public static bool operator !=(XLFillKey left, XLFillKey right) => !(left.Equals(right)); diff --git a/ClosedXML/Excel/Style/XLFontKey.cs b/ClosedXML/Excel/Style/XLFontKey.cs index 6ed1c1f..e1b93ce 100644 --- a/ClosedXML/Excel/Style/XLFontKey.cs +++ b/ClosedXML/Excel/Style/XLFontKey.cs @@ -66,6 +66,14 @@ return hashCode; } + public override string ToString() + { + return $"{FontName} {FontSize}pt {FontColor} " + + (Bold ? "Bold" : "") + (Italic ? "Italic" : "") + (Strikethrough ? "Strikethrough" : "") + + (Underline == XLFontUnderlineValues.None ? "" : Underline.ToString()) + + $"{FontFamilyNumbering} {FontCharSet}"; + } + public static bool operator ==(XLFontKey left, XLFontKey right) => left.Equals(right); public static bool operator !=(XLFontKey left, XLFontKey right) => !(left.Equals(right)); diff --git a/ClosedXML/Excel/Style/XLNumberFormatKey.cs b/ClosedXML/Excel/Style/XLNumberFormatKey.cs index 9b39694..4d2e412 100644 --- a/ClosedXML/Excel/Style/XLNumberFormatKey.cs +++ b/ClosedXML/Excel/Style/XLNumberFormatKey.cs @@ -30,6 +30,11 @@ return base.Equals(obj); } + public override string ToString() + { + return $"{Format}/{NumberFormatId}"; + } + public static bool operator ==(XLNumberFormatKey left, XLNumberFormatKey right) => left.Equals(right); public static bool operator !=(XLNumberFormatKey left, XLNumberFormatKey right) => !(left.Equals(right)); diff --git a/ClosedXML/Excel/Style/XLProtectionKey.cs b/ClosedXML/Excel/Style/XLProtectionKey.cs index 7291252..94637d5 100644 --- a/ClosedXML/Excel/Style/XLProtectionKey.cs +++ b/ClosedXML/Excel/Style/XLProtectionKey.cs @@ -30,6 +30,11 @@ return base.Equals(obj); } + public override string ToString() + { + return (Locked ? "Locked" : "") + (Hidden ? "Hidden" : ""); + } + public static bool operator ==(XLProtectionKey left, XLProtectionKey right) => left.Equals(right); public static bool operator !=(XLProtectionKey left, XLProtectionKey right) => !(left.Equals(right)); diff --git a/ClosedXML/Excel/Style/XLStyleKey.cs b/ClosedXML/Excel/Style/XLStyleKey.cs index 7a84878..e68680d 100644 --- a/ClosedXML/Excel/Style/XLStyleKey.cs +++ b/ClosedXML/Excel/Style/XLStyleKey.cs @@ -38,6 +38,19 @@ Protection == other.Protection; } + public override string ToString() + { + return + this == XLStyle.Default.Key ? "Default" : + string.Format("Alignment: {0} Border: {1} Fill: {2} Font: {3} NumberFormat: {4} Protection: {5}", + Alignment == XLStyle.Default.Key.Alignment ? "Default" : Alignment.ToString(), + Border == XLStyle.Default.Key.Border ? "Default" : Border.ToString(), + Fill == XLStyle.Default.Key.Fill ? "Default" : Fill.ToString(), + Font == XLStyle.Default.Key.Font ? "Default" : Font.ToString(), + NumberFormat == XLStyle.Default.Key.NumberFormat ? "Default" : NumberFormat.ToString(), + Protection == XLStyle.Default.Key.Protection ? "Default" : Protection.ToString()); + } + public override bool Equals(object obj) { if (obj is XLStyleKey) diff --git a/ClosedXML/Excel/Style/XLStylizedBase.cs b/ClosedXML/Excel/Style/XLStylizedBase.cs index afdb7f0..b4f43e1 100644 --- a/ClosedXML/Excel/Style/XLStylizedBase.cs +++ b/ClosedXML/Excel/Style/XLStylizedBase.cs @@ -50,7 +50,7 @@ #endregion Properties - public XLStylizedBase(XLStyleValue styleValue) + protected XLStylizedBase(XLStyleValue styleValue) { StyleValue = styleValue; } @@ -80,10 +80,10 @@ public void ModifyStyle(Func modification) { - var children = GetChildrenRecursively(this); - var allChildren = children.GroupBy(child => child.StyleValue, _comparer); + var children = GetChildrenRecursively(this) + .GroupBy(child => child.StyleValue, _comparer); - foreach (var group in allChildren) + foreach (var group in children) { var styleKey = modification(group.Key.Key); var styleValue = XLStyleValue.FromKey(styleKey); diff --git a/ClosedXML_Sandbox/PerformanceRunner.cs b/ClosedXML_Sandbox/PerformanceRunner.cs index 2fdeb53..d64e02b 100644 --- a/ClosedXML_Sandbox/PerformanceRunner.cs +++ b/ClosedXML_Sandbox/PerformanceRunner.cs @@ -40,35 +40,6 @@ EmulateSave(workbook); } - public static void RunInsertTableWithStyles () - { - var rows = new List(); - - for (int i = 0; i < rowCount; i++) - { - var row = GenerateRow(); - rows.Add(row); - } - - var workbook = new XLWorkbook(); - var worksheet = workbook.Worksheets.Add("Sheet 1"); - worksheet.Cell(1, 1).InsertTable(rows); - - CreateMergedCell(worksheet); - - worksheet.Columns().AdjustToContents(); - - worksheet.Range(worksheet.FirstCellUsed().Address, worksheet.LastCellUsed().Address) - .Style - .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center) - .Border.SetOutsideBorder(XLBorderStyleValues.Thick) - .Fill.SetBackgroundColor(XLColor.Red) - .Font.SetFontColor(XLColor.Blue) - .NumberFormat.SetFormat("0.00") - .Protection.SetLocked(false); - - EmulateSave(workbook); - } public static void OpenTestFile() { using (var wb = new XLWorkbook("test.xlsx")) diff --git a/ClosedXML_Sandbox/Program.cs b/ClosedXML_Sandbox/Program.cs index e277048..1f3f681 100644 --- a/ClosedXML_Sandbox/Program.cs +++ b/ClosedXML_Sandbox/Program.cs @@ -18,10 +18,6 @@ Console.WriteLine(); #endif - Console.WriteLine("Running {0}", nameof(PerformanceRunner.RunInsertTableWithStyles)); - PerformanceRunner.TimeAction(PerformanceRunner.RunInsertTableWithStyles); - Console.WriteLine(); - Console.WriteLine("Press any key to continue"); Console.ReadKey(); }