diff --git a/ClosedXML/Excel/Cells/XLCell.cs b/ClosedXML/Excel/Cells/XLCell.cs index f9f30dd..dab1b88 100644 --- a/ClosedXML/Excel/Cells/XLCell.cs +++ b/ClosedXML/Excel/Cells/XLCell.cs @@ -92,7 +92,7 @@ } public XLCell(XLWorksheet worksheet, XLAddress address, IXLStyle style) - : this(worksheet, address, style.Value) + : this(worksheet, address, (style as XLStyle).Value) { } diff --git a/ClosedXML/Excel/Columns/XLColumn.cs b/ClosedXML/Excel/Columns/XLColumn.cs index 607f181..791c595 100644 --- a/ClosedXML/Excel/Columns/XLColumn.cs +++ b/ClosedXML/Excel/Columns/XLColumn.cs @@ -25,7 +25,7 @@ new XLAddress(xlColumnParameters.Worksheet, XLHelper.MaxRowNumber, column, false, false)), xlColumnParameters.IsReference ? xlColumnParameters.Worksheet.Internals.ColumnsCollection[column].StyleValue - : xlColumnParameters.DefaultStyle.Value) + : (xlColumnParameters.DefaultStyle as XLStyle).Value) { SetColumnNumber(column); @@ -267,12 +267,12 @@ && !autoFilterRows.Contains(t.AutoFilter.Range.FirstRow().RowNumber())) .Select(t => t.AutoFilter.Range.FirstRow().RowNumber())); - IXLStyle cellStyle = null; - foreach (XLCell c in Column(startRow, endRow).CellsUsed()) + XLStyle cellStyle = null; + foreach (var c in Column(startRow, endRow).CellsUsed().Cast()) { if (c.IsMerged()) continue; if (cellStyle == null || cellStyle.Value != c.StyleValue) - cellStyle = c.Style; + cellStyle = c.Style as XLStyle; Double thisWidthMax = 0; Int32 textRotation = cellStyle.Alignment.TextRotation; diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFCellIsConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFCellIsConverter.cs index 72c297a..2a3bf8e 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFCellIsConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFCellIsConverter.cs @@ -10,8 +10,8 @@ String val = GetQuoted(cf.Values[1]); var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle.Value)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; conditionalFormattingRule.Operator = cf.Operator.ToOpenXml(); diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFContainsConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFContainsConverter.cs index bb25709..435e690 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFContainsConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFContainsConverter.cs @@ -9,8 +9,8 @@ { String val = cf.Values[1].Value; var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle.Value)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; conditionalFormattingRule.Operator = ConditionalFormattingOperatorValues.ContainsText; diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFDatesOccuringConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFDatesOccuringConverter.cs index 82bcf6d..a1375b7 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFDatesOccuringConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFDatesOccuringConverter.cs @@ -23,8 +23,8 @@ public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; conditionalFormattingRule.TimePeriod = cf.TimePeriod.ToOpenXml(); diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFEndsWithConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFEndsWithConverter.cs index fa0f6d5..a65194a 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFEndsWithConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFEndsWithConverter.cs @@ -9,8 +9,8 @@ { String val = cf.Values[1].Value; var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; conditionalFormattingRule.Operator = ConditionalFormattingOperatorValues.EndsWith; diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFIsBlankConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFIsBlankConverter.cs index 6d282a9..07eccac 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFIsBlankConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFIsBlankConverter.cs @@ -8,8 +8,8 @@ public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle.Value)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; var formula = new Formula { Text = "LEN(TRIM(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "))=0" }; diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFIsErrorConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFIsErrorConverter.cs index bf2170f..1cfb4fe 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFIsErrorConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFIsErrorConverter.cs @@ -8,8 +8,8 @@ public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle.Value)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; var formula = new Formula { Text = "ISERROR(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + ")" }; diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotBlankConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotBlankConverter.cs index 532777a..4e36698 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotBlankConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotBlankConverter.cs @@ -8,8 +8,8 @@ public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle.Value)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; var formula = new Formula { Text = "LEN(TRIM(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "))>0" }; diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotContainsConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotContainsConverter.cs index 0c3bf31..8849d74 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotContainsConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotContainsConverter.cs @@ -9,8 +9,8 @@ { String val = cf.Values[1].Value; var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; conditionalFormattingRule.Operator = ConditionalFormattingOperatorValues.NotContains; diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotErrorConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotErrorConverter.cs index 7798815..51b794b 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotErrorConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFNotErrorConverter.cs @@ -8,8 +8,8 @@ public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle.Value)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; var formula = new Formula { Text = "NOT(ISERROR(" + cf.Range.RangeAddress.FirstAddress.ToStringRelative(false) + "))" }; diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFStartsWithConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFStartsWithConverter.cs index 1ede504..5f1721e 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFStartsWithConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFStartsWithConverter.cs @@ -9,8 +9,8 @@ { String val = cf.Values[1].Value; var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle.Value)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; conditionalFormattingRule.Operator = ConditionalFormattingOperatorValues.BeginsWith; diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFTopConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFTopConverter.cs index 194f183..cc4accc 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFTopConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFTopConverter.cs @@ -9,8 +9,8 @@ { UInt32 val = UInt32.Parse(cf.Values[1].Value); var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle.Value)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; conditionalFormattingRule.Percent = cf.Percent; diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFUniqueConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFUniqueConverter.cs index 673fae8..7c5035e 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFUniqueConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFUniqueConverter.cs @@ -8,8 +8,8 @@ public ConditionalFormattingRule Convert(IXLConditionalFormat cf, int priority, XLWorkbook.SaveContext context) { var conditionalFormattingRule = XLCFBaseConverter.Convert(cf, priority); - var cfStyle = cf.Style.Value; - if (!cfStyle.Equals(XLWorkbook.DefaultStyle.Value)) + var cfStyle = (cf.Style as XLStyle).Value; + if (!cfStyle.Equals(XLWorkbook.DefaultStyleValue)) conditionalFormattingRule.FormatId = (UInt32)context.DifferentialFormats[cfStyle.Key]; return conditionalFormattingRule; diff --git a/ClosedXML/Excel/ConditionalFormats/XLConditionalFormat.cs b/ClosedXML/Excel/ConditionalFormats/XLConditionalFormat.cs index 0140281..f348160 100644 --- a/ClosedXML/Excel/ConditionalFormats/XLConditionalFormat.cs +++ b/ClosedXML/Excel/ConditionalFormats/XLConditionalFormat.cs @@ -60,7 +60,7 @@ public int GetHashCode(IXLConditionalFormat obj) { var xx = (XLConditionalFormat)obj; - var xStyle = obj.Style.Value; + var xStyle = (obj.Style as XLStyle).Value; var xValues = xx.Values.Values.Where(v => !v.IsFormula).Select(v => v.Value) .Union(xx.Values.Values.Where(v => v.IsFormula).Select(f => ((XLCell)obj.Range.FirstCell()).GetFormulaR1C1(f.Value))); diff --git a/ClosedXML/Excel/Ranges/XLRange.cs b/ClosedXML/Excel/Ranges/XLRange.cs index 7a20194..fbee6dd 100644 --- a/ClosedXML/Excel/Ranges/XLRange.cs +++ b/ClosedXML/Excel/Ranges/XLRange.cs @@ -9,7 +9,7 @@ #region Constructor public XLRange(XLRangeParameters xlRangeParameters) - : base(xlRangeParameters.RangeAddress, xlRangeParameters.DefaultStyle.Value) + : base(xlRangeParameters.RangeAddress, (xlRangeParameters.DefaultStyle as XLStyle).Value) { RangeParameters = new XLRangeParameters(xlRangeParameters.RangeAddress, xlRangeParameters.DefaultStyle); @@ -245,7 +245,7 @@ foreach (IXLCell c in Range(1, 1, columnCount, rowCount).Cells()) { - var border = c.Style.Value.Border; + var border = (c.Style as XLStyle).Value.Border; c.Style.Border.TopBorder = border.LeftBorder; c.Style.Border.TopBorderColor = border.LeftBorderColor; c.Style.Border.LeftBorder = border.TopBorder; diff --git a/ClosedXML/Excel/Ranges/XLRangeColumn.cs b/ClosedXML/Excel/Ranges/XLRangeColumn.cs index a642b56..c027859 100644 --- a/ClosedXML/Excel/Ranges/XLRangeColumn.cs +++ b/ClosedXML/Excel/Ranges/XLRangeColumn.cs @@ -8,7 +8,7 @@ #region Constructor public XLRangeColumn(XLRangeParameters rangeParameters, bool quickLoad) - : base(rangeParameters.RangeAddress, rangeParameters.DefaultStyle.Value) + : base(rangeParameters.RangeAddress, (rangeParameters.DefaultStyle as XLStyle).Value) { if (quickLoad) return; diff --git a/ClosedXML/Excel/Ranges/XLRangeColumns.cs b/ClosedXML/Excel/Ranges/XLRangeColumns.cs index ede54ff..170cd3f 100644 --- a/ClosedXML/Excel/Ranges/XLRangeColumns.cs +++ b/ClosedXML/Excel/Ranges/XLRangeColumns.cs @@ -10,7 +10,7 @@ { private readonly List _ranges = new List(); - public XLRangeColumns() : base(XLWorkbook.DefaultStyle.Value) + public XLRangeColumns() : base(XLWorkbook.DefaultStyleValue) { } diff --git a/ClosedXML/Excel/Ranges/XLRangeRow.cs b/ClosedXML/Excel/Ranges/XLRangeRow.cs index ec245c5..bd0034c 100644 --- a/ClosedXML/Excel/Ranges/XLRangeRow.cs +++ b/ClosedXML/Excel/Ranges/XLRangeRow.cs @@ -8,7 +8,7 @@ #region Constructor public XLRangeRow(XLRangeParameters rangeParameters, bool quickLoad) - : base(rangeParameters.RangeAddress, rangeParameters.DefaultStyle.Value) + : base(rangeParameters.RangeAddress, (rangeParameters.DefaultStyle as XLStyle).Value) { RangeParameters = rangeParameters; if (quickLoad) return; diff --git a/ClosedXML/Excel/Ranges/XLRanges.cs b/ClosedXML/Excel/Ranges/XLRanges.cs index a57186c..b97fc4b 100644 --- a/ClosedXML/Excel/Ranges/XLRanges.cs +++ b/ClosedXML/Excel/Ranges/XLRanges.cs @@ -10,7 +10,7 @@ { private readonly List _ranges = new List(); - public XLRanges() : base(XLWorkbook.DefaultStyle.Value) + public XLRanges() : base(XLWorkbook.DefaultStyleValue) { } diff --git a/ClosedXML/Excel/Rows/XLRow.cs b/ClosedXML/Excel/Rows/XLRow.cs index b4076ca..e52827d 100644 --- a/ClosedXML/Excel/Rows/XLRow.cs +++ b/ClosedXML/Excel/Rows/XLRow.cs @@ -23,7 +23,7 @@ new XLAddress(xlRowParameters.Worksheet, row, XLHelper.MaxColumnNumber, false, false)), xlRowParameters.IsReference ? xlRowParameters.Worksheet.Internals.RowsCollection[row].StyleValue - : xlRowParameters.DefaultStyle.Value + : (xlRowParameters.DefaultStyle as XLStyle).Value ) { SetRowNumber(row); diff --git a/ClosedXML/Excel/Rows/XLRows.cs b/ClosedXML/Excel/Rows/XLRows.cs index c7a9321..8494f8f 100644 --- a/ClosedXML/Excel/Rows/XLRows.cs +++ b/ClosedXML/Excel/Rows/XLRows.cs @@ -11,7 +11,7 @@ private readonly List _rows = new List(); private readonly XLWorksheet _worksheet; - public XLRows(XLWorksheet worksheet) : base(XLWorkbook.DefaultStyle.Value) + public XLRows(XLWorksheet worksheet) : base(XLWorkbook.DefaultStyleValue) { _worksheet = worksheet; } diff --git a/ClosedXML/Excel/Style/IXLStyle.cs b/ClosedXML/Excel/Style/IXLStyle.cs index d90eeab..259f568 100644 --- a/ClosedXML/Excel/Style/IXLStyle.cs +++ b/ClosedXML/Excel/Style/IXLStyle.cs @@ -17,7 +17,5 @@ IXLNumberFormat DateFormat { get; } IXLProtection Protection { get; set; } - - XLStyleValue Value { get; } } } diff --git a/ClosedXML/Excel/Style/XLBorderKey.cs b/ClosedXML/Excel/Style/XLBorderKey.cs index b1fc5eb..0251dfa 100644 --- a/ClosedXML/Excel/Style/XLBorderKey.cs +++ b/ClosedXML/Excel/Style/XLBorderKey.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public struct XLBorderKey : IEquatable + internal struct XLBorderKey : IEquatable { public XLBorderStyleValues LeftBorder { get; set; } diff --git a/ClosedXML/Excel/Style/XLBorderValue.cs b/ClosedXML/Excel/Style/XLBorderValue.cs index 4cb4e01..7c1f8da 100644 --- a/ClosedXML/Excel/Style/XLBorderValue.cs +++ b/ClosedXML/Excel/Style/XLBorderValue.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public class XLBorderValue + internal class XLBorderValue { private static readonly XLBorderRepository Repository = new XLBorderRepository(key => new XLBorderValue(key)); diff --git a/ClosedXML/Excel/Style/XLColorKey.cs b/ClosedXML/Excel/Style/XLColorKey.cs index a195739..2484ecf 100644 --- a/ClosedXML/Excel/Style/XLColorKey.cs +++ b/ClosedXML/Excel/Style/XLColorKey.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public struct XLColorKey : IEquatable + internal struct XLColorKey : IEquatable { public XLColorType ColorType { get; set; } diff --git a/ClosedXML/Excel/Style/XLFillKey.cs b/ClosedXML/Excel/Style/XLFillKey.cs index bb7c930..c2f2495 100644 --- a/ClosedXML/Excel/Style/XLFillKey.cs +++ b/ClosedXML/Excel/Style/XLFillKey.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public struct XLFillKey : IEquatable + internal struct XLFillKey : IEquatable { public XLColorKey BackgroundColor { get; set; } diff --git a/ClosedXML/Excel/Style/XLFillValue.cs b/ClosedXML/Excel/Style/XLFillValue.cs index 230a278..d12d8fd 100644 --- a/ClosedXML/Excel/Style/XLFillValue.cs +++ b/ClosedXML/Excel/Style/XLFillValue.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public sealed class XLFillValue + internal sealed class XLFillValue { private static readonly XLFillRepository Repository = new XLFillRepository(key => new XLFillValue(key)); diff --git a/ClosedXML/Excel/Style/XLFontKey.cs b/ClosedXML/Excel/Style/XLFontKey.cs index e1b93ce..37ee4a0 100644 --- a/ClosedXML/Excel/Style/XLFontKey.cs +++ b/ClosedXML/Excel/Style/XLFontKey.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public struct XLFontKey : IEquatable + internal struct XLFontKey : IEquatable { public bool Bold { get; set; } diff --git a/ClosedXML/Excel/Style/XLFontValue.cs b/ClosedXML/Excel/Style/XLFontValue.cs index 910633c..088ca07 100644 --- a/ClosedXML/Excel/Style/XLFontValue.cs +++ b/ClosedXML/Excel/Style/XLFontValue.cs @@ -3,7 +3,7 @@ namespace ClosedXML.Excel { - public sealed class XLFontValue + internal sealed class XLFontValue { private static readonly XLFontRepository Repository = new XLFontRepository(key => new XLFontValue(key)); diff --git a/ClosedXML/Excel/Style/XLNumberFormatKey.cs b/ClosedXML/Excel/Style/XLNumberFormatKey.cs index 4d2e412..7a14dc5 100644 --- a/ClosedXML/Excel/Style/XLNumberFormatKey.cs +++ b/ClosedXML/Excel/Style/XLNumberFormatKey.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public struct XLNumberFormatKey : IEquatable + internal struct XLNumberFormatKey : IEquatable { public int NumberFormatId { get; set; } diff --git a/ClosedXML/Excel/Style/XLNumberFormatValue.cs b/ClosedXML/Excel/Style/XLNumberFormatValue.cs index 84a9635..dab2ee1 100644 --- a/ClosedXML/Excel/Style/XLNumberFormatValue.cs +++ b/ClosedXML/Excel/Style/XLNumberFormatValue.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public sealed class XLNumberFormatValue + internal sealed class XLNumberFormatValue { private static readonly XLNumberFormatRepository Repository = new XLNumberFormatRepository(key => new XLNumberFormatValue(key)); diff --git a/ClosedXML/Excel/Style/XLProtectionKey.cs b/ClosedXML/Excel/Style/XLProtectionKey.cs index 94637d5..ba4f013 100644 --- a/ClosedXML/Excel/Style/XLProtectionKey.cs +++ b/ClosedXML/Excel/Style/XLProtectionKey.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public struct XLProtectionKey : IEquatable + internal struct XLProtectionKey : IEquatable { public bool Locked { get; set; } diff --git a/ClosedXML/Excel/Style/XLProtectionValue.cs b/ClosedXML/Excel/Style/XLProtectionValue.cs index 6d97093..c5520e9 100644 --- a/ClosedXML/Excel/Style/XLProtectionValue.cs +++ b/ClosedXML/Excel/Style/XLProtectionValue.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public sealed class XLProtectionValue + internal sealed class XLProtectionValue { private static readonly XLProtectionRepository Repository = new XLProtectionRepository(key => new XLProtectionValue(key)); diff --git a/ClosedXML/Excel/Style/XLStyle.cs b/ClosedXML/Excel/Style/XLStyle.cs index 9d3540b..95e63f2 100644 --- a/ClosedXML/Excel/Style/XLStyle.cs +++ b/ClosedXML/Excel/Style/XLStyle.cs @@ -38,7 +38,7 @@ private readonly IXLStylized _container; - public XLStyleValue Value { get; private set; } + internal XLStyleValue Value { get; private set; } internal XLStyleKey Key { diff --git a/ClosedXML/Excel/Style/XLStyleKey.cs b/ClosedXML/Excel/Style/XLStyleKey.cs index e68680d..46eea98 100644 --- a/ClosedXML/Excel/Style/XLStyleKey.cs +++ b/ClosedXML/Excel/Style/XLStyleKey.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public struct XLStyleKey : IEquatable + internal struct XLStyleKey : IEquatable { public XLAlignmentKey Alignment { get; set; } diff --git a/ClosedXML/Excel/Style/XLStyleValue.cs b/ClosedXML/Excel/Style/XLStyleValue.cs index cec54b3..9135e5e 100644 --- a/ClosedXML/Excel/Style/XLStyleValue.cs +++ b/ClosedXML/Excel/Style/XLStyleValue.cs @@ -2,7 +2,7 @@ namespace ClosedXML.Excel { - public class XLStyleValue + internal class XLStyleValue { private static readonly XLStyleRepository Repository = new XLStyleRepository(key => new XLStyleValue(key)); diff --git a/ClosedXML/Excel/Style/XLStylizedBase.cs b/ClosedXML/Excel/Style/XLStylizedBase.cs index b4f43e1..307bcf7 100644 --- a/ClosedXML/Excel/Style/XLStylizedBase.cs +++ b/ClosedXML/Excel/Style/XLStylizedBase.cs @@ -8,14 +8,18 @@ /// /// Base class for any workbook element that has or may have a style. /// - public abstract class XLStylizedBase : IXLStylized + internal abstract class XLStylizedBase : IXLStylized { #region Properties /// /// Read-only style property. /// - public XLStyleValue StyleValue { get; private set; } + internal XLStyleValue StyleValue { get; private set; } + XLStyleValue IXLStylized.StyleValue + { + get { return StyleValue; } + } /// /// Editable style of the workbook element. Modification of this property DOES affect styles of child objects as well - they will @@ -78,7 +82,7 @@ private static ReferenceEqualityComparer _comparer = new ReferenceEqualityComparer(); - public void ModifyStyle(Func modification) + void IXLStylized.ModifyStyle(Func modification) { var children = GetChildrenRecursively(this) .GroupBy(child => child.StyleValue, _comparer); diff --git a/ClosedXML/Excel/Style/XLStylizedContainer.cs b/ClosedXML/Excel/Style/XLStylizedContainer.cs index 7c8329e..04f94a7 100644 --- a/ClosedXML/Excel/Style/XLStylizedContainer.cs +++ b/ClosedXML/Excel/Style/XLStylizedContainer.cs @@ -6,7 +6,7 @@ { protected readonly IXLStylized _container; - public XLStylizedContainer(IXLStyle style, IXLStylized container) : base(style.Value) + public XLStylizedContainer(IXLStyle style, IXLStylized container) : base((style as XLStyle).Value) { _container = container; } diff --git a/ClosedXML/Excel/Style/XLStylizedEmpty.cs b/ClosedXML/Excel/Style/XLStylizedEmpty.cs index dc7cdf3..931c4b4 100644 --- a/ClosedXML/Excel/Style/XLStylizedEmpty.cs +++ b/ClosedXML/Excel/Style/XLStylizedEmpty.cs @@ -4,7 +4,7 @@ { internal class XLStylizedEmpty : XLStylizedBase, IXLStylized { - public XLStylizedEmpty(IXLStyle defaultStyle) : base(defaultStyle?.Value ?? XLStyle.Default.Value) + public XLStylizedEmpty(IXLStyle defaultStyle) : base((defaultStyle as XLStyle)?.Value ?? XLStyle.Default.Value) { } diff --git a/ClosedXML/Excel/Tables/XLTableRows.cs b/ClosedXML/Excel/Tables/XLTableRows.cs index bbc1479..f02dffa 100644 --- a/ClosedXML/Excel/Tables/XLTableRows.cs +++ b/ClosedXML/Excel/Tables/XLTableRows.cs @@ -9,8 +9,7 @@ { private readonly List _ranges = new List(); - public XLTableRows(IXLStyle defaultStyle) : base(defaultStyle.Value) - + public XLTableRows(IXLStyle defaultStyle) : base((defaultStyle as XLStyle).Value) { } diff --git a/ClosedXML/Excel/XLWorkbook.cs b/ClosedXML/Excel/XLWorkbook.cs index f64c655..c9716be 100644 --- a/ClosedXML/Excel/XLWorkbook.cs +++ b/ClosedXML/Excel/XLWorkbook.cs @@ -52,6 +52,14 @@ } } + internal static XLStyleValue DefaultStyleValue + { + get + { + return XLStyleValue.Default; + } + } + public static Double DefaultRowHeight { get; private set; } public static Double DefaultColumnWidth { get; private set; } diff --git a/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/Excel/XLWorkbook_Load.cs index 0d9de6c..85b6eec 100644 --- a/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/Excel/XLWorkbook_Load.cs @@ -2582,7 +2582,7 @@ { LoadFill(fill, xlStylized.InnerStyle.Fill, differentialFillFormat: false); } - xlStyle.Fill = xlStylized.InnerStyle.Value.Key.Fill; + xlStyle.Fill = (xlStylized.InnerStyle as XLStyle).Value.Key.Fill; } var alignment = cellFormat.Alignment; diff --git a/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/Excel/XLWorkbook_Save.cs index 0b4dea1..59619b7 100644 --- a/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/Excel/XLWorkbook_Save.cs @@ -1883,12 +1883,12 @@ // https://github.com/ClosedXML/ClosedXML/issues/513 if (xlField.IsConsistentStyle()) { - var style = xlField.Column.Cells() + var style = (xlField.Column.Cells() .Skip(xlTable.ShowHeaderRow ? 1 : 0) .First() - .Style.Value; + .Style as XLStyle).Value; - if (!DefaultStyle.Value.Equals(style) && context.DifferentialFormats.ContainsKey(style.Key)) + if (!DefaultStyleValue.Equals(style) && context.DifferentialFormats.ContainsKey(style.Key)) tableColumn.DataFormatId = UInt32Value.FromUInt32(Convert.ToUInt32(context.DifferentialFormats[style.Key])); } else @@ -3211,7 +3211,7 @@ private void GenerateWorkbookStylesPartContent(WorkbookStylesPart workbookStylesPart, SaveContext context) { - var defaultStyle = DefaultStyle.Value; + var defaultStyle = DefaultStyleValue; if (!context.SharedFonts.ContainsKey(defaultStyle.Font)) context.SharedFonts.Add(defaultStyle.Font, new FontInfo { FontId = 0, Font = defaultStyle.Font }); @@ -3406,7 +3406,8 @@ { foreach (var cf in ws.ConditionalFormats) { - if (!cf.Style.Value.Equals(DefaultStyle.Value) && !context.DifferentialFormats.ContainsKey(cf.Style.Value.Key)) + var styleValue = (cf.Style as XLStyle).Value; + if (!styleValue.Equals(DefaultStyleValue) && !context.DifferentialFormats.ContainsKey(styleValue.Key)) AddConditionalDifferentialFormat(workbookStylesPart.Stylesheet.DifferentialFormats, cf, context); } @@ -3414,12 +3415,12 @@ { if (tf.IsConsistentStyle()) { - var style = tf.Column.Cells() + var style = (tf.Column.Cells() .Skip(tf.Table.ShowHeaderRow ? 1 : 0) .First() - .Style.Value; + .Style as XLStyle).Value; - if (!style.Equals(DefaultStyle.Value) && !context.DifferentialFormats.ContainsKey(style.Key)) + if (!style.Equals(DefaultStyleValue) && !context.DifferentialFormats.ContainsKey(style.Key)) AddStyleAsDifferentialFormat(workbookStylesPart.Stylesheet.DifferentialFormats, style, context); } } @@ -3455,8 +3456,9 @@ SaveContext context) { var differentialFormat = new DifferentialFormat(); + var styleValue = (cf.Style as XLStyle).Value; - var diffFont = GetNewFont(new FontInfo { Font = cf.Style.Value.Font }, false); + var diffFont = GetNewFont(new FontInfo { Font = styleValue.Font }, false); if (diffFont?.HasChildren ?? false) differentialFormat.Append(diffFont); @@ -3470,17 +3472,17 @@ differentialFormat.Append(numberFormat); } - var diffFill = GetNewFill(new FillInfo { Fill = cf.Style.Value.Fill }, differentialFillFormat: true, ignoreMod: false); + var diffFill = GetNewFill(new FillInfo { Fill = styleValue.Fill }, differentialFillFormat: true, ignoreMod: false); if (diffFill?.HasChildren ?? false) differentialFormat.Append(diffFill); - var diffBorder = GetNewBorder(new BorderInfo { Border = cf.Style.Value.Border }, false); + var diffBorder = GetNewBorder(new BorderInfo { Border = styleValue.Border }, false); if (diffBorder?.HasChildren ?? false) differentialFormat.Append(diffBorder); differentialFormats.Append(differentialFormat); - context.DifferentialFormats.Add(cf.Style.Value.Key, differentialFormats.Count() - 1); + context.DifferentialFormats.Add(styleValue.Key, differentialFormats.Count() - 1); } private static void AddStyleAsDifferentialFormat(DifferentialFormats differentialFormats, XLStyleValue style, @@ -4641,7 +4643,7 @@ maxInColumnsCollection = (Int32)col.Max.Value; } - if (maxInColumnsCollection < XLHelper.MaxColumnNumber && !xlWorksheet.StyleValue.Equals(DefaultStyle.Value)) + if (maxInColumnsCollection < XLHelper.MaxColumnNumber && !xlWorksheet.StyleValue.Equals(DefaultStyleValue)) { var column = new Column { diff --git a/ClosedXML/Excel/XLWorksheet.cs b/ClosedXML/Excel/XLWorksheet.cs index e9e1af5..b29631d 100644 --- a/ClosedXML/Excel/XLWorksheet.cs +++ b/ClosedXML/Excel/XLWorksheet.cs @@ -39,7 +39,7 @@ new XLRangeAddress( new XLAddress(null, XLHelper.MinRowNumber, XLHelper.MinColumnNumber, false, false), new XLAddress(null, XLHelper.MaxRowNumber, XLHelper.MaxColumnNumber, false, false)), - workbook.Style.Value) + (workbook.Style as XLStyle).Value) { EventTrackingEnabled = workbook.EventTracking == XLEventTracking.Enabled;