diff --git a/ClosedXML/Excel/Style/XLBorderKey.cs b/ClosedXML/Excel/Style/XLBorderKey.cs index 04594ab..33761f9 100644 --- a/ClosedXML/Excel/Style/XLBorderKey.cs +++ b/ClosedXML/Excel/Style/XLBorderKey.cs @@ -32,35 +32,47 @@ { var hashCode = -198124310; hashCode = hashCode * -1521134295 + LeftBorder.GetHashCode(); - hashCode = hashCode * -1521134295 + LeftBorderColor.GetHashCode(); hashCode = hashCode * -1521134295 + RightBorder.GetHashCode(); - hashCode = hashCode * -1521134295 + RightBorderColor.GetHashCode(); hashCode = hashCode * -1521134295 + TopBorder.GetHashCode(); - hashCode = hashCode * -1521134295 + TopBorderColor.GetHashCode(); hashCode = hashCode * -1521134295 + BottomBorder.GetHashCode(); - hashCode = hashCode * -1521134295 + BottomBorderColor.GetHashCode(); hashCode = hashCode * -1521134295 + DiagonalBorder.GetHashCode(); - hashCode = hashCode * -1521134295 + DiagonalBorderColor.GetHashCode(); hashCode = hashCode * -1521134295 + DiagonalUp.GetHashCode(); hashCode = hashCode * -1521134295 + DiagonalDown.GetHashCode(); + + if (LeftBorder != XLBorderStyleValues.None) + hashCode = hashCode * -1521134295 + LeftBorderColor.GetHashCode(); + if (RightBorder != XLBorderStyleValues.None) + hashCode = hashCode * -1521134295 + RightBorderColor.GetHashCode(); + if (TopBorder != XLBorderStyleValues.None) + hashCode = hashCode * -1521134295 + TopBorderColor.GetHashCode(); + if (BottomBorder != XLBorderStyleValues.None) + hashCode = hashCode * -1521134295 + BottomBorderColor.GetHashCode(); + if (DiagonalBorder != XLBorderStyleValues.None) + hashCode = hashCode * -1521134295 + DiagonalBorderColor.GetHashCode(); + return hashCode; } public bool Equals(XLBorderKey other) { return - LeftBorder == other.LeftBorder - && LeftBorderColor == other.LeftBorderColor - && RightBorder == other.RightBorder - && RightBorderColor == other.RightBorderColor - && TopBorder == other.TopBorder - && TopBorderColor == other.TopBorderColor - && BottomBorder == other.BottomBorder - && BottomBorderColor == other.BottomBorderColor - && DiagonalBorder == other.DiagonalBorder - && DiagonalBorderColor == other.DiagonalBorderColor - && DiagonalUp == other.DiagonalUp - && DiagonalDown == other.DiagonalDown; + AreEquivalent(LeftBorder, LeftBorderColor, other.LeftBorder, other.LeftBorderColor) + && AreEquivalent(RightBorder, RightBorderColor, other.RightBorder, other.RightBorderColor) + && AreEquivalent(TopBorder, TopBorderColor, other.TopBorder, other.TopBorderColor) + && AreEquivalent(BottomBorder, BottomBorderColor, other.BottomBorder, other.BottomBorderColor) + && AreEquivalent(DiagonalBorder, DiagonalBorderColor, other.DiagonalBorder, other.DiagonalBorderColor) + && DiagonalUp == other.DiagonalUp + && DiagonalDown == other.DiagonalDown; + } + + private bool AreEquivalent( + XLBorderStyleValues borderStyle1, XLColorKey color1, + XLBorderStyleValues borderStyle2, XLColorKey color2) + { + return (borderStyle1 == XLBorderStyleValues.None && + borderStyle2 == XLBorderStyleValues.None) || + borderStyle1 == borderStyle2 && + color1 == color2; } public override bool Equals(object obj) diff --git a/ClosedXML/Excel/Style/XLFillKey.cs b/ClosedXML/Excel/Style/XLFillKey.cs index 39d165d..6714735 100644 --- a/ClosedXML/Excel/Style/XLFillKey.cs +++ b/ClosedXML/Excel/Style/XLFillKey.cs @@ -22,6 +22,7 @@ public bool Equals(XLFillKey other) { return + (PatternType == XLFillPatternValues.None && other.PatternType == XLFillPatternValues.None) || BackgroundColor == other.BackgroundColor && PatternColor == other.PatternColor && PatternType == other.PatternType; diff --git a/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/Excel/XLWorkbook_Save.cs index dedae34..c6bfa21 100644 --- a/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/Excel/XLWorkbook_Save.cs @@ -3399,7 +3399,7 @@ workbookStylesPart.Stylesheet.DifferentialFormats = new DifferentialFormats(); var differentialFormats = workbookStylesPart.Stylesheet.DifferentialFormats; - + differentialFormats.RemoveAllChildren(); FillDifferentialFormatsCollection(differentialFormats, context.DifferentialFormats); foreach (var ws in Worksheets) @@ -3647,8 +3647,10 @@ && f.FillId != null && styleInfo.FillId == f.FillId && f.FontId != null && styleInfo.FontId == f.FontId && f.NumberFormatId != null && styleInfo.NumberFormatId == f.NumberFormatId - && f.ApplyFill != null && f.ApplyFill == ApplyFill(styleInfo) - && f.ApplyBorder != null && f.ApplyBorder == ApplyBorder(styleInfo) + && (f.ApplyFill == null && styleInfo.Style.Fill == XLFillValue.Default || + f.ApplyFill != null && f.ApplyFill == ApplyFill(styleInfo)) + && (f.ApplyBorder == null && styleInfo.Style.Border == XLBorderValue.Default || + f.ApplyBorder != null && f.ApplyBorder == ApplyBorder(styleInfo)) && (f.Alignment == null || AlignmentsAreEqual(f.Alignment, styleInfo.Style.Alignment)) && ProtectionsAreEqual(f.Protection, styleInfo.Style.Protection) ; @@ -3656,7 +3658,7 @@ private static bool ProtectionsAreEqual(Protection protection, XLProtectionValue xlProtection) { - var p = new XLProtectionKey(); + var p = XLProtectionValue.Default.Key; if (protection != null) { if (protection.Locked != null) @@ -3671,7 +3673,7 @@ { if (alignment != null) { - var a = new XLAlignmentKey(); + var a = XLAlignmentValue.Default.Key; if (alignment.Indent != null) a.Indent = (Int32)alignment.Indent.Value; @@ -3802,7 +3804,7 @@ private bool BordersAreEqual(Border b, XLBorderValue xlBorder) { - var nb = new XLBorderKey(); + var nb = XLBorderValue.Default.Key; if (b.DiagonalUp != null) nb.DiagonalUp = b.DiagonalUp.Value; diff --git a/ClosedXML_Tests/Excel/Columns/ColumnTests.cs b/ClosedXML_Tests/Excel/Columns/ColumnTests.cs index 38a5c78..35dc053 100644 --- a/ClosedXML_Tests/Excel/Columns/ColumnTests.cs +++ b/ClosedXML_Tests/Excel/Columns/ColumnTests.cs @@ -241,7 +241,7 @@ { var ws = new XLWorkbook().AddWorksheet("Sheet1") as XLWorksheet; - var column = new XLColumn(-1, new XLColumnParameters(ws, null, false)); + var column = new XLColumn(-1, new XLColumnParameters(ws, XLStyle.Default, false)); Assert.IsFalse(column.RangeAddress.IsValid); } diff --git a/ClosedXML_Tests/Excel/Rows/RowTests.cs b/ClosedXML_Tests/Excel/Rows/RowTests.cs index 4be3963..5314b54 100644 --- a/ClosedXML_Tests/Excel/Rows/RowTests.cs +++ b/ClosedXML_Tests/Excel/Rows/RowTests.cs @@ -259,7 +259,7 @@ { var ws = new XLWorkbook().AddWorksheet("Sheet1") as XLWorksheet; - var row = new XLRow(-1, new XLRowParameters(ws, null, false)); + var row = new XLRow(-1, new XLRowParameters(ws, XLStyle.Default, false)); Assert.IsFalse(row.RangeAddress.IsValid); } diff --git a/ClosedXML_Tests/Resource/Examples/Styles/StyleWorksheet.xlsx b/ClosedXML_Tests/Resource/Examples/Styles/StyleWorksheet.xlsx index cf0c6ef..c7f0652 100644 --- a/ClosedXML_Tests/Resource/Examples/Styles/StyleWorksheet.xlsx +++ b/ClosedXML_Tests/Resource/Examples/Styles/StyleWorksheet.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/StyleReferenceFiles/ConditionalFormattingOrder/ConditionalFormattingOrder.xlsx b/ClosedXML_Tests/Resource/StyleReferenceFiles/ConditionalFormattingOrder/ConditionalFormattingOrder.xlsx index ed07359..84c186d 100644 --- a/ClosedXML_Tests/Resource/StyleReferenceFiles/ConditionalFormattingOrder/ConditionalFormattingOrder.xlsx +++ b/ClosedXML_Tests/Resource/StyleReferenceFiles/ConditionalFormattingOrder/ConditionalFormattingOrder.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx b/ClosedXML_Tests/Resource/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx index bccd5b2..ffd35b3 100644 --- a/ClosedXML_Tests/Resource/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx +++ b/ClosedXML_Tests/Resource/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx Binary files differ