diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj index 059f02a..4155a70 100644 --- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj +++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj @@ -170,6 +170,7 @@ + diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumnCollection.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumnCollection.cs index 80596da..1651ca6 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumnCollection.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumnCollection.cs @@ -5,17 +5,10 @@ namespace ClosedXML.Excel { - //internal delegate void ColumnDeletingDelegate(Int32 deletedColumn, Boolean beingShifted); - //internal delegate void ColumnShiftedDelegate(Int32 startingColumn, Int32 columnsShifted); internal class XLColumnsCollection : IDictionary { - //public event ColumnDeletingDelegate ColumnDeleting; - //public event ColumnShiftedDelegate ColumnShifted; - - //private Boolean beingShifted = false; public void ShiftColumnsRight(Int32 startingColumn, Int32 columnsToShift) { - //beingShifted = true; foreach (var ro in dictionary.Keys.Where(k => k >= startingColumn).OrderByDescending(k => k)) { var columnToMove = dictionary[ro]; @@ -27,10 +20,6 @@ dictionary.Remove(ro); } - //if (ColumnShifted != null) - // ColumnShifted(startingColumn, columnsToShift); - - //beingShifted = false; } private Dictionary dictionary = new Dictionary(); @@ -52,9 +41,6 @@ public bool Remove(int key) { - //if (ColumnDeleting != null) - // ColumnDeleting(key, beingShifted); - return dictionary.Remove(key); } @@ -87,9 +73,6 @@ public void Clear() { - //if (ColumnDeleting != null) - // dictionary.ForEach(r => ColumnDeleting(r.Key, beingShifted)); - dictionary.Clear(); } @@ -115,9 +98,6 @@ public bool Remove(KeyValuePair item) { - //if (ColumnDeleting != null) - // ColumnDeleting(item.Key, beingShifted); - return dictionary.Remove(item.Key); } @@ -130,5 +110,10 @@ { return dictionary.GetEnumerator(); } + + public void RemoveAll(Func predicate) + { + dictionary.RemoveAll(predicate); + } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLRichText.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLRichText.cs index 8bff436..70d11fa 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLRichText.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/IXLRichText.cs @@ -5,21 +5,10 @@ namespace ClosedXML.Excel { - public interface IXLRichText: IEquatable + public interface IXLRichText: IXLFontBase, IEquatable { String Text { get; } - Boolean Bold { get; set; } - Boolean Italic { get; set; } - XLFontUnderlineValues Underline { get; set; } - Boolean Strikethrough { get; set; } - XLFontVerticalTextAlignmentValues VerticalAlignment { get; set; } - Boolean Shadow { get; set; } - Double FontSize { get; set; } - IXLColor FontColor { get; set; } - String FontName { get; set; } - XLFontFamilyNumberingValues FontFamilyNumbering { get; set; } - IXLRichText SetBold(); IXLRichText SetBold(Boolean value); IXLRichText SetItalic(); IXLRichText SetItalic(Boolean value); IXLRichText SetUnderline(); IXLRichText SetUnderline(XLFontUnderlineValues value); diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichString.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichString.cs index dc4f987..6d390aa 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichString.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichString.cs @@ -49,6 +49,7 @@ } } richTexts = newRichTexts; + throw new NotImplementedException(); } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs index 8e93ec2..7474ebc 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs @@ -8,14 +8,15 @@ internal class XLRichText: IXLRichText { public XLRichText(String text) + : this(text, XLWorkbook.DefaultStyle.Font) { + } - public XLRichText(String text, IXLRichText defaultRichText) + public XLRichText(String text, IXLFontBase defaultFont) { Text = text; - var defaultFont = XLWorkbook.DefaultStyle.Font; Bold = defaultFont.Bold; Italic = defaultFont.Italic; Underline = defaultFont.Underline; diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRowCollection.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRowCollection.cs index 37d6e32..109160d 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRowCollection.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRowCollection.cs @@ -5,17 +5,10 @@ namespace ClosedXML.Excel { - //internal delegate void RowDeletingDelegate(Int32 deletedRow, Boolean beingShifted); - //internal delegate void RowShiftedDelegate(Int32 startingRow, Int32 rowsShifted); internal class XLRowsCollection: IDictionary { - //public event RowDeletingDelegate RowDeleting; - //public event RowShiftedDelegate RowShifted; - - //private Boolean beingShifted = false; public void ShiftRowsDown(Int32 startingRow, Int32 rowsToShift) { - //beingShifted = true; foreach (var ro in dictionary.Keys.Where(k => k >= startingRow).OrderByDescending(k => k)) { var rowToMove = dictionary[ro]; @@ -26,17 +19,23 @@ } dictionary.Remove(ro); } - - //if (RowShifted != null) - // RowShifted(startingRow, rowsToShift); - - //beingShifted = false; } private Dictionary dictionary = new Dictionary(); + private Dictionary deleted = new Dictionary(); + public Dictionary Deleted + { + get + { + return deleted; + } + } public void Add(int key, XLRow value) { + if (deleted.ContainsKey(key)) + deleted.Remove(key); + dictionary.Add(key, value); } @@ -52,8 +51,8 @@ public bool Remove(int key) { - //if (RowDeleting != null) - // RowDeleting(key, beingShifted); + if (!deleted.ContainsKey(key)) + deleted.Add(key, dictionary[key]); return dictionary.Remove(key); } @@ -82,13 +81,19 @@ public void Add(KeyValuePair item) { + if (deleted.ContainsKey(item.Key)) + deleted.Remove(item.Key); + dictionary.Add(item.Key, item.Value); } public void Clear() { - //if (RowDeleting != null) - // dictionary.ForEach(r => RowDeleting(r.Key, beingShifted)); + foreach (var kp in dictionary) + { + if (!deleted.ContainsKey(kp.Key)) + deleted.Add(kp.Key, kp.Value); + } dictionary.Clear(); } @@ -115,8 +120,8 @@ public bool Remove(KeyValuePair item) { - //if (RowDeleting != null) - // RowDeleting(item.Key, beingShifted); + if (!deleted.ContainsKey(item.Key)) + deleted.Add(item.Key, dictionary[item.Key]); return dictionary.Remove(item.Key); } @@ -130,5 +135,16 @@ { return dictionary.GetEnumerator(); } + + public void RemoveAll(Func predicate) + { + foreach (var kp in dictionary.Values.Where(predicate).Select(c=>c)) + { + if (!deleted.ContainsKey(kp.RowNumber())) + deleted.Add(kp.RowNumber(), kp); + } + + dictionary.RemoveAll(predicate); + } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs index 746e2c2..3b6c8ca 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs @@ -36,7 +36,7 @@ internal XLColor(Color color) { this.color = color; - hashCode = 13 ^ this.color.GetHashCode(); + hashCode = 13 ^ color.ToArgb(); HasValue = true; colorType = XLColorType.Color; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Public.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Public.cs index 4da1d2c..9acdf40 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Public.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Public.cs @@ -133,7 +133,7 @@ { if (colorType == XLColorType.Color) { - return color == otherC.color; + return color.ToArgb() == otherC.color.ToArgb(); } if (colorType == XLColorType.Theme) { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs index 397b502..6d5f05c 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs @@ -32,18 +32,9 @@ Decorative = 5 } - public interface IXLFont : IEquatable + public interface IXLFont : IXLFontBase, IEquatable { - Boolean Bold { get; set; } - Boolean Italic { get; set; } - XLFontUnderlineValues Underline { get; set; } - Boolean Strikethrough { get; set; } - XLFontVerticalTextAlignmentValues VerticalAlignment { get; set; } - Boolean Shadow { get; set; } - Double FontSize { get; set; } - IXLColor FontColor { get; set; } - String FontName { get; set; } - XLFontFamilyNumberingValues FontFamilyNumbering { get; set; } + IXLStyle SetBold(); IXLStyle SetBold(Boolean value); IXLStyle SetItalic(); IXLStyle SetItalic(Boolean value); diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFontBase.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFontBase.cs new file mode 100644 index 0000000..d15ce3e --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFontBase.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; + +namespace ClosedXML.Excel +{ + + + public interface IXLFontBase + { + Boolean Bold { get; set; } + Boolean Italic { get; set; } + XLFontUnderlineValues Underline { get; set; } + Boolean Strikethrough { get; set; } + XLFontVerticalTextAlignmentValues VerticalAlignment { get; set; } + Boolean Shadow { get; set; } + Double FontSize { get; set; } + IXLColor FontColor { get; set; } + String FontName { get; set; } + XLFontFamilyNumberingValues FontFamilyNumbering { get; set; } + + + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs index ece3ceb..9beeeee 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs @@ -1716,9 +1716,20 @@ cellsByRow[rowNum].Add(c); } + + + var sheetDataRows = sheetData.Elements().ToDictionary(r => (Int32)r.RowIndex.Value, r => r); + foreach (var r in xlWorksheet.Internals.RowsCollection.Deleted) + { + if (sheetDataRows.ContainsKey(r.Key)) + { + sheetData.RemoveChild(sheetDataRows[r.Key]); + sheetDataRows.Remove(r.Key); + } + } + var distinctRows = cellsByRow.Keys.Union((xlWorksheet as XLWorksheet).Internals.RowsCollection.Keys); Boolean noRows = (sheetData.Elements().FirstOrDefault() == null); - var sheetDataRows = sheetData.Elements().ToDictionary(r => (Int32)r.RowIndex.Value, r => r); foreach (var distinctRow in distinctRows.OrderBy(r => r)) { Row row; // = sheetData.Elements().FirstOrDefault(r => r.RowIndex.Value == (UInt32)distinctRow); @@ -1782,19 +1793,27 @@ //row.Hidden = false; } - List cellsToRemove = new List(); - foreach (var cell in row.Elements()) + var cellsByReference = row.Elements().ToDictionary(c => c.CellReference.Value, c => c); + + foreach (var c in xlWorksheet.Internals.CellsCollection.Deleted) { - var cellReference = cell.CellReference; - if ((xlWorksheet as XLWorksheet).Internals.CellsCollection.Deleted.ContainsKey(XLAddress.Create(xlWorksheet, cellReference))) - cellsToRemove.Add(cell); + if (cellsByReference.ContainsKey(c.Key.ToStringRelative())) + row.RemoveChild(cellsByReference[c.Key.ToStringRelative()]); } - cellsToRemove.ForEach(cell => row.RemoveChild(cell)); + + //List cellsToRemove = new List(); + //foreach (var cell in row.Elements()) + //{ + // var cellReference = cell.CellReference; + // if (xlWorksheet.Internals.CellsCollection.Deleted.ContainsKey(XLAddress.Create(xlWorksheet, cellReference))) + // cellsToRemove.Add(cell); + //} + //cellsToRemove.ForEach(cell => row.RemoveChild(cell)); if (cellsByRow.ContainsKey(distinctRow)) { - var cellsByReference = row.Elements().ToDictionary(c => c.CellReference.Value, c => c); + Boolean isNewRow = !row.Elements().Any(); foreach (var opCell in cellsByRow[distinctRow] .OrderBy(c => c.Address.ColumnNumber) diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj index 6c49d43..a829050 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj @@ -358,9 +358,15 @@ Excel\Ranges\XLRanges.cs + + Excel\RichText\IXLRichString.cs + Excel\RichText\IXLRichText.cs + + Excel\RichText\XLRichString.cs + Excel\RichText\XLRichText.cs @@ -406,6 +412,9 @@ Excel\Style\IXLFont.cs + + Excel\Style\IXLFontBase.cs + Excel\Style\IXLNumberFormat.cs