diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs index 4be0f9f..cf25003 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs @@ -1490,7 +1490,7 @@ if (!SettingHyperlink) { - if (Style.Font.FontColor == worksheet.Style.Font.FontColor) + if (Style.Font.FontColor.Equals(worksheet.Style.Font.FontColor)) Style.Font.FontColor = XLColor.FromTheme(XLThemeColor.Hyperlink); if (Style.Font.Underline == worksheet.Style.Font.Underline) diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs index 7ba0581..700ca98 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/RichText/XLRichText.cs @@ -19,7 +19,7 @@ VerticalAlignment = defaultFont.VerticalAlignment; Shadow = defaultFont.Shadow; FontSize = defaultFont.FontSize; - FontColor = defaultFont.FontColor; + FontColor = new XLColor(defaultFont.FontColor); FontName = defaultFont.FontName; FontFamilyNumbering = defaultFont.FontFamilyNumbering; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs index 9a7b489..2906e32 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs @@ -15,40 +15,49 @@ { this.ThemeColor = defaultColor.ThemeColor; this.ThemeTint = defaultColor.ThemeTint; + hashCode = 7 ^ themeColor.GetHashCode() ^ themeTint.GetHashCode(); } else if (defaultColor.ColorType == XLColorType.Indexed) { this.Indexed = defaultColor.Indexed; + hashCode = 11 ^ indexed; } else { this.Color = defaultColor.Color; + hashCode = 13 ^ color.GetHashCode(); } + HasValue = true; } internal XLColor() { HasValue = false; + hashCode = 0; } internal XLColor(Color color) { Color = color; + hashCode = 13 ^ this.color.GetHashCode(); HasValue = true; } internal XLColor(Int32 index) { Indexed = index; + hashCode = 11 ^ indexed; HasValue = true; } internal XLColor(XLThemeColor themeColor) { ThemeColor = themeColor; ThemeTint = 1; + hashCode = 7 ^ this.themeColor.GetHashCode() ^ themeTint.GetHashCode(); HasValue = true; } internal XLColor(XLThemeColor themeColor, Double themeTint) { ThemeColor = themeColor; ThemeTint = themeTint; + hashCode = 7 ^ this.themeColor.GetHashCode() ^ this.themeTint.GetHashCode(); HasValue = true; } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Public.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Public.cs index 8346162..4da1d2c 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Public.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/Colors/XLColor_Public.cs @@ -10,20 +10,30 @@ { public Boolean HasValue { get; private set; } - public XLColorType ColorType { get; private set; } + XLColorType colorType; + public XLColorType ColorType { + get + { + return colorType; + } + private set + { + colorType = value; + } + } private Color color; public Color Color { get { - if (ColorType == XLColorType.Theme) + if (colorType == XLColorType.Theme) { //if (workbook == null) throw new Exception("Cannot convert theme color to Color."); //else // return workbook.GetXLColor(themeColor).Color; } - else if (ColorType == XLColorType.Indexed) + else if (colorType == XLColorType.Indexed) { return IndexedColors[indexed].Color; } @@ -35,7 +45,7 @@ private set { color = value; - ColorType = XLColorType.Color; + colorType = XLColorType.Color; } } @@ -60,7 +70,7 @@ private set { indexed = value; - ColorType = XLColorType.Indexed; + colorType = XLColorType.Indexed; } } @@ -87,7 +97,7 @@ themeColor = value; if (themeTint == 0) themeTint = 1; - ColorType = XLColorType.Theme; + colorType = XLColorType.Theme; } } @@ -112,53 +122,43 @@ private set { themeTint = value; - ColorType = XLColorType.Theme; + colorType = XLColorType.Theme; } } public bool Equals(IXLColor other) { - if (ColorType != other.ColorType) + var otherC = other as XLColor; + if (colorType == otherC.colorType) { - return false; - } - else - { - if (ColorType == XLColorType.Theme) + if (colorType == XLColorType.Color) { - return this.ThemeColor.Equals(other.ThemeColor) - && this.ThemeTint.Equals(other.ThemeTint); + return color == otherC.color; } - else if (ColorType == XLColorType.Indexed) + if (colorType == XLColorType.Theme) { - return this.Indexed.Equals(other.Indexed); + return themeColor == otherC.themeColor + && themeTint == otherC.themeTint; } else { - return this.Color.Equals(other.Color); + return indexed == otherC.indexed; } } + else + { + return false; + } } public override bool Equals(object obj) { return this.Equals((XLColor)obj); } + int hashCode; public override int GetHashCode() { - if (ColorType == XLColorType.Theme) - { - return ThemeColor.GetHashCode() - ^ ThemeTint.GetHashCode(); - } - else if (ColorType == XLColorType.Indexed) - { - return Indexed; - } - else - { - return Color.GetHashCode(); - } + return hashCode; } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs index 3afb559..468ca03 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs @@ -263,16 +263,17 @@ public bool Equals(IXLAlignment other) { + var otherA = other as XLAlignment; return - this.Horizontal.Equals(other.Horizontal) - && this.Vertical.Equals(other.Vertical) - && this.Indent.Equals(other.Indent) - && this.JustifyLastLine.Equals(other.JustifyLastLine) - && this.ReadingOrder.Equals(other.ReadingOrder) - && this.RelativeIndent.Equals(other.RelativeIndent) - && this.ShrinkToFit.Equals(other.ShrinkToFit) - && this.TextRotation.Equals(other.TextRotation) - && this.WrapText.Equals(other.WrapText) + horizontal == otherA.horizontal + && vertical == otherA.vertical + && indent == otherA.indent + && justifyLastLine == otherA.justifyLastLine + && readingOrder == otherA.readingOrder + && relativeIndent == otherA.relativeIndent + && shrinkToFit == otherA.shrinkToFit + && textRotation == otherA.textRotation + && wrapText == otherA.wrapText ; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs index a5656fe..bc21b53 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs @@ -17,15 +17,15 @@ if (defaultBorder != null) { leftBorder = defaultBorder.LeftBorder; - leftBorderColor = defaultBorder.LeftBorderColor; + leftBorderColor = new XLColor(defaultBorder.LeftBorderColor); rightBorder = defaultBorder.RightBorder; - rightBorderColor = defaultBorder.RightBorderColor; + rightBorderColor = new XLColor(defaultBorder.RightBorderColor); topBorder = defaultBorder.TopBorder; - topBorderColor = defaultBorder.TopBorderColor; + topBorderColor = new XLColor(defaultBorder.TopBorderColor); bottomBorder = defaultBorder.BottomBorder; - bottomBorderColor = defaultBorder.BottomBorderColor; + bottomBorderColor = new XLColor(defaultBorder.BottomBorderColor); diagonalBorder = defaultBorder.DiagonalBorder; - diagonalBorderColor = defaultBorder.DiagonalBorderColor; + diagonalBorderColor = new XLColor(defaultBorder.DiagonalBorderColor); diagonalUp = defaultBorder.DiagonalUp; diagonalDown = defaultBorder.DiagonalDown; } @@ -288,19 +288,20 @@ public bool Equals(IXLBorder other) { + var otherB = other as XLBorder; return - this.LeftBorder.Equals(other.LeftBorder) - && this.LeftBorderColor.Equals(other.LeftBorderColor) - && this.RightBorder.Equals(other.RightBorder) - && this.RightBorderColor.Equals(other.RightBorderColor) - && this.TopBorder.Equals(other.TopBorder) - && this.TopBorderColor.Equals(other.TopBorderColor) - && this.BottomBorder.Equals(other.BottomBorder) - && this.BottomBorderColor.Equals(other.BottomBorderColor) - && this.DiagonalBorder.Equals(other.DiagonalBorder) - && this.DiagonalBorderColor.Equals(other.DiagonalBorderColor) - && this.DiagonalUp.Equals(other.DiagonalUp) - && this.DiagonalDown.Equals(other.DiagonalDown) + leftBorder == otherB.leftBorder + && leftBorderColor.Equals(otherB.leftBorderColor) + && rightBorder==otherB.rightBorder + && rightBorderColor.Equals(otherB.rightBorderColor) + && topBorder==otherB.topBorder + && topBorderColor.Equals(otherB.topBorderColor) + && bottomBorder==otherB.bottomBorder + && bottomBorderColor.Equals(otherB.bottomBorderColor) + && diagonalBorder==otherB.diagonalBorder + && diagonalBorderColor.Equals(otherB.diagonalBorderColor) + && diagonalUp==otherB.diagonalUp + && diagonalDown==otherB.diagonalDown ; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFill.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFill.cs index 124475e..ac04541 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFill.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFill.cs @@ -100,8 +100,8 @@ if (defaultFill != null) { patternType = defaultFill.PatternType; - patternColor = defaultFill.PatternColor; - patternBackgroundColor = defaultFill.PatternBackgroundColor; + patternColor = new XLColor(defaultFill.PatternColor); + patternBackgroundColor = new XLColor(defaultFill.PatternBackgroundColor); } } @@ -125,9 +125,8 @@ public bool Equals(IXLFill other) { return - this.BackgroundColor.Equals(other.BackgroundColor) - && this.PatternType.Equals(other.PatternType) - && this.PatternColor.Equals(other.PatternColor) + patternType == other.PatternType + && patternColor.Equals(other.PatternColor) ; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFont.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFont.cs index 96b5fda..dfb7174 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFont.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFont.cs @@ -27,7 +27,7 @@ verticalAlignment = defaultFont.VerticalAlignment; shadow = defaultFont.Shadow; fontSize = defaultFont.FontSize; - fontColor = defaultFont.FontColor; + fontColor = new XLColor(defaultFont.FontColor); fontName = defaultFont.FontName; fontFamilyNumbering = defaultFont.FontFamilyNumbering; } @@ -268,17 +268,18 @@ public Boolean Equals(IXLFont other) { + var otherF = other as XLFont; return - this.Bold.Equals(other.Bold) - && this.Italic.Equals(other.Italic) - && this.Underline.Equals(other.Underline) - && this.Strikethrough.Equals(other.Strikethrough) - && this.VerticalAlignment.Equals(other.VerticalAlignment) - && this.Shadow.Equals(other.Shadow) - && this.FontSize.Equals(other.FontSize) - && this.FontColor.Equals(other.FontColor) - && this.FontName.Equals(other.FontName) - && this.FontFamilyNumbering.Equals(other.FontFamilyNumbering) + bold == otherF.bold + && italic == otherF.italic + && underline == otherF.underline + && strikethrough == otherF.strikethrough + && verticalAlignment == otherF.verticalAlignment + && shadow == otherF.shadow + && fontSize == otherF.fontSize + && fontColor.Equals(otherF.fontColor) + && fontName == otherF.fontName + && fontFamilyNumbering == otherF.fontFamilyNumbering ; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs index de38a6e..d474dc0 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs @@ -83,9 +83,10 @@ public bool Equals(IXLNumberFormat other) { + var otherNF = other as XLNumberFormat; return - this.NumberFormatId.Equals(other.NumberFormatId) - && this.Format.Equals(other.Format) + numberFormatId == otherNF.numberFormatId + && format == otherNF.format ; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLProtection.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLProtection.cs index a47da26..917c8aa 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLProtection.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLProtection.cs @@ -62,8 +62,9 @@ public bool Equals(IXLProtection other) { - return this.Locked.Equals(other.Locked) - && this.Hidden.Equals(other.Hidden); + var otherP = other as XLProtection; + return locked == otherP.locked + && hidden == otherP.hidden; } public override bool Equals(object obj) diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStyle.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStyle.cs index 46a4316..3cb5334 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStyle.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStyle.cs @@ -78,12 +78,19 @@ public bool Equals(IXLStyle other) { return - this.Font.Equals(other.Font) - && this.Fill.Equals(other.Fill) - && this.Border.Equals(other.Border) - && this.NumberFormat.Equals(other.NumberFormat) - && this.Alignment.Equals(other.Alignment) - && this.Protection.Equals(other.Protection) + // this.Font.GetHashCode().Equals(other.Font.GetHashCode()) + //&& this.Fill.GetHashCode().Equals(other.Fill.GetHashCode()) + //&& this.Border.GetHashCode().Equals(other.Border.GetHashCode()) + //&& this.NumberFormat.GetHashCode().Equals(other.NumberFormat.GetHashCode()) + //&& this.Alignment.GetHashCode().Equals(other.Alignment.GetHashCode()) + //&& this.Protection.GetHashCode().Equals(other.Protection.GetHashCode()) + + this.Font.Equals(other.Font) + && this.Fill.Equals(other.Fill) + && this.Border.Equals(other.Border) + && this.NumberFormat.Equals(other.NumberFormat) + && this.Alignment.Equals(other.Alignment) + && this.Protection.Equals(other.Protection) ; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLAddress.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLAddress.cs index 1c6482a..f5e51c2 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLAddress.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLAddress.cs @@ -23,6 +23,8 @@ this.columnLetter = null; this.fixedColumn = fixedColumn; this.fixedRow = fixedRow; + + hashCode = rowNumber ^ columnNumber; } /// @@ -38,6 +40,7 @@ this.columnLetter = columnLetter; this.fixedColumn = fixedColumn; this.fixedRow = fixedRow; + hashCode = rowNumber ^ ColumnNumber; } @@ -82,6 +85,8 @@ } columnNumber = 0; + + hashCode = rowNumber ^ ColumnNumber; } #endregion @@ -393,14 +398,7 @@ public static Boolean operator ==(XLAddress xlCellAddressLeft, XLAddress xlCellAddressRight) { - if (//xlCellAddressLeft.Worksheet == xlCellAddressRight.Worksheet && - xlCellAddressLeft.rowNumber == xlCellAddressRight.rowNumber) - if (xlCellAddressRight.columnNumber > 0) - return xlCellAddressLeft.ColumnNumber == xlCellAddressRight.columnNumber; - else - return xlCellAddressLeft.ColumnLetter == xlCellAddressRight.columnLetter; - else - return false; + return xlCellAddressLeft.Equals(xlCellAddressRight); } public static Boolean operator !=(XLAddress xlCellAddressLeft, XLAddress xlCellAddressRight) @@ -456,12 +454,10 @@ return ((XLAddress)obj).GetHashCode(); } + int hashCode; public override Int32 GetHashCode() { - return - Worksheet.GetHashCode() - ^ rowNumber - ^ ColumnNumber; + return hashCode; } #endregion @@ -471,6 +467,9 @@ public Boolean Equals(IXLAddress other) { var right = other as XLAddress; + if (hashCode != right.hashCode) + return false; + if (this.rowNumber == right.rowNumber) if (right.columnNumber > 0) return this.ColumnNumber == right.columnNumber; @@ -482,7 +481,7 @@ public override Boolean Equals(Object other) { - return this == (XLAddress)other; + return Equals((XLAddress)other); } #endregion diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs index ca492f9..b59cebd 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs @@ -25,7 +25,7 @@ NamedRanges = new XLNamedRanges(this); CustomProperties = new XLCustomProperties(this); PopulateEnums(); - Style = DefaultStyle; + Style = new XLStyle(null, DefaultStyle); RowHeight = DefaultRowHeight; ColumnWidth = DefaultColumnWidth; PageOptions = DefaultPageOptions; @@ -258,67 +258,70 @@ #endregion #region Static - + private static IXLStyle defaultStyle; public static IXLStyle DefaultStyle { get { - var defaultStyle = new XLStyle(null, null) + if (defaultStyle == null) { - Font = new XLFont(null, null) + defaultStyle = new XLStyle(null, null) { - Bold = false, - Italic = false, - Underline = XLFontUnderlineValues.None, - Strikethrough = false, - VerticalAlignment = XLFontVerticalTextAlignmentValues.Baseline, - FontSize = 11, - FontColor = XLColor.FromArgb(0, 0, 0), - FontName = "Calibri", - FontFamilyNumbering = XLFontFamilyNumberingValues.Swiss - }, - - Fill = new XLFill(null) - { - BackgroundColor = XLColor.FromIndex(64), - PatternType = XLFillPatternValues.None, - PatternColor = XLColor.FromIndex(64) - }, - - Border = new XLBorder(null, null) + Font = new XLFont(null, null) { - BottomBorder = XLBorderStyleValues.None, - DiagonalBorder = XLBorderStyleValues.None, - DiagonalDown = false, - DiagonalUp = false, - LeftBorder = XLBorderStyleValues.None, - RightBorder = XLBorderStyleValues.None, - TopBorder = XLBorderStyleValues.None, - BottomBorderColor = XLColor.Black, - DiagonalBorderColor = XLColor.Black, - LeftBorderColor = XLColor.Black, - RightBorderColor = XLColor.Black, - TopBorderColor = XLColor.Black + Bold = false, + Italic = false, + Underline = XLFontUnderlineValues.None, + Strikethrough = false, + VerticalAlignment = XLFontVerticalTextAlignmentValues.Baseline, + FontSize = 11, + FontColor = XLColor.FromArgb(0, 0, 0), + FontName = "Calibri", + FontFamilyNumbering = XLFontFamilyNumberingValues.Swiss }, - NumberFormat = new XLNumberFormat(null, null) { NumberFormatId = 0 }, - Alignment = new XLAlignment(null) - { - Horizontal = XLAlignmentHorizontalValues.General, - Indent = 0, - JustifyLastLine = false, - ReadingOrder = XLAlignmentReadingOrderValues.ContextDependent, - RelativeIndent = 0, - ShrinkToFit = false, - TextRotation = 0, - Vertical = XLAlignmentVerticalValues.Bottom, - WrapText = false + + Fill = new XLFill(null) + { + BackgroundColor = XLColor.FromIndex(64), + PatternType = XLFillPatternValues.None, + PatternColor = XLColor.FromIndex(64) + }, + + Border = new XLBorder(null, null) + { + BottomBorder = XLBorderStyleValues.None, + DiagonalBorder = XLBorderStyleValues.None, + DiagonalDown = false, + DiagonalUp = false, + LeftBorder = XLBorderStyleValues.None, + RightBorder = XLBorderStyleValues.None, + TopBorder = XLBorderStyleValues.None, + BottomBorderColor = XLColor.Black, + DiagonalBorderColor = XLColor.Black, + LeftBorderColor = XLColor.Black, + RightBorderColor = XLColor.Black, + TopBorderColor = XLColor.Black + }, + NumberFormat = new XLNumberFormat(null, null) { NumberFormatId = 0 }, + Alignment = new XLAlignment(null) + { + Horizontal = XLAlignmentHorizontalValues.General, + Indent = 0, + JustifyLastLine = false, + ReadingOrder = XLAlignmentReadingOrderValues.ContextDependent, + RelativeIndent = 0, + ShrinkToFit = false, + TextRotation = 0, + Vertical = XLAlignmentVerticalValues.Bottom, + WrapText = false }, Protection = new XLProtection(null) { Locked = true, Hidden = false } - }; + }; + } return defaultStyle; } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs index dfb11c4..d1cf344 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs @@ -809,7 +809,7 @@ var protection = (Protection)((CellFormat)((CellFormats)s.CellFormats).ElementAt(styleIndex)).Protection; if (protection == null) - xlStylized.InnerStyle.Protection = DefaultStyle.Protection; + xlStylized.InnerStyle.Protection = new XLProtection(null, DefaultStyle.Protection); else { xlStylized.InnerStyle.Protection.Hidden = protection.Hidden != null && protection.Hidden.HasValue && protection.Hidden.Value; diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs index 1be22e3..29cbd75 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs @@ -331,6 +331,7 @@ using (package) { CreateParts(package); + //package.Close(); } } @@ -345,6 +346,7 @@ using (package) { CreateParts(package); + //package.Close(); } } @@ -856,13 +858,15 @@ Int32 stringId = 0; foreach (var s in modifiedStrings) { - SharedStringItem sharedStringItem = new SharedStringItem(); - Text text = new Text(); - text.Text = s; - sharedStringItem.Append(text); - sharedStringTablePart.SharedStringTable.Append(sharedStringItem); - sharedStringTablePart.SharedStringTable.Count += 1; - sharedStringTablePart.SharedStringTable.UniqueCount += 1; + SharedStringItem sharedStringItem = new SharedStringItem(); + Text text = new Text(); + text.Text = s; + if (s.StartsWith(" ") || s.EndsWith(" ")) + text.Space = SpaceProcessingModeValues.Preserve; + sharedStringItem.Append(text); + sharedStringTablePart.SharedStringTable.Append(sharedStringItem); + sharedStringTablePart.SharedStringTable.Count += 1; + sharedStringTablePart.SharedStringTable.UniqueCount += 1; sharedStrings.Add(s, (UInt32)stringId); stringId++; @@ -872,7 +876,7 @@ #region GenerateWorkbookStylesPartContent private void GenerateWorkbookStylesPartContent(WorkbookStylesPart workbookStylesPart) { - var defaultStyle = DefaultStyle; + var defaultStyle = new XLStyle(null, DefaultStyle); Dictionary sharedFonts = new Dictionary(); sharedFonts.Add(defaultStyle.Font, new FontInfo() { FontId = 0, Font = defaultStyle.Font }); @@ -1602,7 +1606,7 @@ #region SheetProperties if (worksheetPart.Worksheet.SheetProperties == null) - worksheetPart.Worksheet.SheetProperties = new SheetProperties();// { CodeName = xlWorksheet.Name.RemoveSpecialCharacters() }; + worksheetPart.Worksheet.SheetProperties = new SheetProperties(); if (xlWorksheet.TabColor.HasValue) worksheetPart.Worksheet.SheetProperties.TabColor = GetTabColor(xlWorksheet.TabColor); diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Ranges/UsingTables.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Ranges/UsingTables.cs index b2c6693..bbdecf1 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Ranges/UsingTables.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Ranges/UsingTables.cs @@ -27,7 +27,7 @@ var table = range.CreateTable(); // You can also use range.AsTable() if you want to // manipulate the range as a table but don't want // to create the table in the worksheet. - + // Let's activate the Totals row and add the sum of Income table.ShowTotalsRow = true; table.Field("Income").TotalsRowFunction = XLTotalsRowFunction.Sum; @@ -55,7 +55,6 @@ headersTable.ShowTotalsRow = true; headersTable.Field(0).TotalsRowFormulaA1 = "CONCATENATE(\"Count: \", CountA(Headers[Table Headers]))"; - // Copy the names Int32 columnWithNames = columnWithHeaders + 2; currentRow = table.RangeAddress.FirstAddress.RowNumber; // reset the currentRow diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/DefaultStyles.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/DefaultStyles.cs index c4cfb3b..5cc6858 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/DefaultStyles.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/DefaultStyles.cs @@ -12,14 +12,6 @@ { public void Create(String filePath) { - // The static default values are read-only so even if - // you try to change a referenced type, the changes will be discarded. - var style = XLWorkbook.DefaultStyle; - style.Border.DiagonalUp = true; - style.Border.DiagonalDown = true; - style.Border.DiagonalBorder = XLBorderStyleValues.Thick; - style.Border.DiagonalBorderColor = XLColor.Red; - // Create our workbook var workbook = new XLWorkbook(); diff --git a/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs b/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs index 464f890..678a91a 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs @@ -12,11 +12,11 @@ { class Program { - static void Main(string[] args) + static void xMain(string[] args) { //var fileName = "DataValidation"; //var fileName = "Sandbox"; - var fileName = "Issue_6756"; + var fileName = "Issue_0000"; var wb = new XLWorkbook(String.Format(@"c:\Excel Files\ForTesting\{0}.xlsx", fileName)); //var wb = new XLWorkbook(); //var ws = wb.Worksheets.Add("Sheet1"); @@ -35,8 +35,7 @@ //Now, when i use workbook.Worksheet("CCR").Range("B1:C34").RangeUsed(). //The expect is B1:C29. - var ws = wb.Worksheet(1); - ws.CopyTo("012345678901234567890123456789"); + wb.SaveAs(String.Format(@"c:\Excel Files\ForTesting\{0}_Saved.xlsx", fileName)); //Console.ReadKey(); } @@ -52,7 +51,7 @@ } } - static void xMain(string[] args) + static void Main(string[] args) { FillStyles(); List runningSave = new List(); @@ -66,11 +65,11 @@ foreach (var i in Enumerable.Range(1, 1)) { var ws = wb.Worksheets.Add("Sheet" + i); - foreach (var ro in Enumerable.Range(1, 2000)) + foreach (var ro in Enumerable.Range(1, 10000)) { - foreach (var co in Enumerable.Range(1, 100)) + foreach (var co in Enumerable.Range(1, 20)) { - ws.Cell(ro, co).Style = GetRandomStyle(); + //ws.Cell(ro, co).Style = GetRandomStyle(); //if (rnd.Next(1, 5) == 1) //ws.Cell(ro, co).FormulaA1 = ws.Cell(ro + 1, co + 1).Address.ToString() + " & \"-Copy\""; //else