[NWD] Further EPPlus fixes & improvements (take 2) - Fix conditional formatting and add a test spreadsheet - Remove System.Drawing dependency. With this change, the EPPlus library has no dependencies outside the base .NET Core library. - Remove ability to modify most styles Change-Id: Ida4fc1d946c8b99f7a35cab6ee1eeb503a2d8219 Reviewed-on: https://gnocchi-internal-review.git.corp.google.com/c/third_party/epplus/+/207701 Reviewed-by: Hughes Hilton <hugheshilton@google.com>
diff --git a/EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingDataBarGroup.cs b/EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingDataBarGroup.cs index 99a44a1..91abb7d 100644 --- a/EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingDataBarGroup.cs +++ b/EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingDataBarGroup.cs
@@ -29,8 +29,6 @@ * Eyal Seagull Conditional Formatting Adaption 2012-04-03 *******************************************************************************/ -using System.Drawing; - namespace OfficeOpenXml.ConditionalFormatting.Contracts; /// <summary> @@ -51,9 +49,4 @@ /// Databar High Value /// </summary> ExcelConditionalFormattingIconDataBarValue HighValue { get; } - - /// <summary> - /// The color of the databar - /// </summary> - Color Color { get; set; } }
diff --git a/EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingIconSetGroup.cs b/EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingIconSetGroup.cs index 700ffd6..770d75b 100644 --- a/EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingIconSetGroup.cs +++ b/EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingIconSetGroup.cs
@@ -44,9 +44,4 @@ /// ShowValue /// </summary> bool ShowValue { get; set; } - - /// <summary> - /// IconSet (3, 4 ou 5 IconSet) - /// </summary> - T IconSet { get; set; } }
diff --git a/EPPlus/ConditionalFormatting/Contracts/IRangeConditionalFormatting.cs b/EPPlus/ConditionalFormatting/Contracts/IRangeConditionalFormatting.cs index b2d99bf..bd84006 100644 --- a/EPPlus/ConditionalFormatting/Contracts/IRangeConditionalFormatting.cs +++ b/EPPlus/ConditionalFormatting/Contracts/IRangeConditionalFormatting.cs
@@ -29,7 +29,6 @@ * Eyal Seagull Conditional Formatting 2012-04-03 *******************************************************************************/ -using System.Drawing; using OfficeOpenXml.ConditionalFormatting.Contracts; namespace OfficeOpenXml.ConditionalFormatting; @@ -284,35 +283,4 @@ /// </summary> /// <returns></returns> IExcelConditionalFormattingTwoColorScale AddTwoColorScale(); - - /// <summary> - /// Adds a <see cref="IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType>"/> to the range - /// </summary> - /// <param name="iconSet"></param> - /// <returns></returns> - IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType> AddThreeIconSet( - eExcelconditionalFormatting3IconsSetType iconSet); - - /// <summary> - /// Adds a <see cref="IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType>"/> to the range - /// </summary> - /// <param name="iconSet"></param> - /// <returns></returns> - IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType> AddFourIconSet( - eExcelconditionalFormatting4IconsSetType iconSet); - - /// <summary> - /// Adds a <see cref="IExcelConditionalFormattingFiveIconSet"/> to the range - /// </summary> - /// <param name="iconSet"></param> - /// <returns></returns> - IExcelConditionalFormattingFiveIconSet AddFiveIconSet( - eExcelconditionalFormatting5IconsSetType iconSet); - - /// <summary> - /// Adds a <see cref="IExcelConditionalFormattingDataBarGroup"/> to the range - /// </summary> - /// <param name="color"></param> - /// <returns></returns> - IExcelConditionalFormattingDataBarGroup AddDatabar(Color color); }
diff --git a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingCollection.cs b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingCollection.cs index 8d0ecf1..08605aa 100644 --- a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingCollection.cs +++ b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingCollection.cs
@@ -29,10 +29,8 @@ * Eyal Seagull Conditional Formatting 2012-04-03 *******************************************************************************/ -using System; using System.Collections; using System.Collections.Generic; -using System.Drawing; using System.Xml; using OfficeOpenXml.ConditionalFormatting.Contracts; using OfficeOpenXml.Utils; @@ -777,66 +775,4 @@ eExcelConditionalFormattingRuleType.TwoColorScale, address); } - - /// <summary> - /// Add ThreeIconSet Rule - /// </summary> - /// <param name="address">The address</param> - /// <param name="iconSet">Type of iconset</param> - /// <returns></returns> - public IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType> AddThreeIconSet( - ExcelAddress address, - eExcelconditionalFormatting3IconsSetType iconSet) { - var icon = - (IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType>) - AddRule(eExcelConditionalFormattingRuleType.ThreeIconSet, address); - icon.IconSet = iconSet; - return icon; - } - - /// <summary> - /// Adds a FourIconSet rule - /// </summary> - /// <param name="address"></param> - /// <param name="iconSet"></param> - /// <returns></returns> - public IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType> AddFourIconSet( - ExcelAddress address, - eExcelconditionalFormatting4IconsSetType iconSet) { - var icon = - (IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType>) - AddRule(eExcelConditionalFormattingRuleType.FourIconSet, address); - icon.IconSet = iconSet; - return icon; - } - - /// <summary> - /// Adds a FiveIconSet rule - /// </summary> - /// <param name="address"></param> - /// <param name="iconSet"></param> - /// <returns></returns> - public IExcelConditionalFormattingFiveIconSet AddFiveIconSet( - ExcelAddress address, - eExcelconditionalFormatting5IconsSetType iconSet) { - var icon = (IExcelConditionalFormattingFiveIconSet)AddRule( - eExcelConditionalFormattingRuleType.FiveIconSet, - address); - icon.IconSet = iconSet; - return icon; - } - - /// <summary> - /// Adds a databar rule - /// </summary> - /// <param name="address"></param> - /// <param name="color"></param> - /// <returns></returns> - public IExcelConditionalFormattingDataBarGroup AddDatabar(ExcelAddress address, Color color) { - var dataBar = (IExcelConditionalFormattingDataBarGroup)AddRule( - eExcelConditionalFormattingRuleType.DataBar, - address); - dataBar.Color = color; - return dataBar; - } }
diff --git a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingColorScaleValue.cs b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingColorScaleValue.cs index a8585f0..84d8fb1 100644 --- a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingColorScaleValue.cs +++ b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingColorScaleValue.cs
@@ -30,7 +30,6 @@ *******************************************************************************/ using System; -using System.Drawing; using System.Xml; using OfficeOpenXml.Utils; @@ -63,7 +62,6 @@ internal ExcelConditionalFormattingColorScaleValue( eExcelConditionalFormattingValueObjectPosition position, eExcelConditionalFormattingValueObjectType type, - Color color, double value, string formula, eExcelConditionalFormattingRuleType ruleType, @@ -132,7 +130,6 @@ Position = position; RuleType = ruleType; Type = type; - Color = color; Value = value; Formula = formula; } @@ -153,7 +150,6 @@ internal ExcelConditionalFormattingColorScaleValue( eExcelConditionalFormattingValueObjectPosition position, eExcelConditionalFormattingValueObjectType type, - Color color, double value, string formula, eExcelConditionalFormattingRuleType ruleType, @@ -164,7 +160,6 @@ : this( position, type, - color, value, formula, ruleType, @@ -188,7 +183,6 @@ internal ExcelConditionalFormattingColorScaleValue( eExcelConditionalFormattingValueObjectPosition position, eExcelConditionalFormattingValueObjectType type, - Color color, eExcelConditionalFormattingRuleType ruleType, ExcelAddress address, int priority, @@ -197,7 +191,6 @@ : this( position, type, - color, 0, null, ruleType, @@ -351,32 +344,6 @@ } /// <summary> - /// - /// </summary> - public Color Color { - get { - // Color Code like "FF5B34F2" - var colorCode = GetXmlNodeString( - string.Format( - "{0}[position()={1}]/{2}", - // {0} - ExcelConditionalFormattingConstants.Paths._color, - // {1} - GetNodeOrder(), - // {2} - ExcelConditionalFormattingConstants.Paths._rgbAttribute)); - - return ExcelConditionalFormattingHelper.ConvertFromColorCode(colorCode); - } - set => - // Use the color code to store (Ex. "FF5B35F2") - CreateNodeByOrdem( - eExcelConditionalFormattingValueObjectNodeType.Color, - ExcelConditionalFormattingConstants.Paths._rgbAttribute, - value.ToArgb().ToString("x")); - } - - /// <summary> /// Get/Set the 'cfvo' node @val attribute /// </summary> public Double Value {
diff --git a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingHelper.cs b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingHelper.cs index 0ea9a45..ba97c3d 100644 --- a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingHelper.cs +++ b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingHelper.cs
@@ -30,7 +30,6 @@ *******************************************************************************/ using System; -using System.Drawing; using System.Globalization; using System.Text.RegularExpressions; using System.Xml; @@ -63,20 +62,6 @@ } /// <summary> - /// Convert a color code to Color Object - /// </summary> - /// <param name="colorCode">Color Code (Ex. "#FFB43C53" or "FFB43C53")</param> - /// <returns></returns> - public static Color ConvertFromColorCode(string colorCode) { - try { - return Color.FromArgb(Int32.Parse(colorCode.Replace("#", ""), NumberStyles.HexNumber)); - } catch { - // Assume white is the default color (instead of giving an error) - return Color.White; - } - } - - /// <summary> /// /// </summary> /// <param name="node"></param>
diff --git a/EPPlus/ConditionalFormatting/RangeConditionalFormatting.cs b/EPPlus/ConditionalFormatting/RangeConditionalFormatting.cs index debf061..6fcc305 100644 --- a/EPPlus/ConditionalFormatting/RangeConditionalFormatting.cs +++ b/EPPlus/ConditionalFormatting/RangeConditionalFormatting.cs
@@ -29,7 +29,6 @@ * Eyal Seagull Conditional Formatting 2012-04-03 *******************************************************************************/ -using System.Drawing; using OfficeOpenXml.ConditionalFormatting.Contracts; using OfficeOpenXml.Utils; @@ -378,61 +377,4 @@ eExcelConditionalFormattingRuleType.TwoColorScale, _address)); } - - /// <summary> - /// Adds a ThreeIconSet rule - /// </summary> - /// <param name="iconSet"></param> - /// <returns></returns> - public IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType> AddThreeIconSet( - eExcelconditionalFormatting3IconsSetType iconSet) { - var rule = - (IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType>)(_worksheet.ConditionalFormatting.AddRule( - eExcelConditionalFormattingRuleType.ThreeIconSet, - _address)); - rule.IconSet = iconSet; - return rule; - } - - /// <summary> - /// Adds a FourIconSet rule - /// </summary> - /// <param name="iconSet"></param> - /// <returns></returns> - public IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType> AddFourIconSet( - eExcelconditionalFormatting4IconsSetType iconSet) { - var rule = - (IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType>)(_worksheet.ConditionalFormatting.AddRule( - eExcelConditionalFormattingRuleType.FourIconSet, - _address)); - rule.IconSet = iconSet; - return rule; - } - - /// <summary> - /// Adds a FiveIconSet rule - /// </summary> - /// <param name="iconSet"></param> - /// <returns></returns> - public IExcelConditionalFormattingFiveIconSet AddFiveIconSet( - eExcelconditionalFormatting5IconsSetType iconSet) { - var rule = (IExcelConditionalFormattingFiveIconSet)(_worksheet.ConditionalFormatting.AddRule( - eExcelConditionalFormattingRuleType.FiveIconSet, - _address)); - rule.IconSet = iconSet; - return rule; - } - - /// <summary> - /// Adds a Databar rule - /// </summary> - /// <param name="color">The color of the databar</param> - /// <returns></returns> - public IExcelConditionalFormattingDataBarGroup AddDatabar(Color color) { - var rule = (IExcelConditionalFormattingDataBarGroup)(_worksheet.ConditionalFormatting.AddRule( - eExcelConditionalFormattingRuleType.DataBar, - _address)); - rule.Color = color; - return rule; - } }
diff --git a/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingDataBar.cs b/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingDataBar.cs index 2a80337..8ca4be2 100644 --- a/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingDataBar.cs +++ b/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingDataBar.cs
@@ -29,7 +29,6 @@ * Eyal Seagull Added 2012-04-03 *******************************************************************************/ -using System.Drawing; using System.Globalization; using System.Xml; using OfficeOpenXml.ConditionalFormatting.Contracts; @@ -153,17 +152,4 @@ public ExcelConditionalFormattingIconDataBarValue LowValue { get; internal set; } public ExcelConditionalFormattingIconDataBarValue HighValue { get; internal set; } - - private const string _colorPath = "d:dataBar/d:color/@rgb"; - - public Color Color { - get { - var rgb = GetXmlNodeString(_colorPath); - if (!string.IsNullOrEmpty(rgb)) { - return Color.FromArgb(int.Parse(rgb, NumberStyles.HexNumber)); - } - return Color.White; - } - set => SetXmlNodeString(_colorPath, value.ToArgb().ToString("X")); - } }
diff --git a/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingThreeColorScale.cs b/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingThreeColorScale.cs index fa0574e..5700e10 100644 --- a/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingThreeColorScale.cs +++ b/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingThreeColorScale.cs
@@ -71,7 +71,6 @@ LowValue = new( eExcelConditionalFormattingValueObjectPosition.Low, eExcelConditionalFormattingValueObjectType.Min, - ColorTranslator.FromHtml(ExcelConditionalFormattingConstants.Colors._cfvoLowValue), eExcelConditionalFormattingRuleType.ThreeColorScale, address, priority, @@ -82,7 +81,6 @@ MiddleValue = new( eExcelConditionalFormattingValueObjectPosition.Middle, eExcelConditionalFormattingValueObjectType.Percent, - ColorTranslator.FromHtml(ExcelConditionalFormattingConstants.Colors._cfvoMiddleValue), 50, string.Empty, eExcelConditionalFormattingRuleType.ThreeColorScale, @@ -95,7 +93,6 @@ HighValue = new( eExcelConditionalFormattingValueObjectPosition.High, eExcelConditionalFormattingValueObjectType.Max, - ColorTranslator.FromHtml(ExcelConditionalFormattingConstants.Colors._cfvoHighValue), eExcelConditionalFormattingRuleType.ThreeColorScale, address, priority,
diff --git a/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingThreeIconSet.cs b/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingThreeIconSet.cs index 2b8b27e..bcf19e1 100644 --- a/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingThreeIconSet.cs +++ b/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingThreeIconSet.cs
@@ -223,18 +223,6 @@ private const string _iconSetPath = "d:iconSet/@iconSet"; - /// <summary> - /// Type of iconset - /// </summary> - public T IconSet { - get { - var v = GetXmlNodeString(_iconSetPath); - v = v.Substring(1); //Skip first icon. - return (T)Enum.Parse(typeof(T), v, true); - } - set => SetXmlNodeString(_iconSetPath, GetIconSetString(value)); - } - private string GetIconSetString(T value) { if (Type == eExcelConditionalFormattingRuleType.FourIconSet) { switch (value.ToString()) {
diff --git a/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingTwoColorScale.cs b/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingTwoColorScale.cs index 69ee8b1..ad7d79f 100644 --- a/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingTwoColorScale.cs +++ b/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingTwoColorScale.cs
@@ -81,7 +81,6 @@ LowValue = new( eExcelConditionalFormattingValueObjectPosition.Low, eExcelConditionalFormattingValueObjectType.Min, - ColorTranslator.FromHtml(ExcelConditionalFormattingConstants.Colors._cfvoLowValue), eExcelConditionalFormattingRuleType.TwoColorScale, address, priority, @@ -92,7 +91,6 @@ HighValue = new( eExcelConditionalFormattingValueObjectPosition.High, eExcelConditionalFormattingValueObjectType.Max, - ColorTranslator.FromHtml(ExcelConditionalFormattingConstants.Colors._cfvoHighValue), eExcelConditionalFormattingRuleType.TwoColorScale, address, priority,
diff --git a/EPPlus/DataValidation/Contracts/IExcelDataValidation.cs b/EPPlus/DataValidation/Contracts/IExcelDataValidation.cs index 44b5d3e..7917008 100644 --- a/EPPlus/DataValidation/Contracts/IExcelDataValidation.cs +++ b/EPPlus/DataValidation/Contracts/IExcelDataValidation.cs
@@ -49,7 +49,7 @@ /// <summary> /// Controls how Excel will handle invalid values. /// </summary> - ExcelDataValidationWarningStyle ErrorStyle { get; set; } + ExcelDataValidationWarningStyle ErrorStyle { get; } /// <summary> /// True if input message should be shown
diff --git a/EPPlus/DataValidation/Contracts/IExcelDataValidationWithOperator.cs b/EPPlus/DataValidation/Contracts/IExcelDataValidationWithOperator.cs index 48b06cb..2604079 100644 --- a/EPPlus/DataValidation/Contracts/IExcelDataValidationWithOperator.cs +++ b/EPPlus/DataValidation/Contracts/IExcelDataValidationWithOperator.cs
@@ -39,5 +39,5 @@ /// <summary> /// Operator type /// </summary> - ExcelDataValidationOperator Operator { get; set; } + ExcelDataValidationOperator Operator { get; } }
diff --git a/EPPlus/DataValidation/ExcelDataValidation.cs b/EPPlus/DataValidation/ExcelDataValidation.cs index 78b6259..88a60de 100644 --- a/EPPlus/DataValidation/ExcelDataValidation.cs +++ b/EPPlus/DataValidation/ExcelDataValidation.cs
@@ -199,18 +199,9 @@ public ExcelDataValidationOperator Operator { get { var operatorString = GetXmlNodeString(_operatorPath); - if (!string.IsNullOrEmpty(operatorString)) { - return (ExcelDataValidationOperator) - Enum.Parse(typeof(ExcelDataValidationOperator), operatorString); - } - return default(ExcelDataValidationOperator); - } - set { - if (!ValidationType.AllowOperator) { - throw new InvalidOperationException( - "The current validation type does not allow operator to be set"); - } - SetXmlNodeString(_operatorPath, value.ToString()); + return Enum.TryParse<ExcelDataValidationOperator>(operatorString, true, out var op) + ? op + : ExcelDataValidationOperator.Any; } } @@ -220,17 +211,9 @@ public ExcelDataValidationWarningStyle ErrorStyle { get { var errorStyleString = GetXmlNodeString(_errorStylePath); - if (!string.IsNullOrEmpty(errorStyleString)) { - return (ExcelDataValidationWarningStyle) - Enum.Parse(typeof(ExcelDataValidationWarningStyle), errorStyleString); - } - return ExcelDataValidationWarningStyle.Undefined; - } - set { - if (value == ExcelDataValidationWarningStyle.Undefined) { - DeleteNode(_errorStylePath); - } - SetXmlNodeString(_errorStylePath, value.ToString()); + return Enum.TryParse<ExcelDataValidationWarningStyle>(errorStyleString, true, out var style) + ? style + : ExcelDataValidationWarningStyle.Undefined; } }
diff --git a/EPPlus/DataValidation/ExcelDataValidationType.cs b/EPPlus/DataValidation/ExcelDataValidationType.cs index 1c7465c..cdcc99c 100644 --- a/EPPlus/DataValidation/ExcelDataValidationType.cs +++ b/EPPlus/DataValidation/ExcelDataValidationType.cs
@@ -116,34 +116,6 @@ /// </summary> internal bool AllowOperator { get; private set; } - /// <summary> - /// Returns a validation type by <see cref="eDataValidationType"/> - /// </summary> - /// <param name="type"></param> - /// <returns></returns> - internal static ExcelDataValidationType GetByValidationType(eDataValidationType type) { - switch (type) { - case eDataValidationType.Any: - return Any; - case eDataValidationType.Whole: - return Whole; - case eDataValidationType.List: - return List; - case eDataValidationType.Decimal: - return Decimal; - case eDataValidationType.TextLength: - return TextLength; - case eDataValidationType.DateTime: - return DateTime; - case eDataValidationType.Time: - return Time; - case eDataValidationType.Custom: - return Custom; - default: - throw new InvalidOperationException("Non supported Validationtype : " + type); - } - } - internal static ExcelDataValidationType GetBySchemaName(string schemaName) { switch (schemaName) { case DataValidationSchemaNames.Any:
diff --git a/EPPlus/Drawing/Vml/ExcelVmlDrawingComment.cs b/EPPlus/Drawing/Vml/ExcelVmlDrawingComment.cs index 3392fc7..bd137cd 100644 --- a/EPPlus/Drawing/Vml/ExcelVmlDrawingComment.cs +++ b/EPPlus/Drawing/Vml/ExcelVmlDrawingComment.cs
@@ -30,9 +30,6 @@ * Jan Källman License changed GPL-->LGPL 2011-12-16 *******************************************************************************/ -using System; -using System.Drawing; -using System.Globalization; using System.Xml; namespace OfficeOpenXml.Drawing.Vml; @@ -152,179 +149,6 @@ } } - private const string _backgroundcolorPath = "@fillcolor"; - - /// <summary> - /// Background color - /// </summary> - public Color BackgroundColor { - get { - string col = GetXmlNodeString(_backgroundcolorPath); - if (col == "") { - return Color.FromArgb(0xff, 0xff, 0xe1); - } - if (col.StartsWith("#")) { - col = col.Substring(1, col.Length - 1); - } - if (int.TryParse( - col, - NumberStyles.AllowHexSpecifier, - CultureInfo.InvariantCulture, - out var res)) { - return Color.FromArgb(res); - } - return Color.Empty; - } - set { - string color = "#" + value.ToArgb().ToString("X").Substring(2, 6); - SetXmlNodeString(_backgroundcolorPath, color); - //SetXmlNode(BACKGROUNDCOLOR2_PATH, color); - } - } - - private const string _linestylePath = "v:stroke/@dashstyle"; - private const string _endcapPath = "v:stroke/@endcap"; - - /// <summary> - /// Linestyle for border - /// </summary> - public eLineStyleVml LineStyle { - get { - string v = GetXmlNodeString(_linestylePath); - if (v == "") { - return eLineStyleVml.Solid; - } - if (v == "1 1") { - v = GetXmlNodeString(_endcapPath); - return (eLineStyleVml)Enum.Parse(typeof(eLineStyleVml), v, true); - } - return (eLineStyleVml)Enum.Parse(typeof(eLineStyleVml), v, true); - } - set { - if (value == eLineStyleVml.Round || value == eLineStyleVml.Square) { - SetXmlNodeString(_linestylePath, "1 1"); - if (value == eLineStyleVml.Round) { - SetXmlNodeString(_endcapPath, "round"); - } else { - DeleteNode(_endcapPath); - } - } else { - string v = value.ToString(); - v = v.Substring(0, 1).ToLower(CultureInfo.InvariantCulture) + v.Substring(1, v.Length - 1); - SetXmlNodeString(_linestylePath, v); - DeleteNode(_endcapPath); - } - } - } - - private const string _linecolorPath = "@strokecolor"; - - /// <summary> - /// Line color - /// </summary> - public Color LineColor { - get { - string col = GetXmlNodeString(_linecolorPath); - if (col == "") { - return Color.Black; - } - if (col.StartsWith("#")) { - col = col.Substring(1, col.Length - 1); - } - if (int.TryParse( - col, - NumberStyles.AllowHexSpecifier, - CultureInfo.InvariantCulture, - out var res)) { - return Color.FromArgb(res); - } - return Color.Empty; - } - set { - string color = "#" + value.ToArgb().ToString("X").Substring(2, 6); - SetXmlNodeString(_linecolorPath, color); - } - } - - private const string _linewidthPath = "@strokeweight"; - - /// <summary> - /// Width of the border - /// </summary> - public Single LineWidth { - get { - string wt = GetXmlNodeString(_linewidthPath); - if (wt == "") { - return (Single).75; - } - if (wt.EndsWith("pt")) { - wt = wt.Substring(0, wt.Length - 2); - } - - if (Single.TryParse(wt, NumberStyles.Any, CultureInfo.InvariantCulture, out var ret)) { - return ret; - } - return 0; - } - set => SetXmlNodeString(_linewidthPath, value.ToString(CultureInfo.InvariantCulture) + "pt"); - } - - ///// <summary> - ///// Width of the Comment - ///// </summary> - //public Single Width - //{ - // get - // { - // string v; - // GetStyle("width", out v); - // if(v.EndsWith("pt")) - // { - // v = v.Substring(0, v.Length - 2); - // } - // short ret; - // if (short.TryParse(v,System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out ret)) - // { - // return ret; - // } - // else - // { - // return 0; - // } - // } - // set - // { - // SetStyle("width", value.ToString("N2",CultureInfo.InvariantCulture) + "pt"); - // } - //} - ///// <summary> - ///// Height of the Comment - ///// </summary> - //public Single Height - //{ - // get - // { - // string v; - // GetStyle("height", out v); - // if (v.EndsWith("pt")) - // { - // v = v.Substring(0, v.Length - 2); - // } - // short ret; - // if (short.TryParse(v, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out ret)) - // { - // return ret; - // } - // else - // { - // return 0; - // } - // } - // set - // { - // SetStyle("height", value.ToString("N2", CultureInfo.InvariantCulture) + "pt"); - // } - //} private const string _textboxStylePath = "v:textbox/@style"; /// <summary>
diff --git a/EPPlus/EPPlusSDK.csproj b/EPPlus/EPPlusSDK.csproj index a26851d..2cdc079 100644 --- a/EPPlus/EPPlusSDK.csproj +++ b/EPPlus/EPPlusSDK.csproj
@@ -4,9 +4,6 @@ <RootNamespace>OfficeOpenXml</RootNamespace> <AssemblyName>EPPlus</AssemblyName> <PackageId>Appsheet.EPPlus</PackageId> - <Version>1.0.6</Version> + <Version>1.0.5</Version> </PropertyGroup> - <ItemGroup> - <PackageReference Include="System.Drawing.Common" Version="6.0.0"/> - </ItemGroup> </Project>
diff --git a/EPPlus/ExcelComment.cs b/EPPlus/ExcelComment.cs index 9e7409a..3930bde 100644 --- a/EPPlus/ExcelComment.cs +++ b/EPPlus/ExcelComment.cs
@@ -124,7 +124,6 @@ } return _text; } - set => RichText.Text = value; } /// <summary>
diff --git a/EPPlus/ExcelCommentCollection.cs b/EPPlus/ExcelCommentCollection.cs index b4a60af..9146df7 100644 --- a/EPPlus/ExcelCommentCollection.cs +++ b/EPPlus/ExcelCommentCollection.cs
@@ -138,79 +138,9 @@ } } - /// <summary> - /// Adds a comment to the top left cell of the range - /// </summary> - /// <param name="cell">The cell</param> - /// <param name="text">The comment text</param> - /// <param name="author">Author</param> - /// <returns>The comment</returns> - public ExcelComment Add(ExcelRangeBase cell, string text, string author) { - var elem = CommentXml.CreateElement("comment", ExcelPackage._schemaMain); - int ix = _comments.IndexOf( - ExcelCellBase.GetCellId(Worksheet.SheetID, cell._fromRow, cell._fromCol)); - //Make sure the nodes come on order. - if (ix < 0 && (~ix < _comments.Count)) { - ix = ~ix; - var preComment = _comments[ix] as ExcelComment; - preComment._commentHelper.TopNode.ParentNode.InsertBefore( - elem, - preComment._commentHelper.TopNode); - } else { - CommentXml.SelectSingleNode("d:comments/d:commentList", NameSpaceManager).AppendChild(elem); - } - elem.SetAttribute("ref", cell.Start.Address); - ExcelComment comment = new ExcelComment(NameSpaceManager, elem, cell); - comment.RichText.Add(text); - if (author != "") { - comment.Author = author; - } - _comments.Add(comment); - //Check if a value exists otherwise add one so it is saved when the cells collection is iterated - if (!Worksheet._values.Exists(cell._fromRow, cell._fromCol)) { - Worksheet._values.SetValue(cell._fromRow, cell._fromCol, null); - } - return comment; - } - - /// <summary> - /// Removes the comment - /// </summary> - /// <param name="comment">The comment to remove</param> - public void Remove(ExcelComment comment) { - ulong id = ExcelCellBase.GetCellId( - Worksheet.SheetID, - comment.Range._fromRow, - comment.Range._fromCol); - int ix = _comments.IndexOf(id); - if (ix >= 0 && comment == _comments[ix]) { - comment.TopNode.ParentNode.RemoveChild(comment.TopNode); //Remove VML - comment._commentHelper.TopNode.ParentNode.RemoveChild(comment._commentHelper.TopNode); //Remove Comment - - Worksheet.VmlDrawingsComments._drawings.Delete(id); - _comments.Delete(id); - } else { - throw (new ArgumentException("Comment does not exist in the worksheet")); - } - } - void IDisposable.Dispose() {} - /// <summary> - /// Removes the comment at the specified position - /// </summary> - /// <param name="index">The index</param> - public void RemoveAt(int index) { - Remove(this[index]); - } - IEnumerator IEnumerable.GetEnumerator() { return _comments; } - - internal void Clear() { - while (Count > 0) { - RemoveAt(0); - } - } }
diff --git a/EPPlus/ExcelPrinterSettings.cs b/EPPlus/ExcelPrinterSettings.cs deleted file mode 100644 index dcdb541..0000000 --- a/EPPlus/ExcelPrinterSettings.cs +++ /dev/null
@@ -1,773 +0,0 @@ -/******************************************************************************* - * You may amend and distribute as you like, but don't remove this header! - * - * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets. - * See http://www.codeplex.com/EPPlus for details. - * - * Copyright (C) 2011 Jan Källman - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php - * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html - * - * All code and executables are provided "as is" with no warranty either express or implied. - * The author accepts no liability for any damage or loss of business that this product may cause. - * - * Code change notes: - * - * Author Change Date - * ****************************************************************************** - * Jan Källman Initial Release 2009-10-01 - * Jan Källman License changed GPL-->LGPL 2011-12-27 - *******************************************************************************/ - -using System; -using System.Globalization; -using System.Xml; - -namespace OfficeOpenXml; - -/// <summary> -/// Printer orientation -/// </summary> -public enum eOrientation { - /// <summary> - /// Portrait orientation - /// </summary> - Portrait, - - /// <summary> - /// Landscape orientation - /// </summary> - Landscape, -} - -/// <summary> -/// Papersize -/// </summary> -public enum ePaperSize { - /// <summary> - /// Letter paper (8.5 in. by 11 in.) - /// </summary> - Letter = 1, - - /// <summary> - /// Letter small paper (8.5 in. by 11 in.) - /// </summary> - LetterSmall = 2, - - /// <summary> - /// // Tabloid paper (11 in. by 17 in.) - /// </summary> - Tabloid = 3, - - /// <summary> - /// Ledger paper (17 in. by 11 in.) - /// </summary> - Ledger = 4, - - /// <summary> - /// Legal paper (8.5 in. by 14 in.) - /// </summary> - Legal = 5, - - /// <summary> - /// Statement paper (5.5 in. by 8.5 in.) - /// </summary> - Statement = 6, - - /// <summary> - /// Executive paper (7.25 in. by 10.5 in.) - /// </summary> - Executive = 7, - - /// <summary> - /// A3 paper (297 mm by 420 mm) - /// </summary> - A3 = 8, - - /// <summary> - /// A4 paper (210 mm by 297 mm) - /// </summary> - A4 = 9, - - /// <summary> - /// A4 small paper (210 mm by 297 mm) - /// </summary> - A4Small = 10, - - /// <summary> - /// A5 paper (148 mm by 210 mm) - /// </summary> - A5 = 11, - - /// <summary> - /// B4 paper (250 mm by 353 mm) - /// </summary> - B4 = 12, - - /// <summary> - /// B5 paper (176 mm by 250 mm) - /// </summary> - B5 = 13, - - /// <summary> - /// Folio paper (8.5 in. by 13 in.) - /// </summary> - Folio = 14, - - /// <summary> - /// Quarto paper (215 mm by 275 mm) - /// </summary> - Quarto = 15, - - /// <summary> - /// Standard paper (10 in. by 14 in.) - /// </summary> - Standard1014 = 16, - - /// <summary> - /// Standard paper (11 in. by 17 in.) - /// </summary> - Standard1117 = 17, - - /// <summary> - /// Note paper (8.5 in. by 11 in.) - /// </summary> - Note = 18, - - /// <summary> - /// #9 envelope (3.875 in. by 8.875 in.) - /// </summary> - Envelope9 = 19, - - /// <summary> - /// #10 envelope (4.125 in. by 9.5 in.) - /// </summary> - Envelope10 = 20, - - /// <summary> - /// #11 envelope (4.5 in. by 10.375 in.) - /// </summary> - Envelope11 = 21, - - /// <summary> - /// #12 envelope (4.75 in. by 11 in.) - /// </summary> - Envelope12 = 22, - - /// <summary> - /// #14 envelope (5 in. by 11.5 in.) - /// </summary> - Envelope14 = 23, - - /// <summary> - /// C paper (17 in. by 22 in.) - /// </summary> - C = 24, - - /// <summary> - /// D paper (22 in. by 34 in.) - /// </summary> - D = 25, - - /// <summary> - /// E paper (34 in. by 44 in.) - /// </summary> - E = 26, - - /// <summary> - /// DL envelope (110 mm by 220 mm) - /// </summary> - DlEnvelope = 27, - - /// <summary> - /// C5 envelope (162 mm by 229 mm) - /// </summary> - C5Envelope = 28, - - /// <summary> - /// C3 envelope (324 mm by 458 mm) - /// </summary> - C3Envelope = 29, - - /// <summary> - /// C4 envelope (229 mm by 324 mm) - /// </summary> - C4Envelope = 30, - - /// <summary> - /// C6 envelope (114 mm by 162 mm) - /// </summary> - C6Envelope = 31, - - /// <summary> - /// C65 envelope (114 mm by 229 mm) - /// </summary> - C65Envelope = 32, - - /// <summary> - /// B4 envelope (250 mm by 353 mm) - /// </summary> - B4Envelope = 33, - - /// <summary> - /// B5 envelope (176 mm by 250 mm) - /// </summary> - B5Envelope = 34, - - /// <summary> - /// B6 envelope (176 mm by 125 mm) - /// </summary> - B6Envelope = 35, - - /// <summary> - /// Italy envelope (110 mm by 230 mm) - /// </summary> - ItalyEnvelope = 36, - - /// <summary> - /// Monarch envelope (3.875 in. by 7.5 in.). - /// </summary> - MonarchEnvelope = 37, - - /// <summary> - /// 6 3/4 envelope (3.625 in. by 6.5 in.) - /// </summary> - Six34Envelope = 38, - - /// <summary> - /// US standard fanfold (14.875 in. by 11 in.) - /// </summary> - UsStandard = 39, - - /// <summary> - /// German standard fanfold (8.5 in. by 12 in.) - /// </summary> - GermanStandard = 40, - - /// <summary> - /// German legal fanfold (8.5 in. by 13 in.) - /// </summary> - GermanLegal = 41, - - /// <summary> - /// ISO B4 (250 mm by 353 mm) - /// </summary> - Isob4 = 42, - - /// <summary> - /// Japanese double postcard (200 mm by 148 mm) - /// </summary> - JapaneseDoublePostcard = 43, - - /// <summary> - /// Standard paper (9 in. by 11 in.) - /// </summary> - Standard9 = 44, - - /// <summary> - /// Standard paper (10 in. by 11 in.) - /// </summary> - Standard10 = 45, - - /// <summary> - /// Standard paper (15 in. by 11 in.) - /// </summary> - Standard15 = 46, - - /// <summary> - /// Invite envelope (220 mm by 220 mm) - /// </summary> - InviteEnvelope = 47, - - /// <summary> - /// Letter extra paper (9.275 in. by 12 in.) - /// </summary> - LetterExtra = 50, - - /// <summary> - /// Legal extra paper (9.275 in. by 15 in.) - /// </summary> - LegalExtra = 51, - - /// <summary> - /// Tabloid extra paper (11.69 in. by 18 in.) - /// </summary> - TabloidExtra = 52, - - /// <summary> - /// A4 extra paper (236 mm by 322 mm) - /// </summary> - A4Extra = 53, - - /// <summary> - /// Letter transverse paper (8.275 in. by 11 in.) - /// </summary> - LetterTransverse = 54, - - /// <summary> - /// A4 transverse paper (210 mm by 297 mm) - /// </summary> - A4Transverse = 55, - - /// <summary> - /// Letter extra transverse paper (9.275 in. by 12 in.) - /// </summary> - LetterExtraTransverse = 56, - - /// <summary> - /// SuperA/SuperA/A4 paper (227 mm by 356 mm) - /// </summary> - SuperA = 57, - - /// <summary> - /// SuperB/SuperB/A3 paper (305 mm by 487 mm) - /// </summary> - SuperB = 58, - - /// <summary> - /// Letter plus paper (8.5 in. by 12.69 in.) - /// </summary> - LetterPlus = 59, - - /// <summary> - /// A4 plus paper (210 mm by 330 mm) - /// </summary> - A4Plus = 60, - - /// <summary> - /// A5 transverse paper (148 mm by 210 mm) - /// </summary> - A5Transverse = 61, - - /// <summary> - /// JIS B5 transverse paper (182 mm by 257 mm) - /// </summary> - Jisb5Transverse = 62, - - /// <summary> - /// A3 extra paper (322 mm by 445 mm) - /// </summary> - A3Extra = 63, - - /// <summary> - /// A5 extra paper (174 mm by 235 mm) - /// </summary> - A5Extra = 64, - - /// <summary> - /// ISO B5 extra paper (201 mm by 276 mm) - /// </summary> - Isob5 = 65, - - /// <summary> - /// A2 paper (420 mm by 594 mm) - /// </summary> - A2 = 66, - - /// <summary> - /// A3 transverse paper (297 mm by 420 mm) - /// </summary> - A3Transverse = 67, - - /// <summary> - /// A3 extra transverse paper (322 mm by 445 mm*/ - /// </summary> - A3ExtraTransverse = 68, -} - -/// <summary> -/// Specifies printed page order -/// </summary> -public enum ePageOrder { - /// <summary> - /// Order pages vertically first, then move horizontally. - /// </summary> - DownThenOver, - - /// <summary> - /// Order pages horizontally first, then move vertically - /// </summary> - OverThenDown, -} - -/// <summary> -/// Printer settings -/// </summary> -public sealed class ExcelPrinterSettings : XmlHelper { - private readonly ExcelWorksheet _ws; - private bool _marginsCreated; - - internal ExcelPrinterSettings(XmlNamespaceManager ns, XmlNode topNode, ExcelWorksheet ws) - : base(ns, topNode) { - _ws = ws; - SchemaNodeOrder = ws.SchemaNodeOrder; - } - - private const string _leftMarginPath = "d:pageMargins/@left"; - - /// <summary> - /// Left margin in inches - /// </summary> - public decimal LeftMargin { - get => GetXmlNodeDecimal(_leftMarginPath); - set { - CreateMargins(); - SetXmlNodeString(_leftMarginPath, value.ToString(CultureInfo.InvariantCulture)); - } - } - - private const string _rightMarginPath = "d:pageMargins/@right"; - - /// <summary> - /// Right margin in inches - /// </summary> - public decimal RightMargin { - get => GetXmlNodeDecimal(_rightMarginPath); - set { - CreateMargins(); - SetXmlNodeString(_rightMarginPath, value.ToString(CultureInfo.InvariantCulture)); - } - } - - private const string _topMarginPath = "d:pageMargins/@top"; - - /// <summary> - /// Top margin in inches - /// </summary> - public decimal TopMargin { - get => GetXmlNodeDecimal(_topMarginPath); - set { - CreateMargins(); - SetXmlNodeString(_topMarginPath, value.ToString(CultureInfo.InvariantCulture)); - } - } - - private const string _bottomMarginPath = "d:pageMargins/@bottom"; - - /// <summary> - /// Bottom margin in inches - /// </summary> - public decimal BottomMargin { - get => GetXmlNodeDecimal(_bottomMarginPath); - set { - CreateMargins(); - SetXmlNodeString(_bottomMarginPath, value.ToString(CultureInfo.InvariantCulture)); - } - } - - private const string _headerMarginPath = "d:pageMargins/@header"; - - /// <summary> - /// Header margin in inches - /// </summary> - public decimal HeaderMargin { - get => GetXmlNodeDecimal(_headerMarginPath); - set { - CreateMargins(); - SetXmlNodeString(_headerMarginPath, value.ToString(CultureInfo.InvariantCulture)); - } - } - - private const string _footerMarginPath = "d:pageMargins/@footer"; - - /// <summary> - /// Footer margin in inches - /// </summary> - public decimal FooterMargin { - get => GetXmlNodeDecimal(_footerMarginPath); - set { - CreateMargins(); - SetXmlNodeString(_footerMarginPath, value.ToString(CultureInfo.InvariantCulture)); - } - } - - private const string _orientationPath = "d:pageSetup/@orientation"; - - /// <summary> - /// Orientation - /// Portrait or Landscape - /// </summary> - public eOrientation Orientation { - get => (eOrientation)Enum.Parse(typeof(eOrientation), GetXmlNodeString(_orientationPath), true); - set => - SetXmlNodeString(_orientationPath, value.ToString().ToLower(CultureInfo.InvariantCulture)); - } - - private const string _fitToWidthPath = "d:pageSetup/@fitToWidth"; - - /// <summary> - /// Fit to Width in pages. - /// Set FitToPage to true when using this one. - /// 0 is automatic - /// </summary> - public int FitToWidth { - get => GetXmlNodeInt(_fitToWidthPath); - set => SetXmlNodeString(_fitToWidthPath, value.ToString()); - } - - private const string _fitToHeightPath = "d:pageSetup/@fitToHeight"; - - /// <summary> - /// Fit to height in pages. - /// Set FitToPage to true when using this one. - /// 0 is automatic - /// </summary> - public int FitToHeight { - get => GetXmlNodeInt(_fitToHeightPath); - set => SetXmlNodeString(_fitToHeightPath, value.ToString()); - } - - private const string _scalePath = "d:pageSetup/@scale"; - - /// <summary> - /// Print scale - /// </summary> - public int Scale { - get => GetXmlNodeInt(_scalePath); - set => SetXmlNodeString(_scalePath, value.ToString()); - } - - private const string _fitToPagePath = "d:sheetPr/d:pageSetUpPr/@fitToPage"; - - /// <summary> - /// Fit To Page. - /// </summary> - public bool FitToPage { - get => GetXmlNodeBool(_fitToPagePath); - set => SetXmlNodeString(_fitToPagePath, value ? "1" : "0"); - } - - private const string _headersPath = "d:printOptions/@headings"; - - /// <summary> - /// Print headings (column letter and row numbers) - /// </summary> - public bool ShowHeaders { - get => GetXmlNodeBool(_headersPath, false); - set => SetXmlNodeBool(_headersPath, value, false); - } - - /// <summary> - /// Print titles - /// Rows to be repeated after each pagebreak. - /// The address must be a full row address (ex. 1:1) - /// </summary> - public ExcelAddress RepeatRows { - get { - if (_ws.Names.ContainsKey("_xlnm.Print_Titles")) { - ExcelRangeBase r = _ws.Names["_xlnm.Print_Titles"]; - if (r.Start.Column == 1 && r.End.Column == ExcelPackage.MaxColumns) { - return new(r.FirstAddress); - } - if (r._addresses != null - && r.Addresses[0].Start.Column == 1 - && r.Addresses[0].End.Column == ExcelPackage.MaxColumns) { - return r._addresses[0]; - } - return null; - } - return null; - } - set { - //Must span entire columns - if (!(value.Start.Column == 1 && value.End.Column == ExcelPackage.MaxColumns)) { - throw new InvalidOperationException( - "Address must span full columns only (for ex. Address=\"A:A\" for the first column)."); - } - - var vertAddr = RepeatColumns; - string addr; - if (vertAddr == null) { - addr = value.Address; - } else { - addr = vertAddr.Address + "," + value.Address; - } - - if (_ws.Names.ContainsKey("_xlnm.Print_Titles")) { - _ws.Names["_xlnm.Print_Titles"].Address = addr; - } else { - _ws.Names.Add("_xlnm.Print_Titles", new(_ws, addr)); - } - } - } - - /// <summary> - /// Print titles - /// Columns to be repeated after each pagebreak. - /// The address must be a full column address (ex. A:A) - /// </summary> - public ExcelAddress RepeatColumns { - get { - if (_ws.Names.ContainsKey("_xlnm.Print_Titles")) { - ExcelRangeBase r = _ws.Names["_xlnm.Print_Titles"]; - if (r.Start.Row == 1 && r.End.Row == ExcelPackage.MaxRows) { - return new(r.FirstAddress); - } - if (r._addresses != null - && (r._addresses[0].Start.Row == 1 - && r._addresses[0].End.Row == ExcelPackage.MaxRows)) { - return r._addresses[0]; - } - return null; - } - return null; - } - set { - //Must span entire rows - if (!(value.Start.Row == 1 && value.End.Row == ExcelPackage.MaxRows)) { - throw new InvalidOperationException( - "Address must span rows only (for ex. Address=\"1:1\" for the first row)."); - } - - var horAddr = RepeatRows; - string addr; - if (horAddr == null) { - addr = value.Address; - } else { - addr = value.Address + "," + horAddr.Address; - } - - if (_ws.Names.ContainsKey("_xlnm.Print_Titles")) { - _ws.Names["_xlnm.Print_Titles"].Address = addr; - } else { - _ws.Names.Add("_xlnm.Print_Titles", new(_ws, addr)); - } - } - } - - /// <summary> - /// The printarea. - /// Null if no print area is set. - /// </summary> - public ExcelRangeBase PrintArea { - get { - if (_ws.Names.ContainsKey("_xlnm.Print_Area")) { - return _ws.Names["_xlnm.Print_Area"]; - } - return null; - } - set { - if (value == null) { - _ws.Names.Remove("_xlnm.Print_Area"); - } else if (_ws.Names.ContainsKey("_xlnm.Print_Area")) { - _ws.Names["_xlnm.Print_Area"].Address = value.Address; - } else { - _ws.Names.Add("_xlnm.Print_Area", value); - } - } - } - - private const string _gridLinesPath = "d:printOptions/@gridLines"; - - /// <summary> - /// Print gridlines - /// </summary> - public bool ShowGridLines { - get => GetXmlNodeBool(_gridLinesPath, false); - set => SetXmlNodeBool(_gridLinesPath, value, false); - } - - private const string _horizontalCenteredPath = "d:printOptions/@horizontalCentered"; - - /// <summary> - /// Horizontal centered when printing - /// </summary>w - public bool HorizontalCentered { - get => GetXmlNodeBool(_horizontalCenteredPath, false); - set => SetXmlNodeBool(_horizontalCenteredPath, value, false); - } - - private const string _verticalCenteredPath = "d:printOptions/@verticalCentered"; - - /// <summary> - /// Vertical centered when printing - /// </summary> - public bool VerticalCentered { - get => GetXmlNodeBool(_verticalCenteredPath, false); - set => SetXmlNodeBool(_verticalCenteredPath, value, false); - } - - private const string _pageOrderPath = "d:pageSetup/@pageOrder"; - - /// <summary> - /// Specifies printed page order - /// </summary> - public ePageOrder PageOrder { - get { - if (GetXmlNodeString(_pageOrderPath) == "overThenDown") { - return ePageOrder.OverThenDown; - } - return ePageOrder.DownThenOver; - } - set { - if (value == ePageOrder.OverThenDown) { - SetXmlNodeString(_pageOrderPath, "overThenDown"); - } else { - DeleteNode(_pageOrderPath); - } - } - } - - private const string _blackAndWhitePath = "d:pageSetup/@blackAndWhite"; - - /// <summary> - /// Print black and white - /// </summary> - public bool BlackAndWhite { - get => GetXmlNodeBool(_blackAndWhitePath, false); - set => SetXmlNodeBool(_blackAndWhitePath, value, false); - } - - private const string _draftPath = "d:pageSetup/@draft"; - - /// <summary> - /// Print a draft - /// </summary> - public bool Draft { - get => GetXmlNodeBool(_draftPath, false); - set => SetXmlNodeBool(_draftPath, value, false); - } - - private const string _paperSizePath = "d:pageSetup/@paperSize"; - - /// <summary> - /// Paper size - /// </summary> - public ePaperSize PaperSize { - get { - string s = GetXmlNodeString(_paperSizePath); - if (s != "") { - return (ePaperSize)int.Parse(s); - } - return ePaperSize.Letter; - } - set => SetXmlNodeString(_paperSizePath, ((int)value).ToString()); - } - - /// <summary> - /// All or none of the margin attributes must exist. Create all att ones. - /// </summary> - private void CreateMargins() { - if (_marginsCreated == false - && TopNode.SelectSingleNode(_leftMarginPath, NameSpaceManager) == null) { - _marginsCreated = true; - LeftMargin = 0.7087M; - RightMargin = 0.7087M; - TopMargin = 0.7480M; - BottomMargin = 0.7480M; - HeaderMargin = 0.315M; - FooterMargin = 0.315M; - } - } -}
diff --git a/EPPlus/ExcelRangeBase.cs b/EPPlus/ExcelRangeBase.cs index b4e48a8..686eb78 100644 --- a/EPPlus/ExcelRangeBase.cs +++ b/EPPlus/ExcelRangeBase.cs
@@ -349,12 +349,6 @@ } } - private void Set_Comment(object value, int row, int col) { - string[] v = (string[])value; - Worksheet.Comments.Add(new(_worksheet, GetAddress(_fromRow, _fromCol)), v[0], v[1]); - // _worksheet.Cell(row, col).Comment = comment; - } - private void SetToSelectedRange() { if (_worksheet.View.SelectedRange == "") { Address = "A1"; @@ -1837,339 +1831,6 @@ } /// <summary> - /// Adds a new comment for the range. - /// If this range contains more than one cell, the top left comment is returned by the method. - /// </summary> - /// <param name="text"></param> - /// <param name="author"></param> - /// <returns>A reference comment of the top left cell</returns> - public ExcelComment AddComment(string text, string author) { - if (string.IsNullOrEmpty(author)) { - author = Thread.CurrentPrincipal.Identity.Name; - } - //Check if any comments exists in the range and throw an exception - _changePropMethod(Exists_Comment, null); - //Create the comments - _changePropMethod(Set_Comment, new[] { text, author }); - - return _worksheet.Comments[new ExcelCellAddress(_fromRow, _fromCol)]; - } - - ///// <summary> - ///// Copies the range of cells to an other range - ///// </summary> - ///// <param name="Destination">The start cell where the range will be copied.</param> - public void Copy(ExcelRangeBase destination) { - bool sameWorkbook = destination._worksheet.Workbook == _worksheet.Workbook; - ExcelStyles sourceStyles = _worksheet.Workbook.Styles, - styles = destination._worksheet.Workbook.Styles; - Dictionary<int, int> styleCashe = new Dictionary<int, int>(); - - //Clear all existing cells; - int toRow = _toRow - _fromRow + 1, - toCol = _toCol - _fromCol + 1; - - string s = ""; - int i = 0; - object o = null; - byte flag = 0; - Uri hl = null; - ExcelComment comment = null; - - var cse = new CellsStoreEnumerator<object>( - _worksheet._values, - _fromRow, - _fromCol, - _toRow, - _toCol); - var copiedValue = new List<CopiedCell>(); - while (cse.Next()) { - var row = cse.Row; - var col = cse.Column; //Issue 15070 - var cell = new CopiedCell { - Row = destination._fromRow + (row - _fromRow), - Column = destination._fromCol + (col - _fromCol), - Value = cse.Value, - }; - - //Destination._worksheet._values.SetValue(row, col, cse.Value); - - if (_worksheet._types.Exists(row, col, ref s)) { - //Destination._worksheet._types.SetValue(row, col,s); - cell.Type = s; - } - - if (_worksheet._formulas.Exists(row, col, ref o)) { - if (o is int) { - // Destination._worksheet._formulas.SetValue(row, col, _worksheet.GetFormula(cse.Row, cse.Column)); //Shared formulas, set the formula per cell to simplify - cell.Formula = _worksheet.GetFormula(cse.Row, cse.Column); - } else { - //Destination._worksheet._formulas.SetValue(row, col, o); - cell.Formula = o; - } - } - if (_worksheet._styles.Exists(row, col, ref i)) { - if (sameWorkbook) { - //Destination._worksheet._styles.SetValue(row, col, i); - cell.StyleID = i; - } else { - if (styleCashe.ContainsKey(i)) { - i = styleCashe[i]; - } else { - var oldStyleId = i; - i = styles.CloneStyle(sourceStyles, i); - styleCashe.Add(oldStyleId, i); - } - //Destination._worksheet._styles.SetValue(row, col, i); - cell.StyleID = i; - } - } - - if (_worksheet._hyperLinks.Exists(row, col, ref hl)) { - //Destination._worksheet._hyperLinks.SetValue(row, col, hl); - cell.HyperLink = hl; - } - - if (_worksheet._commentsStore.Exists(row, col, ref comment)) { - cell.Comment = comment; - } - - if (_worksheet._flags.Exists(row, col, ref flag)) { - cell.Flag = flag; - } - copiedValue.Add(cell); - } - - //Copy styles with no cell value - var cses = new CellsStoreEnumerator<int>( - _worksheet._styles, - _fromRow, - _fromCol, - _toRow, - _toCol); - while (cses.Next()) { - if (!_worksheet._values.Exists(cses.Row, cses.Column)) { - var row = destination._fromRow + (cses.Row - _fromRow); - var col = destination._fromCol + (cses.Column - _fromCol); - var cell = new CopiedCell { - Row = row, - Column = col, - Value = null, - }; - - i = cses.Value; - if (sameWorkbook) { - cell.StyleID = i; - } else { - if (styleCashe.ContainsKey(i)) { - i = styleCashe[i]; - } else { - var oldStyleId = i; - i = styles.CloneStyle(sourceStyles, i); - styleCashe.Add(oldStyleId, i); - } - //Destination._worksheet._styles.SetValue(row, col, i); - cell.StyleID = i; - } - copiedValue.Add(cell); - } - } - var copiedMergedCells = new Dictionary<int, ExcelAddress>(); - //Merged cells - var csem = new CellsStoreEnumerator<int>( - _worksheet.MergedCells._cells, - _fromRow, - _fromCol, - _toRow, - _toCol); - while (csem.Next()) { - if (!copiedMergedCells.ContainsKey(csem.Value)) { - var adr = new ExcelAddress(_worksheet.Name, _worksheet.MergedCells.List[csem.Value]); - if (Collide(adr) == eAddressCollition.Inside) { - copiedMergedCells.Add( - csem.Value, - new( - destination._fromRow + (adr.Start.Row - _fromRow), - destination._fromCol + (adr.Start.Column - _fromCol), - destination._fromRow + (adr.End.Row - _fromRow), - destination._fromCol + (adr.End.Column - _fromCol))); - } else { - //Partial merge of the address ignore. - copiedMergedCells.Add(csem.Value, null); - } - } - } - - destination._worksheet.MergedCells.Clear( - new( - destination._fromRow, - destination._fromCol, - destination._fromRow + toRow - 1, - destination._fromCol + toCol - 1)); - - destination._worksheet._values.Clear(destination._fromRow, destination._fromCol, toRow, toCol); - destination._worksheet._formulas.Clear( - destination._fromRow, - destination._fromCol, - toRow, - toCol); - destination._worksheet._styles.Clear(destination._fromRow, destination._fromCol, toRow, toCol); - destination._worksheet._types.Clear(destination._fromRow, destination._fromCol, toRow, toCol); - destination._worksheet._hyperLinks.Clear( - destination._fromRow, - destination._fromCol, - toRow, - toCol); - destination._worksheet._flags.Clear(destination._fromRow, destination._fromCol, toRow, toCol); - destination._worksheet._commentsStore.Clear( - destination._fromRow, - destination._fromCol, - toRow, - toCol); - - foreach (var cell in copiedValue) { - destination._worksheet._values.SetValue(cell.Row, cell.Column, cell.Value); - - if (cell.Type != null) { - destination._worksheet._types.SetValue(cell.Row, cell.Column, cell.Type); - } - - if (cell.StyleID != null) { - destination._worksheet._styles.SetValue(cell.Row, cell.Column, cell.StyleID.Value); - } - - if (cell.Formula != null) { - cell.Formula = UpdateFormulaReferences( - cell.Formula.ToString(), - destination._fromRow - _fromRow, - destination._fromCol - _fromCol, - 0, - 0, - true); - destination._worksheet._formulas.SetValue(cell.Row, cell.Column, cell.Formula); - } - if (cell.HyperLink != null) { - destination._worksheet._hyperLinks.SetValue(cell.Row, cell.Column, cell.HyperLink); - } - - if (cell.Comment != null) { - //Destination._worksheet._commentsStore.SetValue(cell.Row, cell.Column, cell.Comment); - } - if (cell.Flag != 0) { - destination._worksheet._flags.SetValue(cell.Row, cell.Column, cell.Flag); - } - } - - //Add merged cells - foreach (var m in copiedMergedCells.Values) { - if (m != null) { - destination._worksheet.MergedCells.Add(m, true); - } - } - - //Clone the cell - //var copiedCell = (_worksheet._cells[GetCellID(_worksheet.SheetID, cell._fromRow, cell.column)] as ExcelCell); - - //var newCell = copiedCell.Clone(Destination._worksheet, - // Destination._fromRow + (copiedCell.Row - _fromRow), - // Destination.column + (copiedCell.Column - column)); - - // newCell.MergeId = _worksheet.GetMergeCellId(copiedCell.Row, copiedCell.Column); - - // if (!string.IsNullOrEmpty(newCell.Formula)) - // { - // newCell.Formula = ExcelCell.UpdateFormulaReferences(newCell.Formula, newCell.Row - copiedCell.Row, (newCell.Column - copiedCell.Column), 1, 1); - // } - - // //If its not the same workbook we must copy the styles to the new workbook. - // if (!sameWorkbook) - // { - // if (styleCashe.ContainsKey(cell.StyleID)) - // { - // newCell.StyleID = styleCashe[cell.StyleID]; - // } - // else - // { - // newCell.StyleID = styles.CloneStyle(sourceStyles, cell.StyleID); - // styleCashe.Add(cell.StyleID, newCell.StyleID); - // } - // } - // newCells.Add(newCell); - // if (newCell.Merge) mergedCells.Add(newCell.CellID, newCell); - // } - - // //Now clear the destination. - // Destination.Offset(0, 0, (_toRow - _fromRow) + 1, (_toCol - column) + 1).Clear(); - - // //And last add the new cells to the worksheet - // foreach (var cell in newCells) - // { - // Destination.Worksheet._cells.Add(cell); - // } - // //Add merged cells - // if (mergedCells.Count > 0) - // { - // List<ExcelAddressBase> mergedAddresses = new List<ExcelAddressBase>(); - // foreach (var cell in mergedCells.Values) - // { - // if (!IsAdded(cell, mergedAddresses)) - // { - // int startRow = cell.Row, startCol = cell.Column, endRow = cell.Row, endCol = cell.Column + 1; - // while (mergedCells.ContainsKey(ExcelCell.GetCellID(Destination.Worksheet.SheetID, endRow, endCol))) - // { - // ExcelCell next = mergedCells[ExcelCell.GetCellID(Destination.Worksheet.SheetID, endRow, endCol)]; - // if (cell.MergeId != next.MergeId) - // { - // break; - // } - // endCol++; - // } - - // while (IsMerged(mergedCells, Destination.Worksheet, endRow, startCol, endCol - 1, cell)) - // { - // endRow++; - // } - - // mergedAddresses.Add(new ExcelAddressBase(startRow, startCol, endRow - 1, endCol - 1)); - // } - // } - // Destination.Worksheet.MergedCells.List.AddRange((from r in mergedAddresses select r.Address)); - // } - //} - - //private bool IsAdded(ExcelCell cell, List<ExcelAddressBase> mergedAddresses) - //{ - // foreach (var address in mergedAddresses) - // { - // if (address.Collide(new ExcelAddressBase(cell.CellAddress)) == eAddressCollition.Inside) - // { - // return true; - // } - // } - // return false; - //} - - //private bool IsMerged(Dictionary<ulong, ExcelCell> mergedCells, ExcelWorksheet worksheet, int row, int startCol, int endCol, ExcelCell cell) - //{ - // for (int col = startCol; col <= endCol; col++) - // { - // if (!mergedCells.ContainsKey(ExcelCell.GetCellID(worksheet.SheetID, row, col))) - // { - // return false; - // } - // else - // { - // ExcelCell next = mergedCells[ExcelCell.GetCellID(worksheet.SheetID, row, col)]; - // if (cell.MergeId != next.MergeId) - // { - // return false; - // } - // } - // } - // return true; - } - - /// <summary> /// Clear all cells /// </summary> public void Clear() {
diff --git a/EPPlus/ExcelWorksheet.cs b/EPPlus/ExcelWorksheet.cs index c561c33..33d2dd8 100644 --- a/EPPlus/ExcelWorksheet.cs +++ b/EPPlus/ExcelWorksheet.cs
@@ -1514,17 +1514,6 @@ } } - /// <summary> - /// Printer settings - /// </summary> - public ExcelPrinterSettings PrinterSettings { - get { - var ps = new ExcelPrinterSettings(NameSpaceManager, TopNode, this); - ps.SchemaNodeOrder = SchemaNodeOrder; - return ps; - } - } - ///// <summary> ///// Provides access to an individual cell within the worksheet. ///// </summary>
diff --git a/EPPlus/FormulaParsing/ExpressionGraph/CompileResult.cs b/EPPlus/FormulaParsing/ExpressionGraph/CompileResult.cs index 2545f6a..90693ee 100644 --- a/EPPlus/FormulaParsing/ExpressionGraph/CompileResult.cs +++ b/EPPlus/FormulaParsing/ExpressionGraph/CompileResult.cs
@@ -107,9 +107,7 @@ || DataType == DataType.Boolean || DataType == DataType.Date; - public bool IsNumericString { - get { return DataType == DataType.String && ConvertUtil.IsNumericString(Result); } - } + public bool IsNumericString => DataType == DataType.String && ConvertUtil.IsNumericString(Result); public bool IsResultOfSubtotal { get; set; }
diff --git a/EPPlus/RangeCollection.cs b/EPPlus/RangeCollection.cs index 5dfb567..c7f8218 100644 --- a/EPPlus/RangeCollection.cs +++ b/EPPlus/RangeCollection.cs
@@ -103,9 +103,7 @@ /// <returns></returns> internal IRangeId this[int index] => _cells[_cellIndex[index].ListPointer]; - internal int Count { - get { return _cells.Count; } - } + internal int Count => _cells.Count; internal void Add(IRangeId cell) { var ix = IndexOf(cell.RangeID);
diff --git a/EPPlus/Style/Dxf/DxfStyleBase.cs b/EPPlus/Style/Dxf/DxfStyleBase.cs index 7bbbcd0..0c73cb0 100644 --- a/EPPlus/Style/Dxf/DxfStyleBase.cs +++ b/EPPlus/Style/Dxf/DxfStyleBase.cs
@@ -21,8 +21,8 @@ protected void SetValueColor(XmlHelper helper, string path, ExcelDxfColor color) { if (color != null && color.HasValue) { - if (color.Color != null) { - SetValue(helper, path + "/@rgb", color.Color.Value.ToArgb().ToString("x")); + if (color.Rgb != null) { + SetValue(helper, path + "/@rgb", color.Rgb); } else if (color.Auto != null) { SetValueBool(helper, path + "/@auto", color.Auto); } else if (color.Theme != null) { @@ -68,7 +68,7 @@ } } - protected internal string GetAsString(object v) { + protected string GetAsString(object v) { return (v ?? "").ToString(); }
diff --git a/EPPlus/Style/Dxf/ExcelDxfColor.cs b/EPPlus/Style/Dxf/ExcelDxfColor.cs index 4e6c4f9..d22a7f9 100644 --- a/EPPlus/Style/Dxf/ExcelDxfColor.cs +++ b/EPPlus/Style/Dxf/ExcelDxfColor.cs
@@ -1,5 +1,4 @@ using System; -using System.Drawing; namespace OfficeOpenXml.Style.Dxf; @@ -15,7 +14,7 @@ public double? Tint { get; set; } - public Color? Color { get; set; } + public string Rgb { get; set; } protected internal override string Id => GetAsString(Theme) @@ -26,20 +25,20 @@ + "|" + GetAsString(Tint) + "|" - + GetAsString(Color == null ? "" : Color.Value.ToArgb().ToString("x")); + + GetAsString(Rgb); protected internal override ExcelDxfColor Clone() { return new(_styles) { Theme = Theme, Index = Index, - Color = Color, + Rgb = Rgb, Auto = Auto, Tint = Tint, }; } protected internal override bool HasValue => - Theme != null || Index != null || Auto != null || Tint != null || Color != null; + Theme != null || Index != null || Auto != null || Tint != null || Rgb != null; protected internal override void CreateNodes(XmlHelper helper, string path) { throw new NotImplementedException();
diff --git a/EPPlus/Style/Dxf/ExcelDxfStyle.cs b/EPPlus/Style/Dxf/ExcelDxfStyle.cs index 7180b21..325d5b1 100644 --- a/EPPlus/Style/Dxf/ExcelDxfStyle.cs +++ b/EPPlus/Style/Dxf/ExcelDxfStyle.cs
@@ -1,5 +1,4 @@ using System; -using System.Drawing; using System.Globalization; using System.Xml; @@ -53,46 +52,17 @@ return bi; } - private ExcelBorderStyle GetBorderStyleEnum(string style) { - if (style == "") { - return ExcelBorderStyle.None; - } - string sInStyle = - style.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture) - + style.Substring(1, style.Length - 1); - try { - return (ExcelBorderStyle)Enum.Parse(typeof(ExcelBorderStyle), sInStyle); - } catch { - return ExcelBorderStyle.None; - } - } + private ExcelBorderStyle GetBorderStyleEnum(string style) => + Enum.TryParse<ExcelBorderStyle>(style, true, out var result) ? result : ExcelBorderStyle.None; - private ExcelFillStyle GetPatternTypeEnum(string patternType) { - if (patternType == "") { - return ExcelFillStyle.None; - } - patternType = - patternType.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture) - + patternType.Substring(1, patternType.Length - 1); - try { - return (ExcelFillStyle)Enum.Parse(typeof(ExcelFillStyle), patternType); - } catch { - return ExcelFillStyle.None; - } - } + private ExcelFillStyle GetPatternTypeEnum(string patternType) => + Enum.TryParse<ExcelFillStyle>(patternType, true, out var result) ? result : ExcelFillStyle.None; private ExcelDxfColor GetColor(XmlHelperInstance helper, string path) { ExcelDxfColor ret = new ExcelDxfColor(_styles); ret.Theme = helper.GetXmlNodeIntNull(path + "/@theme"); ret.Index = helper.GetXmlNodeIntNull(path + "/@indexed"); - string rgb = helper.GetXmlNodeString(path + "/@rgb"); - if (rgb != "") { - ret.Color = Color.FromArgb( - int.Parse(rgb.Substring(0, 2), NumberStyles.AllowHexSpecifier), - int.Parse(rgb.Substring(2, 2), NumberStyles.AllowHexSpecifier), - int.Parse(rgb.Substring(4, 2), NumberStyles.AllowHexSpecifier), - int.Parse(rgb.Substring(6, 2), NumberStyles.AllowHexSpecifier)); - } + ret.Rgb = helper.GetXmlNodeString(path + "/@rgb"); ret.Auto = helper.GetXmlNodeBoolNullable(path + "/@auto"); ret.Tint = helper.GetXmlNodeDoubleNull(path + "/@tint"); return ret;
diff --git a/EPPlus/Style/ExcelBorder.cs b/EPPlus/Style/ExcelBorder.cs index bf07432..55889fb 100644 --- a/EPPlus/Style/ExcelBorder.cs +++ b/EPPlus/Style/ExcelBorder.cs
@@ -30,8 +30,6 @@ * Jan Källman License changed GPL-->LGPL 2011-12-16 *******************************************************************************/ -using System.Drawing; - namespace OfficeOpenXml.Style; /// <summary> @@ -88,10 +86,6 @@ } return false; } - set => - _ChangedEvent( - this, - new(eStyleClass.Border, eStyleProperty.BorderDiagonalUp, value, _positionID, _address)); } /// <summary> @@ -104,99 +98,8 @@ } return false; } - set => - _ChangedEvent( - this, - new(eStyleClass.Border, eStyleProperty.BorderDiagonalDown, value, _positionID, _address)); } internal override string Id => Top.Id + Bottom.Id + Left.Id + Right.Id + Diagonal.Id + DiagonalUp + DiagonalDown; - - /// <summary> - /// Set the border style around the range. - /// </summary> - /// <param name="style">The border style</param> - public void BorderAround(ExcelBorderStyle style) { - var addr = new ExcelAddress(_address); - SetBorderAroundStyle(style, addr); - } - - /// <summary> - /// Set the border style around the range. - /// </summary> - /// <param name="style">The border style</param> - /// <param name="color">The color of the border</param> - public void BorderAround(ExcelBorderStyle style, Color color) { - var addr = new ExcelAddress(_address); - SetBorderAroundStyle(style, addr); - - _ChangedEvent( - this, - new( - eStyleClass.BorderTop, - eStyleProperty.Color, - color.ToArgb().ToString("X"), - _positionID, - new ExcelAddress(addr._fromRow, addr._fromCol, addr._fromRow, addr._toCol).Address)); - _ChangedEvent( - this, - new( - eStyleClass.BorderBottom, - eStyleProperty.Color, - color.ToArgb().ToString("X"), - _positionID, - new ExcelAddress(addr._toRow, addr._fromCol, addr._toRow, addr._toCol).Address)); - _ChangedEvent( - this, - new( - eStyleClass.BorderLeft, - eStyleProperty.Color, - color.ToArgb().ToString("X"), - _positionID, - new ExcelAddress(addr._fromRow, addr._fromCol, addr._toRow, addr._fromCol).Address)); - _ChangedEvent( - this, - new( - eStyleClass.BorderRight, - eStyleProperty.Color, - color.ToArgb().ToString("X"), - _positionID, - new ExcelAddress(addr._fromRow, addr._toCol, addr._toRow, addr._toCol).Address)); - } - - private void SetBorderAroundStyle(ExcelBorderStyle style, ExcelAddress addr) { - _ChangedEvent( - this, - new( - eStyleClass.BorderTop, - eStyleProperty.Style, - style, - _positionID, - new ExcelAddress(addr._fromRow, addr._fromCol, addr._fromRow, addr._toCol).Address)); - _ChangedEvent( - this, - new( - eStyleClass.BorderBottom, - eStyleProperty.Style, - style, - _positionID, - new ExcelAddress(addr._toRow, addr._fromCol, addr._toRow, addr._toCol).Address)); - _ChangedEvent( - this, - new( - eStyleClass.BorderLeft, - eStyleProperty.Style, - style, - _positionID, - new ExcelAddress(addr._fromRow, addr._fromCol, addr._toRow, addr._fromCol).Address)); - _ChangedEvent( - this, - new( - eStyleClass.BorderRight, - eStyleProperty.Style, - style, - _positionID, - new ExcelAddress(addr._fromRow, addr._toCol, addr._toRow, addr._toCol).Address)); - } }
diff --git a/EPPlus/Style/ExcelBorderItem.cs b/EPPlus/Style/ExcelBorderItem.cs index 7708ab9..6f8208b 100644 --- a/EPPlus/Style/ExcelBorderItem.cs +++ b/EPPlus/Style/ExcelBorderItem.cs
@@ -57,10 +57,7 @@ /// <summary> /// The line style of the border /// </summary> - public ExcelBorderStyle Style { - get => GetSource().Style; - set => _ChangedEvent(this, new(_cls, eStyleProperty.Style, value, _positionID, _address)); - } + public ExcelBorderStyle Style => GetSource().Style; private ExcelColor _color;
diff --git a/EPPlus/Style/ExcelColor.cs b/EPPlus/Style/ExcelColor.cs index e673510..8725905 100644 --- a/EPPlus/Style/ExcelColor.cs +++ b/EPPlus/Style/ExcelColor.cs
@@ -31,7 +31,6 @@ *******************************************************************************/ using System; -using System.Drawing; using OfficeOpenXml.Style.XmlAccess; namespace OfficeOpenXml.Style; @@ -63,41 +62,17 @@ /// <summary> /// The tint value /// </summary> - public decimal Tint { - get => GetSource().Tint; - set { - if (value > 1 || value < -1) { - throw (new ArgumentOutOfRangeException("Value must be between -1 and 1")); - } - _ChangedEvent(this, new(_cls, eStyleProperty.Tint, value, _positionID, _address)); - } - } + public decimal Tint => GetSource().Tint; /// <summary> /// The RGB value /// </summary> - public string Rgb { - get => GetSource().Rgb; - internal set => - _ChangedEvent(this, new(_cls, eStyleProperty.Color, value, _positionID, _address)); - } + public string Rgb => GetSource().Rgb; /// <summary> /// The indexed color number. /// </summary> - public int Indexed { - get => GetSource().Indexed; - set => - _ChangedEvent(this, new(_cls, eStyleProperty.IndexedColor, value, _positionID, _address)); - } - - /// <summary> - /// Set the color of the object - /// </summary> - /// <param name="color">The color</param> - public void SetColor(Color color) { - Rgb = color.ToArgb().ToString("X"); - } + public int Indexed => GetSource().Indexed; internal override string Id => Theme + Tint + Rgb + Indexed;
diff --git a/EPPlus/Style/ExcelFill.cs b/EPPlus/Style/ExcelFill.cs index d1a5ea6..09193d7 100644 --- a/EPPlus/Style/ExcelFill.cs +++ b/EPPlus/Style/ExcelFill.cs
@@ -56,14 +56,6 @@ } return _styles.Fills[Index].PatternType; } - set { - if (_gradient != null) { - _gradient = null; - } - _ChangedEvent( - this, - new(eStyleClass.Fill, eStyleProperty.PatternType, value, _positionID, _address)); - } } private ExcelColor _patternColor;
diff --git a/EPPlus/Style/ExcelFont.cs b/EPPlus/Style/ExcelFont.cs index 36beb83..528c3c6 100644 --- a/EPPlus/Style/ExcelFont.cs +++ b/EPPlus/Style/ExcelFont.cs
@@ -31,7 +31,6 @@ *******************************************************************************/ using System; -using System.Drawing; namespace OfficeOpenXml.Style; @@ -52,31 +51,17 @@ /// <summary> /// The name of the font /// </summary> - public string Name { - get => _styles.Fonts[Index].Name; - set => - _ChangedEvent(this, new(eStyleClass.Font, eStyleProperty.Name, value, _positionID, _address)); - } + public string Name => _styles.Fonts[Index].Name; /// <summary> /// The Size of the font /// </summary> - public float Size { - get => _styles.Fonts[Index].Size; - set => - _ChangedEvent(this, new(eStyleClass.Font, eStyleProperty.Size, value, _positionID, _address)); - } + public float Size => _styles.Fonts[Index].Size; /// <summary> /// Font family /// </summary> - public int Family { - get => _styles.Fonts[Index].Family; - set => - _ChangedEvent( - this, - new(eStyleClass.Font, eStyleProperty.Family, value, _positionID, _address)); - } + public int Family => _styles.Fonts[Index].Family; /// <summary> /// Cell color @@ -87,13 +72,7 @@ /// <summary> /// Scheme /// </summary> - public string Scheme { - get => _styles.Fonts[Index].Scheme; - set => - _ChangedEvent( - this, - new(eStyleClass.Font, eStyleProperty.Scheme, value, _positionID, _address)); - } + public string Scheme => _styles.Fonts[Index].Scheme; /// <summary> /// Font-bold @@ -107,78 +86,30 @@ /// <summary> /// Font-italic /// </summary> - public bool Italic { - get => _styles.Fonts[Index].Italic; - set => - _ChangedEvent( - this, - new(eStyleClass.Font, eStyleProperty.Italic, value, _positionID, _address)); - } + public bool Italic => _styles.Fonts[Index].Italic; /// <summary> /// Font-Strikeout /// </summary> - public bool Strike { - get => _styles.Fonts[Index].Strike; - set => - _ChangedEvent( - this, - new(eStyleClass.Font, eStyleProperty.Strike, value, _positionID, _address)); - } + public bool Strike => _styles.Fonts[Index].Strike; /// <summary> /// Font-Underline /// </summary> - public bool UnderLine { - get => _styles.Fonts[Index].UnderLine; - set { - if (value) { - UnderLineType = ExcelUnderLineType.Single; - } else { - UnderLineType = ExcelUnderLineType.None; - } - //_ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Font, eStyleProperty.UnderlineType, value, _positionID, _address)); - } - } + public bool UnderLine => _styles.Fonts[Index].UnderLine; - public ExcelUnderLineType UnderLineType { - get => _styles.Fonts[Index].UnderLineType; - set => - _ChangedEvent( - this, - new(eStyleClass.Font, eStyleProperty.UnderlineType, value, _positionID, _address)); - } + public ExcelUnderLineType UnderLineType => _styles.Fonts[Index].UnderLineType; /// <summary> /// Font-Vertical Align /// </summary> - public ExcelVerticalAlignmentFont VerticalAlign { - get { - if (_styles.Fonts[Index].VerticalAlign == "") { - return ExcelVerticalAlignmentFont.None; - } - return (ExcelVerticalAlignmentFont) - Enum.Parse(typeof(ExcelVerticalAlignmentFont), _styles.Fonts[Index].VerticalAlign, true); - } - set => - _ChangedEvent( - this, - new(eStyleClass.Font, eStyleProperty.VerticalAlign, value, _positionID, _address)); - } - - /// <summary> - /// Set the font from a Font object - /// </summary> - /// <param name="font"></param> - public void SetFromFont(Font font) { - Name = font.Name; - //Family=fnt.FontFamily.; - Size = (int)font.Size; - Strike = font.Strikeout; - Bold = font.Bold; - UnderLine = font.Underline; - Italic = font.Italic; - } + public ExcelVerticalAlignmentFont VerticalAlign => + Enum.TryParse<ExcelVerticalAlignmentFont>( + _styles.Fonts[Index].VerticalAlign, + true, + out var result) + ? result + : ExcelVerticalAlignmentFont.None; internal override string Id => Name
diff --git a/EPPlus/Style/ExcelGradientFill.cs b/EPPlus/Style/ExcelGradientFill.cs index 16e73c8..7103b37 100644 --- a/EPPlus/Style/ExcelGradientFill.cs +++ b/EPPlus/Style/ExcelGradientFill.cs
@@ -52,99 +52,32 @@ /// <summary> /// Angle of the linear gradient /// </summary> - public double Degree { - get => ((ExcelGradientFillXml)_styles.Fills[Index]).Degree; - set => - _ChangedEvent( - this, - new( - eStyleClass.GradientFill, - eStyleProperty.GradientDegree, - value, - _positionID, - _address)); - } + public double Degree => ((ExcelGradientFillXml)_styles.Fills[Index]).Degree; /// <summary> /// Linear or Path gradient /// </summary> - public ExcelFillGradientType Type { - get => ((ExcelGradientFillXml)_styles.Fills[Index]).Type; - set => - _ChangedEvent( - this, - new(eStyleClass.GradientFill, eStyleProperty.GradientType, value, _positionID, _address)); - } + public ExcelFillGradientType Type => ((ExcelGradientFillXml)_styles.Fills[Index]).Type; /// <summary> /// Specifies in percentage format(from the top to the bottom) the position of the top edge of the inner rectangle (color 1). For top, 0 means the top edge of the inner rectangle is on the top edge of the cell, and 1 means it is on the bottom edge of the cell. (applies to From Corner and From Center gradients). /// </summary> - public double Top { - get => ((ExcelGradientFillXml)_styles.Fills[Index]).Top; - set { - if (value < 0 | value > 1) { - throw (new ArgumentOutOfRangeException("Value must be between 0 and 1")); - } - _ChangedEvent( - this, - new(eStyleClass.GradientFill, eStyleProperty.GradientTop, value, _positionID, _address)); - } - } + public double Top => ((ExcelGradientFillXml)_styles.Fills[Index]).Top; /// <summary> /// Specifies in percentage format (from the top to the bottom) the position of the bottom edge of the inner rectangle (color 1). For bottom, 0 means the bottom edge of the inner rectangle is on the top edge of the cell, and 1 means it is on the bottom edge of the cell. /// </summary> - public double Bottom { - get => ((ExcelGradientFillXml)_styles.Fills[Index]).Bottom; - set { - if (value < 0 | value > 1) { - throw (new ArgumentOutOfRangeException("Value must be between 0 and 1")); - } - _ChangedEvent( - this, - new( - eStyleClass.GradientFill, - eStyleProperty.GradientBottom, - value, - _positionID, - _address)); - } - } + public double Bottom => ((ExcelGradientFillXml)_styles.Fills[Index]).Bottom; /// <summary> /// Specifies in percentage format (from the left to the right) the position of the left edge of the inner rectangle (color 1). For left, 0 means the left edge of the inner rectangle is on the left edge of the cell, and 1 means it is on the right edge of the cell. (applies to From Corner and From Center gradients). /// </summary> - public double Left { - get => ((ExcelGradientFillXml)_styles.Fills[Index]).Left; - set { - if (value < 0 | value > 1) { - throw (new ArgumentOutOfRangeException("Value must be between 0 and 1")); - } - _ChangedEvent( - this, - new(eStyleClass.GradientFill, eStyleProperty.GradientLeft, value, _positionID, _address)); - } - } + public double Left => ((ExcelGradientFillXml)_styles.Fills[Index]).Left; /// <summary> /// Specifies in percentage format (from the left to the right) the position of the right edge of the inner rectangle (color 1). For right, 0 means the right edge of the inner rectangle is on the left edge of the cell, and 1 means it is on the right edge of the cell. (applies to From Corner and From Center gradients). /// </summary> - public double Right { - get => ((ExcelGradientFillXml)_styles.Fills[Index]).Right; - set { - if (value < 0 | value > 1) { - throw (new ArgumentOutOfRangeException("Value must be between 0 and 1")); - } - _ChangedEvent( - this, - new( - eStyleClass.GradientFill, - eStyleProperty.GradientRight, - value, - _positionID, - _address)); - } - } + public double Right => ((ExcelGradientFillXml)_styles.Fills[Index]).Right; private ExcelColor _gradientColor1;
diff --git a/EPPlus/Style/ExcelNumberFormat.cs b/EPPlus/Style/ExcelNumberFormat.cs index d1841df..32d88ac 100644 --- a/EPPlus/Style/ExcelNumberFormat.cs +++ b/EPPlus/Style/ExcelNumberFormat.cs
@@ -51,10 +51,6 @@ /// </summary> public int NumFmtID => Index; - //set - //{ - // _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Numberformat, "NumFmtID", value, _workSheetID, _address)); - //} /// <summary> /// The numberformat /// </summary>
diff --git a/EPPlus/Style/ExcelRichText.cs b/EPPlus/Style/ExcelRichText.cs index 2207656..2458430 100644 --- a/EPPlus/Style/ExcelRichText.cs +++ b/EPPlus/Style/ExcelRichText.cs
@@ -33,7 +33,6 @@ *******************************************************************************/ using System; -using System.Drawing; using System.Globalization; using System.Xml; @@ -216,33 +215,13 @@ /// <summary> /// Vertical Alignment /// </summary> - public ExcelVerticalAlignmentFont VerticalAlign { - get { - string v = GetXmlNodeString(_vertAlignPath); - if (v == "") { - return ExcelVerticalAlignmentFont.None; - } - try { - return (ExcelVerticalAlignmentFont)Enum.Parse(typeof(ExcelVerticalAlignmentFont), v, true); - } catch { - return ExcelVerticalAlignmentFont.None; - } - } - set { - _collection.ConvertRichtext(); - if (value == ExcelVerticalAlignmentFont.None) { - // If Excel 2010 encounters a vertical align value of blank, it will not load - // the spreadsheet. So if None is specified, delete the node, it will be - // recreated if a new value is applied later. - DeleteNode(_vertAlignPath); - } else { - SetXmlNodeString(_vertAlignPath, value.ToString().ToLowerInvariant()); - } - if (_callback != null) { - _callback(); - } - } - } + public ExcelVerticalAlignmentFont VerticalAlign => + Enum.TryParse<ExcelVerticalAlignmentFont>( + GetXmlNodeString(TopNode, _vertAlignPath), + true, + out var result) + ? result + : ExcelVerticalAlignmentFont.None; private const string _sizePath = "d:rPr/d:sz/@val"; @@ -281,22 +260,11 @@ /// <summary> /// Text color /// </summary> - public Color Color { - get { - string col = GetXmlNodeString(_colorPath); - if (col == "") { - return Color.Empty; - } - return Color.FromArgb(int.Parse(col, NumberStyles.AllowHexSpecifier)); - } + public string Color { + get => GetXmlNodeString(_colorPath); set { _collection.ConvertRichtext(); - SetXmlNodeString( - _colorPath, - value - .ToArgb() - .ToString( - "X") /*.Substring(2, 6)*/); + SetXmlNodeString(_colorPath, value); if (_callback != null) { _callback(); }
diff --git a/EPPlus/Style/ExcelRichTextCollection.cs b/EPPlus/Style/ExcelRichTextCollection.cs index 5e87c4b..62925f7 100644 --- a/EPPlus/Style/ExcelRichTextCollection.cs +++ b/EPPlus/Style/ExcelRichTextCollection.cs
@@ -32,7 +32,6 @@ using System.Collections; using System.Collections.Generic; -using System.Drawing; using System.Globalization; using System.Linq; using System.Text; @@ -102,11 +101,7 @@ ExcelRichText prevItem = _list[_list.Count - 1]; rt.FontName = prevItem.FontName; rt.Size = prevItem.Size; - if (prevItem.Color.IsEmpty) { - rt.Color = Color.Black; - } else { - rt.Color = prevItem.Color; - } + rt.Color = prevItem.Color == "" ? "FF00000" : prevItem.Color; rt.PreserveSpace = rt.PreserveSpace; rt.Bold = prevItem.Bold; rt.Italic = prevItem.Italic; @@ -160,11 +155,6 @@ this[0].Italic = fnt.Italic; this[0].Size = fnt.Size; this[0].UnderLine = fnt.UnderLine; - - if (fnt.Color.Rgb != "" - && int.TryParse(fnt.Color.Rgb, NumberStyles.HexNumber, null, out var hex)) { - this[0].Color = Color.FromArgb(hex); - } } } @@ -173,18 +163,6 @@ } /// <summary> - /// Clear the collection - /// </summary> - public void Clear() { - _list.Clear(); - TopNode.RemoveAll(); - UpdateCells(); - if (_cells != null) { - _cells.IsRichText = false; - } - } - - /// <summary> /// Removes an item at the specific index /// </summary> /// <param name="index"></param>
diff --git a/EPPlus/Style/ExcelRichTextHtmlUtility.cs b/EPPlus/Style/ExcelRichTextHtmlUtility.cs deleted file mode 100644 index 83e37c6..0000000 --- a/EPPlus/Style/ExcelRichTextHtmlUtility.cs +++ /dev/null
@@ -1,187 +0,0 @@ -/******************************************************************************* - * You may amend and distribute as you like, but don't remove this header! - * - * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets. - * See http://www.codeplex.com/EPPlus for details. - * - * Copyright (C) 2011 Jan Källman - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php - * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html - * - * All code and executables are provided "as is" with no warranty either express or implied. - * The author accepts no liability for any damage or loss of business that this product may cause. - * - * Code change notes: - * - * Author Change Date - * ****************************************************************************** - * Richard Tallent Initial Release 2012-08-13 - *******************************************************************************/ - -using System; -using System.Text.RegularExpressions; -using System.Web; - -namespace OfficeOpenXml.Style; - -public class ExcelRichTextHtmlUtility { - /// <summary> - /// Provides basic HTML support by converting well-behaved HTML into appropriate RichText blocks. - /// HTML support is limited, and does not include font colors, sizes, or typefaces at this time, - /// and also does not support CSS style attributes. It does support line breaks using the BR tag. - /// - /// This routine parses the HTML into RegEx pairings of an HTML tag and the text until the NEXT - /// tag (if any). The tag is parsed to determine the setting change to be applied to the last set - /// of settings, and if the text is not blank, a new block is added to rich text. - /// </summary> - /// <param name="range"></param> - /// <param name="html">The HTML to parse into RichText</param> - /// <param name="defaultFontName"></param> - /// <param name="defaultFontSize"></param> - public static void SetRichTextFromHtml( - ExcelRange range, - string html, - string defaultFontName, - short defaultFontSize) { - // Reset the cell value, just in case there is an existing RichText value. - range.Value = ""; - - // Sanity check for blank values, skips creating Regex objects for performance. - if (String.IsNullOrEmpty(html)) { - range.IsRichText = false; - return; - } - - // Change all BR tags to line breaks. http://epplus.codeplex.com/discussions/238692/ - // Cells with line breaks aren't necessarily considered rich text, so this is performed - // before parsing the HTML tags. - html = Regex.Replace( - html, - "<br[^>]*>", - "\r\n", - RegexOptions.Compiled | RegexOptions.IgnoreCase); - - string tag; - string text; - ExcelRichText thisrt = null; - bool isFirst = true; - - // Get all pairs of legitimate tags and the text between them. This loop will - // only execute if there is at least one start or end tag. - foreach (Match m in Regex.Matches( - html, - @"<(/?[a-z]+)[^<>]*>([\s\S]*?)(?=</?[a-z]+[^<>]*>|$)", - RegexOptions.Compiled | RegexOptions.IgnoreCase)) { - if (isFirst) { - // On the very first match, set up the initial rich text object with - // the defaults for the text BEFORE the match. - range.IsRichText = true; - thisrt = range.RichText.Add(CleanText(html.Substring(0, m.Index))); // May be 0-length - thisrt.Size = defaultFontSize; // Set the default font size - thisrt.FontName = defaultFontName; // Set the default font name - isFirst = false; - } - // Get the tag and the block of text until the NEXT tag or EOS. If there are HTML entities - // encoded, unencode them, they should be passed to RichText as normal characters (other - // than non-breaking spaces, which should be replaced with normal spaces, they break Excel. - tag = m.Groups[1].Captures[0].Value; - text = CleanText(m.Groups[2].Captures[0].Value); - - if (thisrt.Text == "") { - // The most recent rich text block wasn't *actually* used last time around, so update - // the text and keep it as the "current" block. This happens with the first block if - // it starts with a tag, and may happen later if tags come one right after the other. - thisrt.Text = text; - } else { - // The current rich text block has some text, so create a new one. RichText.Add() - // automatically applies the settings from the previous block, other than vertical - // alignment. - thisrt = range.RichText.Add(text); - } - // Override the settings based on the current tag, keep all other settings. - SetStyleFromTag(tag, thisrt); - } - - if (thisrt == null) { - // No HTML tags were found, so treat this as a normal text value. - range.IsRichText = false; - range.Value = CleanText(html); - } else if (String.IsNullOrEmpty(thisrt.Text)) { - // Rich text was found, but the last node contains no text, so remove it. This can happen if, - // say, the end of the string is an end tag or unsupported tag (common). - range.RichText.Remove(thisrt); - - // Failsafe -- the HTML may be just tags, no text, in which case there may be no rich text - // directives that remain. If that is the case, turn off rich text and treat this like a blank - // cell value. - if (range.RichText.Count == 0) { - range.IsRichText = false; - range.Value = ""; - } - } - } - - private static void SetStyleFromTag(string tag, ExcelRichText settings) { - switch (tag.ToLower()) { - case "b": - case "strong": - settings.Bold = true; - break; - case "i": - case "em": - settings.Italic = true; - break; - case "u": - settings.UnderLine = true; - break; - case "s": - case "strike": - settings.Strike = true; - break; - case "sup": - settings.VerticalAlign = ExcelVerticalAlignmentFont.Superscript; - break; - case "sub": - settings.VerticalAlign = ExcelVerticalAlignmentFont.Subscript; - break; - case "/b": - case "/strong": - settings.Bold = false; - break; - case "/i": - case "/em": - settings.Italic = false; - break; - case "/u": - settings.UnderLine = false; - break; - case "/s": - case "/strike": - settings.Strike = false; - break; - case "/sup": - case "/sub": - settings.VerticalAlign = ExcelVerticalAlignmentFont.None; - break; - } - } - - private static string CleanText(string s) { - // Need to convert HTML entities (named or numbered) into actual Unicode characters - s = HttpUtility.HtmlDecode(s); - // Remove any non-breaking spaces, kills Excel - s = s.Replace("\u00A0", " "); - return s; - } -}
diff --git a/EPPlus/Style/ExcelStyle.cs b/EPPlus/Style/ExcelStyle.cs index 9c2509a..3292c7b 100644 --- a/EPPlus/Style/ExcelStyle.cs +++ b/EPPlus/Style/ExcelStyle.cs
@@ -84,24 +84,12 @@ /// <summary> /// The horizontal alignment in the cell /// </summary> - public ExcelHorizontalAlignment HorizontalAlignment { - get => _styles.CellXfs[Index].HorizontalAlignment; - set => - _ChangedEvent( - this, - new(eStyleClass.Style, eStyleProperty.HorizontalAlign, value, _positionID, _address)); - } + public ExcelHorizontalAlignment HorizontalAlignment => _styles.CellXfs[Index].HorizontalAlignment; /// <summary> /// The vertical alignment in the cell /// </summary> - public ExcelVerticalAlignment VerticalAlignment { - get => _styles.CellXfs[Index].VerticalAlignment; - set => - _ChangedEvent( - this, - new(eStyleClass.Style, eStyleProperty.VerticalAlign, value, _positionID, _address)); - } + public ExcelVerticalAlignment VerticalAlignment => _styles.CellXfs[Index].VerticalAlignment; /// <summary> /// Wrap the text @@ -117,89 +105,39 @@ /// <summary> /// Readingorder /// </summary> - public ExcelReadingOrder ReadingOrder { - get => _styles.CellXfs[Index].ReadingOrder; - set => - _ChangedEvent( - this, - new(eStyleClass.Style, eStyleProperty.ReadingOrder, value, _positionID, _address)); - } + public ExcelReadingOrder ReadingOrder => _styles.CellXfs[Index].ReadingOrder; /// <summary> /// Shrink the text to fit /// </summary> - public bool ShrinkToFit { - get => _styles.CellXfs[Index].ShrinkToFit; - set => - _ChangedEvent( - this, - new(eStyleClass.Style, eStyleProperty.ShrinkToFit, value, _positionID, _address)); - } + public bool ShrinkToFit => _styles.CellXfs[Index].ShrinkToFit; /// <summary> /// The margin between the border and the text /// </summary> - public int Indent { - get => _styles.CellXfs[Index].Indent; - set { - if (value < 0 || value > 250) { - throw (new ArgumentOutOfRangeException("Indent must be between 0 and 250")); - } - _ChangedEvent( - this, - new(eStyleClass.Style, eStyleProperty.Indent, value, _positionID, _address)); - } - } + public int Indent => _styles.CellXfs[Index].Indent; /// <summary> /// Text orientation in degrees. Values range from 0 to 180. /// </summary> - public int TextRotation { - get => _styles.CellXfs[Index].TextRotation; - set { - if (value < 0 || value > 180) { - throw new ArgumentOutOfRangeException("TextRotation out of range."); - } - _ChangedEvent( - this, - new(eStyleClass.Style, eStyleProperty.TextRotation, value, _positionID, _address)); - } - } + public int TextRotation => _styles.CellXfs[Index].TextRotation; /// <summary> /// If true the cell is locked for editing when the sheet is protected /// <seealso cref="ExcelWorksheet.Protection"/> /// </summary> - public bool Locked { - get => _styles.CellXfs[Index].Locked; - set => - _ChangedEvent( - this, - new(eStyleClass.Style, eStyleProperty.Locked, value, _positionID, _address)); - } + public bool Locked => _styles.CellXfs[Index].Locked; /// <summary> /// If true the formula is hidden when the sheet is protected. /// <seealso cref="ExcelWorksheet.Protection"/> /// </summary> - public bool Hidden { - get => _styles.CellXfs[Index].Hidden; - set => - _ChangedEvent( - this, - new(eStyleClass.Style, eStyleProperty.Hidden, value, _positionID, _address)); - } + public bool Hidden => _styles.CellXfs[Index].Hidden; /// <summary> /// The index in the style collection /// </summary> - public int XfId { - get => _styles.CellXfs[Index].XfId; - set => - _ChangedEvent( - this, - new(eStyleClass.Style, eStyleProperty.XfId, value, _positionID, _address)); - } + public int XfId => _styles.CellXfs[Index].XfId; internal int PositionID { get; set; }
diff --git a/EPPlus/Style/ExcelTextFont.cs b/EPPlus/Style/ExcelTextFont.cs index f098072..9252413 100644 --- a/EPPlus/Style/ExcelTextFont.cs +++ b/EPPlus/Style/ExcelTextFont.cs
@@ -31,7 +31,6 @@ *******************************************************************************/ using System; -using System.Drawing; using System.Globalization; using System.Xml; @@ -141,22 +140,6 @@ } } - private readonly string _underLineColorPath = "a:uFill/a:solidFill/a:srgbClr/@val"; - - public Color UnderLineColor { - get { - string col = GetXmlNodeString(_underLineColorPath); - if (col == "") { - return Color.Empty; - } - return Color.FromArgb(int.Parse(col, NumberStyles.AllowHexSpecifier)); - } - set { - CreateTopNode(); - SetXmlNodeString(_underLineColorPath, value.ToArgb().ToString("X").Substring(2, 6)); - } - } - private readonly string _italicPath = "@i"; public bool Italic { @@ -187,22 +170,6 @@ } } - private readonly string _colorPath = "a:solidFill/a:srgbClr/@val"; - - public Color Color { - get { - string col = GetXmlNodeString(_colorPath); - if (col == "") { - return Color.Empty; - } - return Color.FromArgb(int.Parse(col, NumberStyles.AllowHexSpecifier)); - } - set { - CreateTopNode(); - SetXmlNodeString(_colorPath, value.ToArgb().ToString("X").Substring(2, 6)); - } - } - private eUnderLineType TranslateUnderline(string text) { switch (text) { case "sng": @@ -212,7 +179,9 @@ case "": return eUnderLineType.None; default: - return (eUnderLineType)Enum.Parse(typeof(eUnderLineType), text); + return Enum.TryParse<eUnderLineType>(text, true, out var result) + ? result + : eUnderLineType.None; } } @@ -250,26 +219,4 @@ return "noStrike"; } } - - /// <summary> - /// Set the font style from a font object - /// </summary> - /// <param name="font"></param> - public void SetFromFont(Font font) { - LatinFont = font.Name; - ComplexFont = font.Name; - Size = font.Size; - if (font.Bold) { - Bold = font.Bold; - } - if (font.Italic) { - Italic = font.Italic; - } - if (font.Underline) { - UnderLine = eUnderLineType.Single; - } - if (font.Strikeout) { - Strike = eStrikeType.Single; - } - } }
diff --git a/EPPlus/Style/StyleBase.cs b/EPPlus/Style/StyleBase.cs index fa1b390..edc6650 100644 --- a/EPPlus/Style/StyleBase.cs +++ b/EPPlus/Style/StyleBase.cs
@@ -1,4 +1,4 @@ -/******************************************************************************* +/******************************************************************************* * You may amend and distribute as you like, but don't remove this header! * * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
diff --git a/EPPlus/Style/XmlAccess/ExcelBorderItemXml.cs b/EPPlus/Style/XmlAccess/ExcelBorderItemXml.cs index 7e94481..9c0de5e 100644 --- a/EPPlus/Style/XmlAccess/ExcelBorderItemXml.cs +++ b/EPPlus/Style/XmlAccess/ExcelBorderItemXml.cs
@@ -61,14 +61,9 @@ if (style == "") { return ExcelBorderStyle.None; } - string sInStyle = - style.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture) - + style.Substring(1, style.Length - 1); - try { - return (ExcelBorderStyle)Enum.Parse(typeof(ExcelBorderStyle), sInStyle); - } catch { - return ExcelBorderStyle.None; - } + return Enum.TryParse<ExcelBorderStyle>(style, true, out var result) + ? result + : ExcelBorderStyle.None; } private ExcelBorderStyle _borderStyle = ExcelBorderStyle.None;
diff --git a/EPPlus/Style/XmlAccess/ExcelColorXml.cs b/EPPlus/Style/XmlAccess/ExcelColorXml.cs index ba1fd11..7a6d024 100644 --- a/EPPlus/Style/XmlAccess/ExcelColorXml.cs +++ b/EPPlus/Style/XmlAccess/ExcelColorXml.cs
@@ -31,7 +31,6 @@ *******************************************************************************/ using System; -using System.Drawing; using System.Globalization; using System.Xml; @@ -142,11 +141,6 @@ _auto = false; } - public void SetColor(Color color) { - Clear(); - _rgb = color.ToArgb().ToString("X"); - } - internal ExcelColorXml Copy() { return new(NameSpaceManager) { _indexed = _indexed,
diff --git a/EPPlus/Style/XmlAccess/ExcelFillXml.cs b/EPPlus/Style/XmlAccess/ExcelFillXml.cs index 98b7c9d..cf43d0e 100644 --- a/EPPlus/Style/XmlAccess/ExcelFillXml.cs +++ b/EPPlus/Style/XmlAccess/ExcelFillXml.cs
@@ -55,17 +55,9 @@ } private ExcelFillStyle GetPatternType(string patternType) { - if (patternType == "") { - return ExcelFillStyle.None; - } - patternType = - patternType.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture) - + patternType.Substring(1, patternType.Length - 1); - try { - return (ExcelFillStyle)Enum.Parse(typeof(ExcelFillStyle), patternType); - } catch { - return ExcelFillStyle.None; - } + return Enum.TryParse<ExcelFillStyle>(patternType, true, out var result) + ? result + : ExcelFillStyle.None; } internal override string Id => PatternType + PatternColor.Id + BackgroundColor.Id;
diff --git a/EPPlus/Style/XmlAccess/ExcelFontXml.cs b/EPPlus/Style/XmlAccess/ExcelFontXml.cs index 88ab554..2d90c95 100644 --- a/EPPlus/Style/XmlAccess/ExcelFontXml.cs +++ b/EPPlus/Style/XmlAccess/ExcelFontXml.cs
@@ -31,7 +31,6 @@ *******************************************************************************/ using System; -using System.Drawing; using System.Globalization; using System.Xml; @@ -71,7 +70,9 @@ if (ut == "") { _underlineType = ExcelUnderLineType.Single; } else { - _underlineType = (ExcelUnderLineType)Enum.Parse(typeof(ExcelUnderLineType), ut, true); + if (!Enum.TryParse(ut, true, out _underlineType)) { + _underlineType = ExcelUnderLineType.Single; + } } } else { _underlineType = ExcelUnderLineType.None; @@ -222,16 +223,6 @@ set => _verticalAlign = value; } - public void SetFromFont(Font font) { - Name = font.Name; - //Family=fnt.FontFamily.; - Size = (int)font.Size; - Strike = font.Strikeout; - Bold = font.Bold; - UnderLine = font.Underline; - Italic = font.Italic; - } - internal ExcelFontXml Copy() { ExcelFontXml newFont = new ExcelFontXml(NameSpaceManager); newFont.Name = _name;
diff --git a/EPPlus/Style/XmlAccess/ExcelXfsXml.cs b/EPPlus/Style/XmlAccess/ExcelXfsXml.cs index d00ed0e..45acdda 100644 --- a/EPPlus/Style/XmlAccess/ExcelXfsXml.cs +++ b/EPPlus/Style/XmlAccess/ExcelXfsXml.cs
@@ -31,7 +31,6 @@ *******************************************************************************/ using System; -using System.Drawing; using System.Globalization; using System.Xml; @@ -82,45 +81,15 @@ } } - private ExcelHorizontalAlignment GetHorizontalAlign(string align) { - if (align == "") { - return ExcelHorizontalAlignment.General; - } - align = - align.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture) - + align.Substring(1, align.Length - 1); - try { - return (ExcelHorizontalAlignment)Enum.Parse(typeof(ExcelHorizontalAlignment), align); - } catch { - return ExcelHorizontalAlignment.General; - } - } + private ExcelHorizontalAlignment GetHorizontalAlign(string align) => + Enum.TryParse<ExcelHorizontalAlignment>(align, true, out var result) + ? result + : ExcelHorizontalAlignment.General; - private ExcelVerticalAlignment GetVerticalAlign(string align) { - if (align == "") { - return ExcelVerticalAlignment.Bottom; - } - align = - align.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture) - + align.Substring(1, align.Length - 1); - try { - return (ExcelVerticalAlignment)Enum.Parse(typeof(ExcelVerticalAlignment), align); - } catch { - return ExcelVerticalAlignment.Bottom; - } - } - - internal void Xf_ChangedEvent(object sender, EventArgs e) { - //if (_cell != null) - //{ - // if (!Styles.ChangedCells.ContainsKey(_cell.Id)) - // { - // //_cell.Style = ""; - // _cell.SetNewStyleID(int.MinValue.ToString()); - // Styles.ChangedCells.Add(_cell.Id, _cell); - // } - //} - } + private ExcelVerticalAlignment GetVerticalAlign(string align) => + Enum.TryParse<ExcelVerticalAlignment>(align, true, out var result) + ? result + : ExcelVerticalAlignment.Bottom; private int _xfID; @@ -548,8 +517,8 @@ fill = (ExcelGradientFillXml)Fill.Copy(); } else { fill = new(Fill.NameSpaceManager); - fill.GradientColor1.SetColor(Color.White); - fill.GradientColor2.SetColor(Color.FromArgb(79, 129, 189)); + fill.GradientColor1.Rgb = "FFFFFFFF"; + fill.GradientColor2.Rgb = "FF4F81BD"; fill.Type = ExcelFillGradientType.Linear; fill.Degree = 90; fill.Top = double.NaN;
diff --git a/NetCoreTests/ExcelPackageTest.cs b/NetCoreTests/ExcelPackageTest.cs index 8785d5d..369e55a 100644 --- a/NetCoreTests/ExcelPackageTest.cs +++ b/NetCoreTests/ExcelPackageTest.cs
@@ -3,6 +3,7 @@ using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using OfficeOpenXml; +using OfficeOpenXml.DataValidation; namespace NetCoreTests; @@ -32,6 +33,20 @@ worksheet.Name.Should().Be("pusum11a"); } + [TestMethod] + public void TestGetAsByteArray_DataValidation() { + var package = new ExcelPackage(new FileInfo(GetTestWorkbookPath("DataValidation.xlsx"))); + var data = package.GetAsByteArray(); + + // Verify that we can reload + var newPackage = new ExcelPackage(new MemoryStream(data, false)); + newPackage.Workbook.Worksheets.Count.Should().Be(1); + var worksheet = newPackage.Workbook.Worksheets.First(); + worksheet.Name.Should().Be("Sheet1"); + worksheet.DataValidations.Should().HaveCount(31); + worksheet.DataValidations[1].ValidationType.Should().Be(ExcelDataValidationType.Whole); + } + private static string GetTestWorkbookPath(string filename) { var assemblyPath = Path.GetDirectoryName(typeof(ExcelPackageTest).Assembly.Location)!; return Path.Combine(assemblyPath, "TestWorkbooks", filename);
diff --git a/NetCoreTests/TestWorkbooks/DataValidation.xlsx b/NetCoreTests/TestWorkbooks/DataValidation.xlsx new file mode 100644 index 0000000..78d508c --- /dev/null +++ b/NetCoreTests/TestWorkbooks/DataValidation.xlsx Binary files differ