diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj index c0236b7..3f56652 100644 --- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj +++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj @@ -233,6 +233,7 @@ + diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs index b3176ab..a08f49c 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs @@ -1383,14 +1383,7 @@ if (canInsert) cellsToInsert.Add(newKey, newCell); } - //cellsDataValidations.ForEach(kp => - //{ - // XLCell targetCell; - // if (!cellsToInsert.TryGetValue(kp.Key, out targetCell)) - // targetCell = Worksheet.Cell(kp.Key); - // - // targetCell.CopyDataValidation(Worksheet.Cell(kp.Value.SourceAddress), kp.Value.DataValidation); - //}); + cellsToDelete.ForEach(c => Worksheet.Internals.CellsCollection.Remove(c.RowNumber, c.ColumnNumber)); cellsToInsert.ForEach( diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStylizedEmpty.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStylizedEmpty.cs new file mode 100644 index 0000000..9e059f9 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStylizedEmpty.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + internal class XLStylizedEmpty: IXLStylized + { + public XLStylizedEmpty(IXLStyle defaultStyle) + { + Style = defaultStyle; + } + public IXLStyle Style { get; set; } + + public IEnumerable Styles + { + get + { + UpdatingStyle = true; + yield return Style; + UpdatingStyle = false; + } + } + + public bool UpdatingStyle { get; set; } + + public IXLStyle InnerStyle { get; set; } + + public IXLRanges RangesUsed + { + get { return new XLRanges(); } + } + + public bool StyleChanged { get; set; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs index fc06bce..a4b7dba 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs @@ -111,7 +111,12 @@ var borders = s.Borders; var fonts = s.Fonts; Int32 dfCount = 0; - var differentialFormats = s.DifferentialFormats.Elements().ToDictionary(k => dfCount++); + Dictionary differentialFormats; + if (s.DifferentialFormats != null) + differentialFormats = s.DifferentialFormats.Elements().ToDictionary(k => dfCount++); + else + differentialFormats = new Dictionary(); + var sheets = dSpreadsheet.WorkbookPart.Workbook.Sheets; Int32 position = 0; foreach (Sheet dSheet in sheets.OfType()) diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs index 059eb66..8a4d128 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs @@ -1824,11 +1824,13 @@ { if (workbookStylesPart.Stylesheet.DifferentialFormats == null) workbookStylesPart.Stylesheet.DifferentialFormats = new DifferentialFormats(); - else - workbookStylesPart.Stylesheet.DifferentialFormats.RemoveAllChildren(); + var differentialFormats = workbookStylesPart.Stylesheet.DifferentialFormats; + FillDifferentialFormatsCollection(differentialFormats, context.DifferentialFormats); + + foreach(var ws in Worksheets) { foreach(var cf in ws.ConditionalFormats) @@ -1839,6 +1841,25 @@ } differentialFormats.Count = (UInt32) differentialFormats.Count(); + if (differentialFormats.Count == 0) + workbookStylesPart.Stylesheet.DifferentialFormats = null; + + } + + private void FillDifferentialFormatsCollection(DifferentialFormats differentialFormats, Dictionary dictionary) + { + dictionary.Clear(); + Int32 id = 0; + foreach(var df in differentialFormats.Elements()) + { + var style = new XLStyle(new XLStylizedEmpty(DefaultStyle), DefaultStyle); + LoadFont(df.Font, style.Font); + LoadBorder(df.Border, style.Border); + LoadNumberFormat(df.NumberingFormat, style.NumberFormat); + LoadFill(df.Fill, style.Fill); + if (!dictionary.ContainsKey(style)) + dictionary.Add(style, ++id); + } } private void AddDifferentialFormat(DifferentialFormats differentialFormats, IXLConditionalFormat cf, SaveContext context) diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj index 926014a..a184d52 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj @@ -822,6 +822,7 @@ PathHelper.cs + diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/Excel/Style/XLStylizedEmpty.cs b/ClosedXML/ClosedXML/ClosedXML_Net3.5/Excel/Style/XLStylizedEmpty.cs new file mode 100644 index 0000000..9e059f9 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/Excel/Style/XLStylizedEmpty.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + internal class XLStylizedEmpty: IXLStylized + { + public XLStylizedEmpty(IXLStyle defaultStyle) + { + Style = defaultStyle; + } + public IXLStyle Style { get; set; } + + public IEnumerable Styles + { + get + { + UpdatingStyle = true; + yield return Style; + UpdatingStyle = false; + } + } + + public bool UpdatingStyle { get; set; } + + public IXLStyle InnerStyle { get; set; } + + public IXLRanges RangesUsed + { + get { return new XLRanges(); } + } + + public bool StyleChanged { get; set; } + } +}