diff --git a/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML.csproj index b53bde4..4500c11 100644 --- a/ClosedXML/ClosedXML.csproj +++ b/ClosedXML/ClosedXML.csproj @@ -26,8 +26,14 @@ + + + + + + diff --git a/ClosedXML/Excel/Columns/XLColumn.cs b/ClosedXML/Excel/Columns/XLColumn.cs index 12c689e..37e70b0 100644 --- a/ClosedXML/Excel/Columns/XLColumn.cs +++ b/ClosedXML/Excel/Columns/XLColumn.cs @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Drawing; - +using System.Linq; namespace ClosedXML.Excel { @@ -16,7 +15,7 @@ private Double _width; - #endregion + #endregion Private fields #region Constructor @@ -54,7 +53,7 @@ SetStyle(column.GetStyleId()); } - #endregion + #endregion Constructor public Boolean IsReference { get; private set; } @@ -297,9 +296,7 @@ public IXLColumn AdjustToContents(Int32 startRow, Int32 endRow, Double minWidth, Double maxWidth) { -#if _NETFRAMEWORK_ var fontCache = new Dictionary(); -#endif Double colMaxWidth = minWidth; @@ -323,14 +320,14 @@ { var kpList = new List>(); -#region if (c.HasRichText) + #region if (c.HasRichText) if (c.HasRichText) { foreach (IXLRichString rt in c.RichText) { String formattedString = rt.Text; - var arr = formattedString.Split(new[] {Environment.NewLine}, StringSplitOptions.None); + var arr = formattedString.Split(new[] { Environment.NewLine }, StringSplitOptions.None); Int32 arrCount = arr.Count(); for (Int32 i = 0; i < arrCount; i++) { @@ -344,7 +341,7 @@ else { String formattedString = c.GetFormattedString(); - var arr = formattedString.Split(new[] {Environment.NewLine}, StringSplitOptions.None); + var arr = formattedString.Split(new[] { Environment.NewLine }, StringSplitOptions.None); Int32 arrCount = arr.Count(); for (Int32 i = 0; i < arrCount; i++) { @@ -355,9 +352,9 @@ } } -#endregion + #endregion if (c.HasRichText) -#region foreach (var kp in kpList) + #region foreach (var kp in kpList) Double runningWidth = 0; Boolean rotated = false; @@ -371,65 +368,41 @@ Int32 newLinePosition = formattedString.IndexOf(Environment.NewLine); if (textRotation == 0) { -#region if (newLinePosition >= 0) + #region if (newLinePosition >= 0) if (newLinePosition >= 0) { if (newLinePosition > 0) -#if _NETFRAMEWORK_ runningWidth += f.GetWidth(formattedString.Substring(0, newLinePosition), fontCache); -#else - runningWidth += f.GetWidth(formattedString.Substring(0, newLinePosition)); -#endif if (runningWidth > thisWidthMax) thisWidthMax = runningWidth; runningWidth = newLinePosition < formattedString.Length - 2 -#if _NETFRAMEWORK_ ? f.GetWidth(formattedString.Substring(newLinePosition + 2), fontCache) -#else - ? f.GetWidth(formattedString.Substring(newLinePosition + 2)) -#endif : 0; } else -#if _NETFRAMEWORK_ runningWidth += f.GetWidth(formattedString, fontCache); -#else - runningWidth += f.GetWidth(formattedString); -#endif -#endregion + #endregion if (newLinePosition >= 0) } else { -#region if (textRotation == 255) + #region if (textRotation == 255) if (textRotation == 255) { if (runningWidth <= 0) -#if _NETFRAMEWORK_ runningWidth = f.GetWidth("X", fontCache); -#else - runningWidth = f.GetWidth("X"); -#endif if (newLinePosition >= 0) -#if _NETFRAMEWORK_ runningWidth += f.GetWidth("X", fontCache); -#else - runningWidth += f.GetWidth("X"); -#endif } else { rotated = true; -#if _NETFRAMEWORK_ Double vWidth = f.GetWidth("X", fontCache); -#else - Double vWidth = f.GetWidth("X"); -#endif if (vWidth > maxLineWidth) maxLineWidth = vWidth; @@ -438,41 +411,29 @@ lineCount++; if (newLinePosition > 0) -#if _NETFRAMEWORK_ runningWidth += f.GetWidth(formattedString.Substring(0, newLinePosition), fontCache); -#else - runningWidth += f.GetWidth(formattedString.Substring(0, newLinePosition)); -#endif if (runningWidth > thisWidthMax) thisWidthMax = runningWidth; runningWidth = newLinePosition < formattedString.Length - 2 -#if _NETFRAMEWORK_ ? f.GetWidth(formattedString.Substring(newLinePosition + 2), fontCache) -#else - ? f.GetWidth(formattedString.Substring(newLinePosition + 2)) -#endif : 0; } else -#if _NETFRAMEWORK_ runningWidth += f.GetWidth(formattedString, fontCache); -#else - runningWidth += f.GetWidth(formattedString); -#endif } -#endregion + #endregion if (textRotation == 255) } } -#endregion + #endregion foreach (var kp in kpList) if (runningWidth > thisWidthMax) thisWidthMax = runningWidth; -#region if (rotated) + #region if (rotated) if (rotated) { @@ -487,18 +448,14 @@ thisWidthMax = (thisWidthMax * Math.Cos(r)) + (maxLineWidth * lineCount); } -#endregion + #endregion if (rotated) } else -#if _NETFRAMEWORK_ thisWidthMax = c.Style.Font.GetWidth(c.GetFormattedString(), fontCache); -#else - thisWidthMax = c.Style.Font.GetWidth(c.GetFormattedString()); -#endif + if (autoFilterRows.Contains(c.Address.RowNumber)) thisWidthMax += 2.7148; // Allow room for arrow icon in autofilter - if (thisWidthMax >= maxWidth) { colMaxWidth = maxWidth; @@ -514,16 +471,13 @@ Width = colMaxWidth; -#if _NETFRAMEWORK_ foreach (IDisposable font in fontCache.Values) { font.Dispose(); } -#endif return this; } - public IXLColumn Hide() { IsHidden = true; @@ -634,19 +588,18 @@ return this; } - IXLRangeColumn IXLColumn.CopyTo(IXLCell target) { using (var asRange = AsRange()) - using (var copy = asRange.CopyTo(target)) - return copy.Column(1); + using (var copy = asRange.CopyTo(target)) + return copy.Column(1); } IXLRangeColumn IXLColumn.CopyTo(IXLRangeBase target) { using (var asRange = AsRange()) - using (var copy = asRange.CopyTo(target)) - return copy.Column(1); + using (var copy = asRange.CopyTo(target)) + return copy.Column(1); } public IXLColumn CopyTo(IXLColumn column) @@ -702,7 +655,7 @@ return Column(FirstCellUsed(includeFormats), LastCellUsed(includeFormats)); } -#endregion + #endregion IXLColumn Members public override XLRange AsRange() { @@ -764,13 +717,12 @@ return Math.PI * angle / 180.0; } - private XLColumn ColumnShift(Int32 columnsToShift) { return Worksheet.Column(ColumnNumber() + columnsToShift); } -#region XLColumn Left + #region XLColumn Left IXLColumn IXLColumn.ColumnLeft() { @@ -792,9 +744,9 @@ return ColumnShift(step * -1); } -#endregion + #endregion XLColumn Left -#region XLColumn Right + #region XLColumn Right IXLColumn IXLColumn.ColumnRight() { @@ -816,7 +768,7 @@ return ColumnShift(step); } -#endregion + #endregion XLColumn Right public override Boolean IsEmpty() { diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFColorScaleConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFColorScaleConverter.cs index 058d97d..ca1ce64 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFColorScaleConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFColorScaleConverter.cs @@ -1,13 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Spreadsheet; - -#if _NETSTANDARD_ -using ClosedXML.NetStandard; -#endif +using System; namespace ClosedXML.Excel { diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFDataBarConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFDataBarConverter.cs index 1daa86b..3feddcc 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFDataBarConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFDataBarConverter.cs @@ -1,13 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Spreadsheet; - -#if _NETSTANDARD_ -using ClosedXML.NetStandard; -#endif +using System; +using System.Linq; namespace ClosedXML.Excel { @@ -30,9 +23,11 @@ case XLColorType.Color: color.Rgb = cf.Colors[1].Color.ToHex(); break; + case XLColorType.Theme: color.Theme = System.Convert.ToUInt32(cf.Colors[1].ThemeColor); break; + case XLColorType.Indexed: color.Indexed = System.Convert.ToUInt32(cf.Colors[1].Indexed); break; diff --git a/ClosedXML/Excel/PageSetup/XLHFText.cs b/ClosedXML/Excel/PageSetup/XLHFText.cs index 78cb5a6..6659cd6 100644 --- a/ClosedXML/Excel/PageSetup/XLHFText.cs +++ b/ClosedXML/Excel/PageSetup/XLHFText.cs @@ -1,20 +1,18 @@ using System; using System.Text; -#if _NETSTANDARD_ -using ClosedXML.NetStandard; -#endif - namespace ClosedXML.Excel { internal class XLHFText { private readonly XLHFItem _hfItem; + public XLHFText(XLRichString richText, XLHFItem hfItem) { RichText = richText; _hfItem = hfItem; } + public XLRichString RichText { get; private set; } public String GetHFText(String prevText) @@ -102,6 +100,5 @@ return sb.ToString(); } - } } diff --git a/ClosedXML/Excel/Rows/XLRow.cs b/ClosedXML/Excel/Rows/XLRow.cs index 885ea62..e6aab85 100644 --- a/ClosedXML/Excel/Rows/XLRow.cs +++ b/ClosedXML/Excel/Rows/XLRow.cs @@ -43,7 +43,7 @@ _height = row._height; IsReference = row.IsReference; if (IsReference) - SubscribeToShiftedRows((range, rowShifted) => this.WorksheetRangeShiftedRows(range, rowShifted)); + SubscribeToShiftedRows((range, rowShifted) => this.WorksheetRangeShiftedRows(range, rowShifted)); _collapsed = row._collapsed; _isHidden = row._isHidden; @@ -284,9 +284,8 @@ public IXLRow AdjustToContents(Int32 startColumn, Int32 endColumn, Double minHeight, Double maxHeight) { -#if _NETFRAMEWORK_ var fontCache = new Dictionary(); -#endif + Double rowMaxHeight = minHeight; foreach (XLCell c in from XLCell c in Row(startColumn, endColumn).CellsUsed() where !c.IsMerged() select c) { @@ -300,7 +299,7 @@ foreach (IXLRichString rt in c.RichText) { String formattedString = rt.Text; - var arr = formattedString.Split(new[] {Environment.NewLine}, StringSplitOptions.None); + var arr = formattedString.Split(new[] { Environment.NewLine }, StringSplitOptions.None); Int32 arrCount = arr.Count(); for (Int32 i = 0; i < arrCount; i++) { @@ -314,7 +313,7 @@ else { String formattedString = c.GetFormattedString(); - var arr = formattedString.Split(new[] {Environment.NewLine}, StringSplitOptions.None); + var arr = formattedString.Split(new[] { Environment.NewLine }, StringSplitOptions.None); Int32 arrCount = arr.Count(); for (Int32 i = 0; i < arrCount; i++) { @@ -326,11 +325,7 @@ } Double maxLongCol = kpList.Max(kp => kp.Value.Length); -#if _NETFRAMEWORK_ Double maxHeightCol = kpList.Max(kp => kp.Key.GetHeight(fontCache)); -#else - Double maxHeightCol = kpList.Max(kp => kp.Key.GetHeight()); -#endif Int32 lineCount = kpList.Count(kp => kp.Value.Contains(Environment.NewLine)) + 1; if (textRotation == 0) thisHeight = maxHeightCol * lineCount; @@ -351,11 +346,8 @@ } } else -#if _NETFRAMEWORK_ thisHeight = c.Style.Font.GetHeight(fontCache); -#else - thisHeight = c.Style.Font.GetHeight(); -#endif + if (thisHeight >= maxHeight) { rowMaxHeight = maxHeight; @@ -370,12 +362,10 @@ Height = rowMaxHeight; -#if _NETFRAMEWORK_ foreach (IDisposable font in fontCache.Values) { font.Dispose(); } -#endif return this; } @@ -538,15 +528,15 @@ IXLRangeRow IXLRow.CopyTo(IXLCell target) { using (var asRange = AsRange()) - using (var copy = asRange.CopyTo(target)) - return copy.Row(1); + using (var copy = asRange.CopyTo(target)) + return copy.Row(1); } IXLRangeRow IXLRow.CopyTo(IXLRangeBase target) { using (var asRange = AsRange()) - using (var copy = asRange.CopyTo(target)) - return copy.Row(1); + using (var copy = asRange.CopyTo(target)) + return copy.Row(1); } public IXLRow CopyTo(IXLRow row) @@ -672,7 +662,7 @@ return Worksheet.Row(RowNumber() + rowsToShift); } -#region XLRow Above + #region XLRow Above IXLRow IXLRow.RowAbove() { @@ -696,7 +686,7 @@ #endregion XLRow Above -#region XLRow Below + #region XLRow Below IXLRow IXLRow.RowBelow() { @@ -741,6 +731,6 @@ public override Boolean IsEntireColumn() { return false; + } } } -} diff --git a/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs b/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs index a5aeafc..dcea153 100644 --- a/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs +++ b/ClosedXML/Excel/Style/Colors/XLColor_Internal.cs @@ -65,4 +65,4 @@ _colorType = XLColorType.Theme; } } -} \ No newline at end of file +} diff --git a/ClosedXML/Excel/Style/Colors/XLColor_Public.cs b/ClosedXML/Excel/Style/Colors/XLColor_Public.cs index 18f7fb6..ce6031a 100644 --- a/ClosedXML/Excel/Style/Colors/XLColor_Public.cs +++ b/ClosedXML/Excel/Style/Colors/XLColor_Public.cs @@ -1,10 +1,6 @@ using System; using System.Drawing; -#if _NETSTANDARD_ -using ClosedXML.NetStandard; -#endif - namespace ClosedXML.Excel { public enum XLColorType @@ -109,7 +105,7 @@ if (ColorType == XLColorType.Indexed) throw new InvalidOperationException("Cannot extract theme tint from an indexed color."); - return _color.A/255.0; + return _color.A / 255.0; } } @@ -136,11 +132,11 @@ return false; } - #endregion + #endregion IEquatable Members public override bool Equals(object obj) { - return Equals((XLColor) obj); + return Equals((XLColor)obj); } public override int GetHashCode() diff --git a/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/Excel/XLWorkbook_Load.cs index 89b4cb8..9b6d306 100644 --- a/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/Excel/XLWorkbook_Load.cs @@ -17,6 +17,7 @@ #if _NETSTANDARD_ using ClosedXML.NetStandard; #endif + namespace ClosedXML.Excel { using Ap; diff --git a/ClosedXML/Extensions.cs b/ClosedXML/Extensions.cs index c31768c..4be8ac5 100644 --- a/ClosedXML/Extensions.cs +++ b/ClosedXML/Extensions.cs @@ -208,30 +208,6 @@ public static class FontBaseExtensions { - -#if _NETSTANDARD_ - public static Double GetWidth(this IXLFontBase fontBase, String text) - { - // Calibri size 11's width of the @ character is 13.112628 - // @ is one of the widest regular characters - - var textWidth = text.Length * 13.112628 * fontBase.FontSize / 11f; - - double width = (textWidth / 7d * 256 - 128 / 7) / 256; - width = (double)decimal.Round((decimal)width + 0.2M, 2); - - return width; - } - - public static Double GetHeight(this IXLFontBase fontBase) - { - // Calibri size 11's height of the X character is 17.9036427 - var textHeight = 17.9036427 * fontBase.FontSize / 11f; - return (double)textHeight * 0.85; - } -#endif - -#if _NETFRAMEWORK_ public static Double GetWidth(this IXLFontBase fontBase, String text, Dictionary fontCache) { if (String.IsNullOrWhiteSpace(text)) @@ -246,14 +222,12 @@ return width; } - public static Double GetHeight(this IXLFontBase fontBase, Dictionary fontCache) { var font = GetCachedFont(fontBase, fontCache); var textHeight = GraphicsUtils.MeasureString("X", font).Height; return (double)textHeight * 0.85; } -#endif public static void CopyFont(this IXLFontBase font, IXLFontBase sourceFont) { @@ -269,7 +243,6 @@ font.FontFamilyNumbering = sourceFont.FontFamilyNumbering; } -#if _NETFRAMEWORK_ private static Font GetCachedFont(IXLFontBase fontBase, Dictionary fontCache) { Font font; @@ -290,7 +263,6 @@ if (font.Underline != XLFontUnderlineValues.None) fontStyle |= FontStyle.Underline; return fontStyle; } -#endif } public static class XDocumentExtensions diff --git a/ClosedXML/NetStandard/KnownColor.cs b/ClosedXML/NetStandard/KnownColor.cs deleted file mode 100644 index c65973e..0000000 --- a/ClosedXML/NetStandard/KnownColor.cs +++ /dev/null @@ -1,182 +0,0 @@ -#if _NETSTANDARD_ -namespace ClosedXML.Excel -{ - public enum KnownColor - { - ActiveBorder, - ActiveCaption, - ActiveCaptionText, - AliceBlue, - AntiqueWhite, - AppWorkspace, - Aqua, - Aquamarine, - Azure, - Beige, - Bisque, - Black, - BlanchedAlmond, - Blue, - BlueViolet, - Brown, - BurlyWood, - ButtonFace, - ButtonHighlight, - ButtonShadow, - CadetBlue, - Chartreuse, - Chocolate, - Control, - ControlDark, - ControlDarkDark, - ControlLight, - ControlLightLight, - ControlText, - Coral, - CornflowerBlue, - Cornsilk, - Crimson, - Cyan, - DarkBlue, - DarkCyan, - DarkGoldenrod, - DarkGray, - DarkGreen, - DarkKhaki, - DarkMagenta, - DarkOliveGreen, - DarkOrange, - DarkOrchid, - DarkRed, - DarkSalmon, - DarkSeaGreen, - DarkSlateBlue, - DarkSlateGray, - DarkTurquoise, - DarkViolet, - DeepPink, - DeepSkyBlue, - Desktop, - DimGray, - DodgerBlue, - Firebrick, - FloralWhite, - ForestGreen, - Fuchsia, - Gainsboro, - GhostWhite, - Gold, - Goldenrod, - GradientActiveCaption, - GradientInactiveCaption, - Gray, - GrayText, - Green, - GreenYellow, - Highlight, - HighlightText, - Honeydew, - HotPink, - HotTrack, - InactiveBorder, - InactiveCaption, - InactiveCaptionText, - IndianRed, - Indigo, - Info, - InfoText, - Ivory, - Khaki, - Lavender, - LavenderBlush, - LawnGreen, - LemonChiffon, - LightBlue, - LightCoral, - LightCyan, - LightGoldenrodYellow, - LightGray, - LightGreen, - LightPink, - LightSalmon, - LightSeaGreen, - LightSkyBlue, - LightSlateGray, - LightSteelBlue, - LightYellow, - Lime, - LimeGreen, - Linen, - Magenta, - Maroon, - MediumAquamarine, - MediumBlue, - MediumOrchid, - MediumPurple, - MediumSeaGreen, - MediumSlateBlue, - MediumSpringGreen, - MediumTurquoise, - MediumVioletRed, - Menu, - MenuBar, - MenuHighlight, - MenuText, - MidnightBlue, - MintCream, - MistyRose, - Moccasin, - NavajoWhite, - Navy, - OldLace, - Olive, - OliveDrab, - Orange, - OrangeRed, - Orchid, - PaleGoldenrod, - PaleGreen, - PaleTurquoise, - PaleVioletRed, - PapayaWhip, - PeachPuff, - Peru, - Pink, - Plum, - PowderBlue, - Purple, - Red, - RosyBrown, - RoyalBlue, - SaddleBrown, - Salmon, - SandyBrown, - ScrollBar, - SeaGreen, - SeaShell, - Sienna, - Silver, - SkyBlue, - SlateBlue, - SlateGray, - Snow, - SpringGreen, - SteelBlue, - Tan, - Teal, - Thistle, - Tomato, - Transparent, - Turquoise, - Violet, - Wheat, - White, - WhiteSmoke, - Window, - WindowFrame, - WindowText, - Yellow, - YellowGreen - } -} -#endif \ No newline at end of file diff --git a/ClosedXML/NetStandard/XLColorTranslator.cs b/ClosedXML/NetStandard/XLColorTranslator.cs index 112b978..257f909 100644 --- a/ClosedXML/NetStandard/XLColorTranslator.cs +++ b/ClosedXML/NetStandard/XLColorTranslator.cs @@ -1,16 +1,15 @@ #if _NETSTANDARD_ -using ClosedXML.Excel; + using System; using System.Collections.Generic; -using System.Text.RegularExpressions; using System.Drawing; +using System.Text.RegularExpressions; namespace ClosedXML.NetStandard { public class XLColorTranslator { private static IDictionary NAMED_COLOR_MAP = new Dictionary{ - //X11 Color Names (W3C color names) //Red color names {"indianred", Color.FromArgb(205, 92, 92)}, @@ -206,4 +205,5 @@ } } } + #endif diff --git a/ClosedXML/Utils/GraphicsUtils.cs b/ClosedXML/Utils/GraphicsUtils.cs index d9a4825..a4e79d2 100644 --- a/ClosedXML/Utils/GraphicsUtils.cs +++ b/ClosedXML/Utils/GraphicsUtils.cs @@ -5,9 +5,9 @@ { internal static class GraphicsUtils { -#if _NETFRAMEWORK_ [ThreadStatic] private static Graphics threadLocalGraphics; + internal static Graphics Graphics { get @@ -26,20 +26,5 @@ SizeF result = Graphics.MeasureString(s, font, Int32.MaxValue, StringFormat.GenericTypographic); return result; } -#else - - internal static Graphics Graphics = new Graphics(); -#endif } - -#if _NETSTANDARD_ - - // Stub structure for .NET Standard - internal struct Graphics - { - public float DpiX { get { return 96; } } - public float DpiY { get { return 96; } } - } - -#endif } diff --git a/ClosedXML_Tests/ClosedXML_Tests.csproj b/ClosedXML_Tests/ClosedXML_Tests.csproj index ea7d934..816d98d 100644 --- a/ClosedXML_Tests/ClosedXML_Tests.csproj +++ b/ClosedXML_Tests/ClosedXML_Tests.csproj @@ -30,7 +30,7 @@ - + diff --git a/ClosedXML_Tests/Excel/NetStandard/XLColorTranslatorTests.cs b/ClosedXML_Tests/Excel/NetStandard/XLColorTranslatorTests.cs index a90b410..52256d4 100644 --- a/ClosedXML_Tests/Excel/NetStandard/XLColorTranslatorTests.cs +++ b/ClosedXML_Tests/Excel/NetStandard/XLColorTranslatorTests.cs @@ -1,9 +1,7 @@ #if _NETSTANDARD_ -using ClosedXML.Excel; using ClosedXML.NetStandard; using NUnit.Framework; -using System.Linq; using System.Drawing; namespace ClosedXML_Tests.Excel.NetStandard @@ -14,8 +12,6 @@ [TestFixture] public class XLColorTranslatorTests { - - [Test] public void CanResolveFromHtmlColor() { @@ -41,4 +37,4 @@ } } -#endif \ No newline at end of file +#endif