diff --git a/OpenXmlFormats/Encryption/Encryption.cs b/OpenXmlFormats/Encryption/Encryption.cs index a6abaa842..75f00a69e 100644 --- a/OpenXmlFormats/Encryption/Encryption.cs +++ b/OpenXmlFormats/Encryption/Encryption.cs @@ -17,7 +17,6 @@ namespace NPOI.OpenXmlFormats.Encryption using System.Xml; using System.Collections.Generic; using NPOI.OpenXml4Net.Util; - using EnumsNET; [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3761.0")] [System.SerializableAttribute()] @@ -434,7 +433,7 @@ public static CT_KeyEncryptor Parse(XmlNode node, XmlNamespaceManager nameSpaceM if (node.Attributes["uri"] != null) { ctObj.uriFieldSpecified = true; - ctObj.uriField = Enums.Parse(node.Attributes["uri"].Value, false, EnumFormat.Description); + ctObj.uriField = CT_KeyEncryptorUriParser.Parse(node.Attributes["uri"].Value); } foreach(XmlNode child in node.ChildNodes) { @@ -458,14 +457,27 @@ public static CT_KeyEncryptor Parse(XmlNode node, XmlNamespaceManager nameSpaceM public enum CT_KeyEncryptorUri { /// - [Description("http://schemas.microsoft.com/office/2006/keyEncryptor/password")] + [Description(CT_KeyEncryptorUriParser.httpschemasmicrosoftcomoffice2006keyEncryptorpassword)] httpschemasmicrosoftcomoffice2006keyEncryptorpassword, /// - [Description("http://schemas.microsoft.com/office/2006/keyEncryptor/certificate")] + [Description(CT_KeyEncryptorUriParser.httpschemasmicrosoftcomoffice2006keyEncryptorcertificate)] httpschemasmicrosoftcomoffice2006keyEncryptorcertificate, } + internal static class CT_KeyEncryptorUriParser + { + public const string httpschemasmicrosoftcomoffice2006keyEncryptorpassword = "http://schemas.microsoft.com/office/2006/keyEncryptor/password"; + public const string httpschemasmicrosoftcomoffice2006keyEncryptorcertificate = "http://schemas.microsoft.com/office/2006/keyEncryptor/certificate"; + + public static CT_KeyEncryptorUri Parse(string uri) => uri switch + { + httpschemasmicrosoftcomoffice2006keyEncryptorcertificate => CT_KeyEncryptorUri.httpschemasmicrosoftcomoffice2006keyEncryptorcertificate, + httpschemasmicrosoftcomoffice2006keyEncryptorpassword => CT_KeyEncryptorUri.httpschemasmicrosoftcomoffice2006keyEncryptorpassword, + _ => throw new ArgumentOutOfRangeException(nameof(uri)) + }; + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3761.0")] [System.SerializableAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] diff --git a/OpenXmlFormats/NPOI.OpenXmlFormats.Core.csproj b/OpenXmlFormats/NPOI.OpenXmlFormats.Core.csproj index 520e3a5e1..d8261b569 100644 --- a/OpenXmlFormats/NPOI.OpenXmlFormats.Core.csproj +++ b/OpenXmlFormats/NPOI.OpenXmlFormats.Core.csproj @@ -1,7 +1,7 @@  - net472;netstandard2.0;netstandard2.1;net6.0 + net472;netstandard2.0;netstandard2.1;net6.0;net8.0 NPOI.OpenXmlFormats NPOI.OpenXmlFormats true diff --git a/OpenXmlFormats/Shared/Math.cs b/OpenXmlFormats/Shared/Math.cs index b49742489..21242a803 100644 --- a/OpenXmlFormats/Shared/Math.cs +++ b/OpenXmlFormats/Shared/Math.cs @@ -15,7 +15,7 @@ using NPOI.OpenXml4Net.Util; using NPOI.OpenXmlFormats.Dml.WordProcessing; using System.ComponentModel; -using EnumsNET; +using System.Runtime.CompilerServices; namespace NPOI.OpenXmlFormats.Shared { @@ -720,7 +720,7 @@ public static CT_BreakBinSub Parse(XmlNode node, XmlNamespaceManager namespaceMa internal void Write(StreamWriter sw, string nodeName) { sw.Write(string.Format(""); } @@ -758,18 +758,32 @@ public enum ST_BreakBinSub { - [Description("--")] + [Description(ST_BreakBinSubParser.Item)] Item, - [Description("-+")] + [Description(ST_BreakBinSubParser.Item1)] Item1, - [Description("+-")] + [Description(ST_BreakBinSubParser.Item2)] Item2, } + internal static class ST_BreakBinSubParser + { + public const string Item = "--"; + public const string Item1 = "-+"; + public const string Item2 = "+-"; + + public static string AsString(this ST_BreakBinSub val) => val switch + { + ST_BreakBinSub.Item => Item, + ST_BreakBinSub.Item1 => Item1, + ST_BreakBinSub.Item2 => Item2, + _ => throw new ArgumentOutOfRangeException(nameof(val)) + }; + } [Serializable] diff --git a/OpenXmlFormats/Spreadsheet/AutoFilter.cs b/OpenXmlFormats/Spreadsheet/AutoFilter.cs index 3b0612a45..41d2d0077 100644 --- a/OpenXmlFormats/Spreadsheet/AutoFilter.cs +++ b/OpenXmlFormats/Spreadsheet/AutoFilter.cs @@ -15,7 +15,6 @@ using System.Xml; using NPOI.OpenXml4Net.Util; using System.IO; -using EnumsNET; namespace NPOI.OpenXmlFormats.Spreadsheet { @@ -979,74 +978,138 @@ public bool iconIdSpecified public enum ST_IconSetType { - [Description("3Arrows")] + [Description(ST_IconSetTypeParser.Item3Arrows)] Item3Arrows, - [Description("3ArrowsGray")] + [Description(ST_IconSetTypeParser.Item3ArrowsGray)] Item3ArrowsGray, - [Description("3Flags")] + [Description(ST_IconSetTypeParser.Item3Flags)] Item3Flags, - [Description("3TrafficLights1")] + [Description(ST_IconSetTypeParser.Item3TrafficLights1)] Item3TrafficLights1, - [Description("3TrafficLights2")] + [Description(ST_IconSetTypeParser.Item3TrafficLights2)] Item3TrafficLights2, - [Description("3Signs")] + [Description(ST_IconSetTypeParser.Item3Signs)] Item3Signs, - [Description("3Symbols")] + [Description(ST_IconSetTypeParser.Item3Symbols)] Item3Symbols, - [Description("3Symbols2")] + [Description(ST_IconSetTypeParser.Item3Symbols2)] Item3Symbols2, - [Description("4Arrows")] + [Description(ST_IconSetTypeParser.Item4Arrows)] Item4Arrows, - [Description("4ArrowsGray")] + [Description(ST_IconSetTypeParser.Item4ArrowsGray)] Item4ArrowsGray, - [Description("4RedToBlack")] + [Description(ST_IconSetTypeParser.Item4RedToBlack)] Item4RedToBlack, - [Description("4Rating")] + [Description(ST_IconSetTypeParser.Item4Rating)] Item4Rating, - [Description("4TrafficLights")] + [Description(ST_IconSetTypeParser.Item4TrafficLights)] Item4TrafficLights, - [Description("5Arrows")] + [Description(ST_IconSetTypeParser.Item5Arrows)] Item5Arrows, - [Description("5ArrowsGray")] + [Description(ST_IconSetTypeParser.Item5ArrowsGray)] Item5ArrowsGray, - [Description("5Rating")] + [Description(ST_IconSetTypeParser.Item5Rating)] Item5Rating, - [Description("5Quarters")] + [Description(ST_IconSetTypeParser.Item5Quarters)] Item5Quarters, } + public static class ST_IconSetTypeParser + { + public const string Item3Arrows = "3Arrows"; + public const string Item3ArrowsGray = "3ArrowsGray"; + public const string Item3Flags = "3Flags"; + public const string Item3TrafficLights1 = "3TrafficLights1"; + public const string Item3TrafficLights2 = "3TrafficLights2"; + public const string Item3Signs = "3Signs"; + public const string Item3Symbols = "3Symbols"; + public const string Item3Symbols2 = "3Symbols2"; + public const string Item4Arrows = "4Arrows"; + public const string Item4ArrowsGray = "4ArrowsGray"; + public const string Item4RedToBlack = "4RedToBlack"; + public const string Item4Rating = "4Rating"; + public const string Item4TrafficLights = "4TrafficLights"; + public const string Item5Arrows = "5Arrows"; + public const string Item5ArrowsGray = "5ArrowsGray"; + public const string Item5Rating = "5Rating"; + public const string Item5Quarters = "5Quarters"; + + public static ST_IconSetType Parse(string name) => name switch + { + Item3Arrows => ST_IconSetType.Item3Arrows, + Item3ArrowsGray => ST_IconSetType.Item3ArrowsGray, + Item3Flags => ST_IconSetType.Item3Flags, + Item3TrafficLights1 => ST_IconSetType.Item3TrafficLights1, + Item3TrafficLights2 => ST_IconSetType.Item3TrafficLights2, + Item3Signs => ST_IconSetType.Item3Signs, + Item3Symbols => ST_IconSetType.Item3Symbols, + Item3Symbols2 => ST_IconSetType.Item3Symbols2, + Item4Arrows => ST_IconSetType.Item4Arrows, + Item4ArrowsGray => ST_IconSetType.Item4ArrowsGray, + Item4RedToBlack => ST_IconSetType.Item4RedToBlack, + Item4Rating => ST_IconSetType.Item4Rating, + Item4TrafficLights => ST_IconSetType.Item4TrafficLights, + Item5Arrows => ST_IconSetType.Item5Arrows, + Item5ArrowsGray => ST_IconSetType.Item5ArrowsGray, + Item5Rating => ST_IconSetType.Item5Rating, + Item5Quarters => ST_IconSetType.Item5Quarters, + _ => throw new ArgumentOutOfRangeException(nameof(name)) + }; + + public static string AsString(this ST_IconSetType val) => val switch + { + ST_IconSetType.Item3Arrows => Item3Arrows, + ST_IconSetType.Item3ArrowsGray => Item3ArrowsGray, + ST_IconSetType.Item3Flags => Item3Flags, + ST_IconSetType.Item3TrafficLights1 => Item3TrafficLights1, + ST_IconSetType.Item3TrafficLights2 => Item3TrafficLights2, + ST_IconSetType.Item3Signs => Item3Signs, + ST_IconSetType.Item3Symbols => Item3Symbols, + ST_IconSetType.Item3Symbols2 => Item3Symbols2, + ST_IconSetType.Item4Arrows => Item4Arrows, + ST_IconSetType.Item4ArrowsGray => Item4ArrowsGray, + ST_IconSetType.Item4RedToBlack => Item4RedToBlack, + ST_IconSetType.Item4Rating => Item4Rating, + ST_IconSetType.Item4TrafficLights => Item4TrafficLights, + ST_IconSetType.Item5Arrows => Item5Arrows, + ST_IconSetType.Item5ArrowsGray => Item5ArrowsGray, + ST_IconSetType.Item5Rating => Item5Rating, + ST_IconSetType.Item5Quarters => Item5Quarters, + _ => throw new ArgumentOutOfRangeException(nameof(val)) + }; + } public class CT_Top10 { @@ -1318,7 +1381,7 @@ public static CT_SortCondition Parse(XmlNode node, XmlNamespaceManager namespace if (node.Attributes["dxfId"] != null) ctObj.dxfId = XmlHelper.ReadUInt(node.Attributes["dxfId"]); if (node.Attributes["iconSet"] != null) - ctObj.iconSet = Enums.Parse(node.Attributes["iconSet"].Value,false, EnumFormat.Description); + ctObj.iconSet = ST_IconSetTypeParser.Parse(node.Attributes["iconSet"].Value); if (node.Attributes["iconId"] != null) ctObj.iconId = XmlHelper.ReadUInt(node.Attributes["iconId"]); return ctObj; @@ -1334,7 +1397,7 @@ internal void Write(StreamWriter sw, string nodeName) XmlHelper.WriteAttribute(sw, "ref", this.@ref); XmlHelper.WriteAttribute(sw, "customList", this.customList); XmlHelper.WriteAttribute(sw, "dxfId", this.dxfId); - XmlHelper.WriteAttribute(sw, "iconSet", this.iconSet.AsString(EnumFormat.Description)); + XmlHelper.WriteAttribute(sw, "iconSet", this.iconSet.AsString()); XmlHelper.WriteAttribute(sw, "iconId", this.iconId); sw.Write("/>"); } diff --git a/OpenXmlFormats/Spreadsheet/Workbook/CT_WebPublishObjects.cs b/OpenXmlFormats/Spreadsheet/Workbook/CT_WebPublishObjects.cs index 310bf9c37..ea0b853fd 100644 --- a/OpenXmlFormats/Spreadsheet/Workbook/CT_WebPublishObjects.cs +++ b/OpenXmlFormats/Spreadsheet/Workbook/CT_WebPublishObjects.cs @@ -6,54 +6,97 @@ using System.Text; using System.Xml; using System.Xml.Serialization; -using EnumsNET; namespace NPOI.OpenXmlFormats.Spreadsheet -{ +{ public enum ST_TargetScreenSize { - [Description("544x376")] + [Description(ST_TargetScreenSizeParser.Item544x376)] Item544x376, - [Description("640x480")] + [Description(ST_TargetScreenSizeParser.Item640x480)] Item640x480, - [Description("720x512")] + [Description(ST_TargetScreenSizeParser.Item720x512)] Item720x512, - [Description("800x600")] + [Description(ST_TargetScreenSizeParser.Item800x600)] Item800x600, - [Description("1024x768")] + [Description(ST_TargetScreenSizeParser.Item1024x768)] Item1024x768, - [Description("1152x882")] + [Description(ST_TargetScreenSizeParser.Item1152x882)] Item1152x882, - [Description("1152x900")] + [Description(ST_TargetScreenSizeParser.Item1152x900)] Item1152x900, - [Description("1280x1024")] + [Description(ST_TargetScreenSizeParser.Item1280x1024)] Item1280x1024, - [Description("1600x1200")] + [Description(ST_TargetScreenSizeParser.Item1600x1200)] Item1600x1200, - [Description("1800x1440")] + [Description(ST_TargetScreenSizeParser.Item1800x1440)] Item1800x1440, - [Description("1920x1200")] + [Description(ST_TargetScreenSizeParser.Item1920x1200)] Item1920x1200, } + internal static class ST_TargetScreenSizeParser + { + public const string Item544x376 = "544x376"; + public const string Item640x480 = "640x480"; + public const string Item720x512 = "720x512"; + public const string Item800x600 = "800x600"; + public const string Item1024x768 = "1024x768"; + public const string Item1152x882 = "1152x882"; + public const string Item1152x900 = "1152x900"; + public const string Item1280x1024 = "1280x1024"; + public const string Item1600x1200 = "1600x1200"; + public const string Item1800x1440 = "1800x1440"; + public const string Item1920x1200 = "1920x1200"; + public static string AsString(this ST_TargetScreenSize targetScreenSize) => targetScreenSize switch + { + ST_TargetScreenSize.Item544x376 => Item544x376, + ST_TargetScreenSize.Item640x480 => Item640x480, + ST_TargetScreenSize.Item720x512 => Item720x512, + ST_TargetScreenSize.Item800x600 => Item800x600, + ST_TargetScreenSize.Item1024x768 => Item1024x768, + ST_TargetScreenSize.Item1152x882 => Item1152x882, + ST_TargetScreenSize.Item1152x900 => Item1152x900, + ST_TargetScreenSize.Item1280x1024 => Item1280x1024, + ST_TargetScreenSize.Item1600x1200 => Item1600x1200, + ST_TargetScreenSize.Item1800x1440 => Item1800x1440, + ST_TargetScreenSize.Item1920x1200 => Item1920x1200, + _ => throw new ArgumentOutOfRangeException(nameof(targetScreenSize)) + }; + public static ST_TargetScreenSize Parse(string desc) => desc switch + { + Item544x376 => ST_TargetScreenSize.Item544x376, + Item640x480 => ST_TargetScreenSize.Item640x480, + Item720x512 => ST_TargetScreenSize.Item720x512, + Item800x600 => ST_TargetScreenSize.Item800x600, + Item1024x768 => ST_TargetScreenSize.Item1024x768, + Item1152x882 => ST_TargetScreenSize.Item1152x882, + Item1152x900 => ST_TargetScreenSize.Item1152x900, + Item1280x1024 => ST_TargetScreenSize.Item1280x1024, + Item1600x1200 => ST_TargetScreenSize.Item1600x1200, + Item1800x1440 => ST_TargetScreenSize.Item1800x1440, + Item1920x1200 => ST_TargetScreenSize.Item1920x1200, + _ => throw new ArgumentOutOfRangeException(nameof(desc)) + }; + } [Serializable] [XmlType(Namespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main")] public class CT_WebPublishing @@ -88,7 +131,7 @@ public static CT_WebPublishing Parse(XmlNode node, XmlNamespaceManager namespace ctObj.allowPng = XmlHelper.ReadBool(node.Attributes["allowPng"]); if (node.Attributes["targetScreenSize"] != null) { - ctObj.targetScreenSize = Enums.Parse(node.Attributes["targetScreenSize"].Value,false, EnumFormat.Description); + ctObj.targetScreenSize = ST_TargetScreenSizeParser.Parse(node.Attributes["targetScreenSize"].Value); } ctObj.dpi = XmlHelper.ReadUInt(node.Attributes["dpi"]); ctObj.codePage = XmlHelper.ReadUInt(node.Attributes["codePage"]); @@ -105,7 +148,7 @@ internal void Write(StreamWriter sw, string nodeName) XmlHelper.WriteAttribute(sw, "longFileNames", this.longFileNames); XmlHelper.WriteAttribute(sw, "vml", this.vml); XmlHelper.WriteAttribute(sw, "allowPng", this.allowPng); - XmlHelper.WriteAttribute(sw, "targetScreenSize", this.targetScreenSize.AsString(EnumFormat.Description)); + XmlHelper.WriteAttribute(sw, "targetScreenSize", this.targetScreenSize.AsString()); XmlHelper.WriteAttribute(sw, "dpi", this.dpi); XmlHelper.WriteAttribute(sw, "codePage", this.codePage); sw.Write(">"); diff --git a/main/NPOI.Core.csproj b/main/NPOI.Core.csproj index 0a09cd6ce..0acc37ae2 100644 --- a/main/NPOI.Core.csproj +++ b/main/NPOI.Core.csproj @@ -1,7 +1,7 @@  - net472;netstandard2.0;netstandard2.1;net6.0 + net472;netstandard2.0;netstandard2.1;net6.0;net8.0 NPOI true ..\npoi.snk @@ -18,7 +18,6 @@ - diff --git a/main/SS/Formula/EvaluationConditionalFormatRule.cs b/main/SS/Formula/EvaluationConditionalFormatRule.cs index 2da873de2..ab59452a8 100644 --- a/main/SS/Formula/EvaluationConditionalFormatRule.cs +++ b/main/SS/Formula/EvaluationConditionalFormatRule.cs @@ -1,5 +1,4 @@ -using EnumsNET; -using NPOI.SS.Formula.Eval; +using NPOI.SS.Formula.Eval; using NPOI.SS.Formula.Functions; using NPOI.SS.UserModel; using NPOI.SS.Util; diff --git a/main/SS/Formula/FormulaType.cs b/main/SS/Formula/FormulaType.cs index eccd2bc7f..806759e94 100644 --- a/main/SS/Formula/FormulaType.cs +++ b/main/SS/Formula/FormulaType.cs @@ -21,7 +21,7 @@ namespace NPOI.SS.Formula { internal class SingleValueAttribute : Attribute { - private bool _isSingleValue=false; + private bool _isSingleValue = false; public SingleValueAttribute(bool isSingleValue) { this._isSingleValue = isSingleValue; @@ -35,7 +35,7 @@ public bool IsSingleValue /// /// Enumeration of various formula types. For internal use only /// - public enum FormulaType:int + public enum FormulaType : int { [SingleValue(true)] Cell = 0, @@ -52,4 +52,13 @@ public enum FormulaType:int [SingleValue(false)] DataValidationList = 5, } + + internal static class FormulaTypeExtensions + { + public static bool IsSingleValue(this FormulaType val) => val switch + { + FormulaType.Cell or FormulaType.Shared or FormulaType.CondFormat => true, + _ => false, + }; + } } \ No newline at end of file diff --git a/main/SS/Formula/Functions/LookupUtils.cs b/main/SS/Formula/Functions/LookupUtils.cs index 1ec6fbcd8..b7f2f4f8a 100644 --- a/main/SS/Formula/Functions/LookupUtils.cs +++ b/main/SS/Formula/Functions/LookupUtils.cs @@ -24,7 +24,7 @@ namespace NPOI.SS.Formula.Functions using System.Globalization; using System.Text.RegularExpressions; using System.Collections.Generic; - using EnumsNET; + using NPOI.Util; /** * Common functionality used by VLOOKUP, HLOOKUP, LOOKUP and MATCH @@ -38,11 +38,11 @@ internal class LookupUtils static LookupUtils() { - foreach (var value in Enums.GetValues()) + foreach (var value in AotExtensions.GetEnumValues()) { matchModeMap.Add((int)value, value); } - foreach (var value in Enums.GetValues()) + foreach (var value in AotExtensions.GetEnumValues()) { searchModeMap.Add((int)value, value); } diff --git a/main/SS/Formula/WorkbookEvaluator.cs b/main/SS/Formula/WorkbookEvaluator.cs index 1cc940c6a..36f3081ee 100644 --- a/main/SS/Formula/WorkbookEvaluator.cs +++ b/main/SS/Formula/WorkbookEvaluator.cs @@ -32,7 +32,6 @@ namespace NPOI.SS.Formula using NPOI.SS.Formula.PTG; using NPOI.Util; using NPOI.SS.Formula.Function; - using EnumsNET; /** * Evaluates formula cells.

@@ -306,7 +305,7 @@ private ValueEval Evaluate(String formula, CellReference target, CellRangeAddres AdjustRegionRelativeReference(ptgs, target, region); OperationEvaluationContext ec = new OperationEvaluationContext(this, Workbook, sheetIndex, target.Row, target.Col, new EvaluationTracker(_cache), - formulaType.GetAttributes().Get().IsSingleValue); + formulaType.IsSingleValue()); return EvaluateNameFormula(ptgs, ec); } protected bool AdjustRegionRelativeReference(Ptg[] ptgs, CellReference target, CellRangeAddressBase region) diff --git a/main/Util/AotExtensions.cs b/main/Util/AotExtensions.cs index f261b0d28..f52ba1d3f 100644 --- a/main/Util/AotExtensions.cs +++ b/main/Util/AotExtensions.cs @@ -33,6 +33,11 @@ public static string GetEnumName(T val) where T : struct, Enum { return Enum.GetName(typeof(T), val); } + + public static string[] GetEnumNames() where T : struct, Enum + { + return Enum.GetNames(typeof(T)); + } #else // AOT-friendly public static T[] GetEnumValues() where T : struct, Enum @@ -44,6 +49,11 @@ public static string GetEnumName(T val) where T : struct, Enum { return Enum.GetName(val); } + + public static string[] GetEnumNames() where T : struct, Enum + { + return Enum.GetNames(); + } #endif } } diff --git a/ooxml/NPOI.OOXML.Core.csproj b/ooxml/NPOI.OOXML.Core.csproj index 3668d87ed..00f85f3f3 100644 --- a/ooxml/NPOI.OOXML.Core.csproj +++ b/ooxml/NPOI.OOXML.Core.csproj @@ -1,7 +1,7 @@  - net472;netstandard2.0;netstandard2.1;net6.0 + net472;netstandard2.0;netstandard2.1;net6.0;net8.0 NPOI.OOXML NPOI true diff --git a/ooxml/XSSF/UserModel/XSSFBuiltinTableStyle.cs b/ooxml/XSSF/UserModel/XSSFBuiltinTableStyle.cs index 9ce559b6a..c4eb98d4d 100644 --- a/ooxml/XSSF/UserModel/XSSFBuiltinTableStyle.cs +++ b/ooxml/XSSF/UserModel/XSSFBuiltinTableStyle.cs @@ -1,5 +1,5 @@ -using EnumsNET; -using NPOI.SS.UserModel; +using NPOI.SS.UserModel; +using NPOI.Util; using NPOI.XSSF.Model; using System; using System.Collections.Generic; @@ -309,11 +309,13 @@ public static ITableStyle GetStyle(XSSFBuiltinTableStyleEnum style) Init(); return styleMap[style]; } + private static readonly HashSet BuiltInStyleNames = new HashSet(AotExtensions.GetEnumNames()); public static bool IsBuiltinStyle(ITableStyle style) { if (style == null) return false; - return Enums.GetNames().Any(x=>x==style.Name); + + return BuiltInStyleNames.Contains(style.Name); } private static void Init() { diff --git a/ooxml/XSSF/UserModel/XSSFConditionalFormattingRule.cs b/ooxml/XSSF/UserModel/XSSFConditionalFormattingRule.cs index 117f949b0..9b6c73c62 100644 --- a/ooxml/XSSF/UserModel/XSSFConditionalFormattingRule.cs +++ b/ooxml/XSSF/UserModel/XSSFConditionalFormattingRule.cs @@ -17,7 +17,6 @@ * ==================================================================== */ -using EnumsNET; using NPOI.OOXML.XSSF.UserModel; using NPOI.OpenXmlFormats.Spreadsheet; using NPOI.SS.UserModel; @@ -295,7 +294,7 @@ public XSSFIconMultiStateFormatting CreateMultiStateFormatting(IconSet iconSet) // Set the type of the icon set if (iconSet.name != null) { - ST_IconSetType xIconSet =Enums.Parse(iconSet.name, false, EnumFormat.Description); + ST_IconSetType xIconSet = ST_IconSetTypeParser.Parse(iconSet.name); icons.iconSet = xIconSet; } diff --git a/ooxml/XSSF/UserModel/XSSFIconMultiStateFormatting.cs b/ooxml/XSSF/UserModel/XSSFIconMultiStateFormatting.cs index e4e8f0f5c..3070e2786 100644 --- a/ooxml/XSSF/UserModel/XSSFIconMultiStateFormatting.cs +++ b/ooxml/XSSF/UserModel/XSSFIconMultiStateFormatting.cs @@ -19,7 +19,6 @@ namespace NPOI.XSSF.UserModel { using System; - using EnumsNET; using NPOI.OpenXmlFormats.Spreadsheet; using NPOI.SS.UserModel; using NPOI.XSSF.Util; @@ -47,7 +46,7 @@ public IconSet IconSet } set { - ST_IconSetType xIconSet = Enums.Parse(value.name, false, EnumFormat.Description); + ST_IconSetType xIconSet = ST_IconSetTypeParser.Parse(value.name); _iconset.iconSet = (xIconSet); } } diff --git a/ooxml/XSSF/UserModel/XSSFTableStyle.cs b/ooxml/XSSF/UserModel/XSSFTableStyle.cs index 7fb00a66e..025cbad5b 100644 --- a/ooxml/XSSF/UserModel/XSSFTableStyle.cs +++ b/ooxml/XSSF/UserModel/XSSFTableStyle.cs @@ -1,9 +1,7 @@ using NPOI.OpenXmlFormats.Spreadsheet; using NPOI.SS.UserModel; -using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; -using EnumsNET; namespace NPOI.OOXML.XSSF.UserModel { @@ -22,7 +20,7 @@ public XSSFTableStyle(int index, CT_Dxfs dxfs, CT_TableStyle tableStyle, IIndexe foreach (CT_TableStyleElement element in tableStyle.tableStyleElement) { - TableStyleType type = Enums.Parse(element.type.GetName()); + TableStyleType type = Translate(element.type); DifferentialStyleProvider dstyle = null; if (element.dxfIdSpecified) { @@ -30,12 +28,45 @@ public XSSFTableStyle(int index, CT_Dxfs dxfs, CT_TableStyle tableStyle, IIndexe CT_Dxf dxf; dxf = dxfList[idx]; int stripeSize = 0; - if (element.size!=0) stripeSize = (int)element.size; + if (element.size != 0) stripeSize = (int)element.size; if (dxf != null) dstyle = new XSSFDxfStyleProvider(dxf, stripeSize, colorMap); } elementMap.Add(type, dstyle); } } + + private static TableStyleType Translate(ST_TableStyleType type) => type switch + { + ST_TableStyleType.wholeTable => TableStyleType.wholeTable, + ST_TableStyleType.headerRow => TableStyleType.headerRow, + ST_TableStyleType.totalRow => TableStyleType.totalRow, + ST_TableStyleType.firstColumn => TableStyleType.firstColumn, + ST_TableStyleType.lastColumn => TableStyleType.lastColumn, + ST_TableStyleType.firstRowStripe => TableStyleType.firstRowStripe, + ST_TableStyleType.secondRowStripe => TableStyleType.secondRowStripe, + ST_TableStyleType.firstColumnStripe => TableStyleType.firstColumnStripe, + ST_TableStyleType.secondColumnStripe => TableStyleType.secondColumnStripe, + ST_TableStyleType.firstHeaderCell => TableStyleType.firstHeaderCell, + ST_TableStyleType.lastHeaderCell => TableStyleType.lastHeaderCell, + ST_TableStyleType.firstTotalCell => TableStyleType.firstTotalCell, + ST_TableStyleType.lastTotalCell => TableStyleType.lastTotalCell, + ST_TableStyleType.firstSubtotalColumn => TableStyleType.firstSubtotalColumn, + ST_TableStyleType.secondSubtotalColumn => TableStyleType.secondSubtotalColumn, + ST_TableStyleType.thirdSubtotalColumn => TableStyleType.thirdSubtotalColumn, + ST_TableStyleType.firstSubtotalRow => TableStyleType.firstSubtotalRow, + ST_TableStyleType.secondSubtotalRow => TableStyleType.secondSubtotalRow, + ST_TableStyleType.thirdSubtotalRow => TableStyleType.thirdSubtotalRow, + ST_TableStyleType.blankRow => TableStyleType.blankRow, + ST_TableStyleType.firstColumnSubheading => TableStyleType.firstColumnSubheading, + ST_TableStyleType.secondColumnSubheading => TableStyleType.secondColumnSubheading, + ST_TableStyleType.thirdColumnSubheading => TableStyleType.thirdColumnSubheading, + ST_TableStyleType.firstRowSubheading => TableStyleType.firstRowSubheading, + ST_TableStyleType.secondRowSubheading => TableStyleType.secondRowSubheading, + ST_TableStyleType.thirdRowSubheading => TableStyleType.thirdRowSubheading, + ST_TableStyleType.pageFieldLabels => TableStyleType.pageFieldLabels, + ST_TableStyleType.pageFieldValues => TableStyleType.pageFieldValues, + _ => throw new ArgumentException() + }; public string Name { get { return name; } diff --git a/openxml4Net/NPOI.OpenXml4Net.Core.csproj b/openxml4Net/NPOI.OpenXml4Net.Core.csproj index 37ab25460..5c3a8a21d 100644 --- a/openxml4Net/NPOI.OpenXml4Net.Core.csproj +++ b/openxml4Net/NPOI.OpenXml4Net.Core.csproj @@ -1,7 +1,7 @@  - net472;netstandard2.0;netstandard2.1;net6.0 + net472;netstandard2.0;netstandard2.1;net6.0;net8.0 NPOI.OpenXml4Net NPOI.OpenXml4Net true