private Task InitBuiltInExcelStyleCollections() { _builtInStyls.Clear(); return(Task.Run(() => { // hdt,内容转为嵌入资源 using (Stream s = typeof(BuiltInExcelStyles).Assembly.GetManifestResourceStream("Dt.Xls.BuiltInStyles.xml")) { s.Seek(0L, (SeekOrigin)SeekOrigin.Begin); XDocument document = XDocument.Load(s); List <ExcelFont> fonts = new List <ExcelFont>(); List <Tuple <FillPatternType, ExcelColor, ExcelColor> > fills = new List <Tuple <FillPatternType, ExcelColor, ExcelColor> >(); List <ExcelBorder> borders = new List <ExcelBorder>(); List <ExtendedFormat> list4 = new List <ExtendedFormat>(); Dictionary <int, ExcelNumberFormat> dictionary = new Dictionary <int, ExcelNumberFormat>(); using (IEnumerator <XElement> enumerator = document.Elements().GetEnumerator()) { while (enumerator.MoveNext()) { XElement element = enumerator.Current; if (element.Name.LocalName == "styleSheet") { using (IEnumerator <XElement> enumerator2 = element.Elements().GetEnumerator()) { while (enumerator2.MoveNext()) { XElement element2 = enumerator2.Current; if (element2.Name.LocalName == "numFmts") { using (IEnumerator <XElement> enumerator3 = element2.Elements().GetEnumerator()) { while (enumerator3.MoveNext()) { XElement element3 = enumerator3.Current; int id = element3.GetAttributeValueOrDefaultOfInt32Type("numFmtId", -2147483648); if (id >= 0) { string code = element3.GetAttributeValueOrDefaultOfStringType("formatCode", null); dictionary.Add(id, new ExcelNumberFormat(id, code)); } } continue; } } if (element2.Name.LocalName == "fonts") { using (IEnumerator <XElement> enumerator4 = element2.Elements().GetEnumerator()) { while (enumerator4.MoveNext()) { XElement child = enumerator4.Current; if (child.Name.LocalName == "font") { fonts.Add(XlsxReader.ReadFont(child)); } } continue; } } if (element2.Name.LocalName == "fills") { using (IEnumerator <XElement> enumerator5 = element2.Elements().GetEnumerator()) { while (enumerator5.MoveNext()) { XElement element5 = enumerator5.Current; if (element5.Name.LocalName == "fill") { fills.Add(XlsxReader.ReadFillPattern(element5.Element(XlsxReader.XNames.patternFill))); } } continue; } } if (element2.Name.LocalName == "borders") { using (IEnumerator <XElement> enumerator6 = element2.Elements().GetEnumerator()) { while (enumerator6.MoveNext()) { XElement element6 = enumerator6.Current; if (element6.HasElements) { ExcelBorder border = new ExcelBorder { Left = XlsxReader.GetBorder(element6, "left"), Right = XlsxReader.GetBorder(element6, "right"), Top = XlsxReader.GetBorder(element6, "top"), Bottom = XlsxReader.GetBorder(element6, "bottom") }; borders.Add(border); } } continue; } } if (element2.Name.LocalName == "cellStyleXfs") { using (IEnumerator <XElement> enumerator7 = element2.Elements().GetEnumerator()) { while (enumerator7.MoveNext()) { XElement node = enumerator7.Current; if (node.Name.LocalName == "xf") { list4.Add(XlsxReader.ReadXF(node, fonts, fills, borders, true)); } } continue; } } if (element2.Name.LocalName == "cellStyles") { using (IEnumerator <XElement> enumerator8 = element2.Elements().GetEnumerator()) { while (enumerator8.MoveNext()) { XElement element8 = enumerator8.Current; string str2 = element8.GetAttributeValueOrDefaultOfStringType("name", null); int num2 = element8.GetAttributeValueOrDefaultOfInt32Type("xfId", 0); ExtendedFormat format = list4[num2]; format.IsStyleFormat = true; BuiltInStyleIndex index = (BuiltInStyleIndex)element8.GetAttributeValueOrDefaultOfInt32Type("builtinId", 0); ExcelStyle style = new ExcelStyle { Name = str2, Format = format.Clone() }; if ((style.Format.NumberFormat == null) && dictionary.ContainsKey(style.Format.NumberFormatIndex)) { style.Format.NumberFormat = dictionary[style.Format.NumberFormatIndex]; style.Format.NumberFormatIndex = 0; } style.IsCustomBuiltIn = false; style.BuiltInStyle = index; style.Category = style.GetBuiltInStyleCategory(); _builtInStyls.Add(style); } continue; } } } continue; } } } } } })); }
/// <summary> /// Determines whether the specified <see cref="T:Dt.Xls.ExtendedFormat" /> is equals to the current item /// </summary> /// <param name="excelStyle">The specified <see cref="T:Dt.Xls.ExtendedFormat" /> used to compared with the current item</param> /// <returns> /// <see langword="true" /> if the specified item has the same settings, otherwise, <c>False</c> /// </returns> public bool Equals(ExtendedFormat excelStyle) { int?parentFormatID = null; int?nullable14 = null; if (object.ReferenceEquals(this, excelStyle)) { return(true); } if (excelStyle == null) { return(false); } if ((((this.Border.Equals(excelStyle.Border) && (this.FillPattern == excelStyle.FillPattern)) && ((this.NumberFormatIndex == excelStyle.NumberFormatIndex) && (this.HorizontalAlign == excelStyle.HorizontalAlign))) && (((this.VerticalAlign == excelStyle.VerticalAlign) && (this.IsLocked == excelStyle.IsLocked)) && ((this.Rotation == excelStyle.Rotation) && (this.IsWordWrap == excelStyle.IsWordWrap)))) && ((((this.IsJustfyLastLine == excelStyle.IsJustfyLastLine) && (this.IsShrinkToFit == excelStyle.IsShrinkToFit)) && ((this.IsFirstSymbolApostrophe == excelStyle.IsFirstSymbolApostrophe) && (this.ReadingOrder == excelStyle.ReadingOrder))) && ((this.IsHidden == excelStyle.IsHidden) && (this.Indent == excelStyle.Indent)))) { bool?applyAlignment = this.ApplyAlignment; bool?nullable2 = excelStyle.ApplyAlignment; if ((applyAlignment.GetValueOrDefault() == nullable2.GetValueOrDefault()) && (applyAlignment.HasValue == nullable2.HasValue)) { bool?applyBorder = this.ApplyBorder; bool?nullable4 = excelStyle.ApplyBorder; if ((applyBorder.GetValueOrDefault() == nullable4.GetValueOrDefault()) && (applyBorder.HasValue == nullable4.HasValue)) { bool?applyFill = this.ApplyFill; bool?nullable6 = excelStyle.ApplyFill; if ((applyFill.GetValueOrDefault() == nullable6.GetValueOrDefault()) && (applyFill.HasValue == nullable6.HasValue)) { bool?applyFont = this.ApplyFont; bool?nullable8 = excelStyle.ApplyFont; if ((applyFont.GetValueOrDefault() == nullable8.GetValueOrDefault()) && (applyFont.HasValue == nullable8.HasValue)) { bool?applyNumberFormat = this.ApplyNumberFormat; bool?nullable10 = excelStyle.ApplyNumberFormat; if ((applyNumberFormat.GetValueOrDefault() == nullable10.GetValueOrDefault()) && (applyNumberFormat.HasValue == nullable10.HasValue)) { bool?applyProtection = this.ApplyProtection; bool?nullable12 = excelStyle.ApplyProtection; if ((applyProtection.GetValueOrDefault() == nullable12.GetValueOrDefault()) && (applyProtection.HasValue == nullable12.HasValue)) { parentFormatID = this.ParentFormatID; nullable14 = excelStyle.ParentFormatID; } } } } } } } bool flag = (parentFormatID.GetValueOrDefault() == nullable14.GetValueOrDefault()) && (parentFormatID.HasValue == nullable14.HasValue); if (this.Font == null) { if (excelStyle.Font != null) { return(false); } } else { flag = flag && this.Font.Equals(excelStyle.Font); } if ((this.NumberFormat == null) && (excelStyle.NumberFormat != null)) { return(false); } if (this.NumberFormat != null) { flag = flag && this.NumberFormat.Equals(excelStyle.NumberFormat); } if ((this.PatternColor == null) && (excelStyle.PatternColor != null)) { return(false); } if ((this.PatternBackgroundColor == null) && (excelStyle.PatternBackgroundColor != null)) { return(false); } if (this.PatternBackgroundColor != null) { flag = flag && this.PatternBackgroundColor.Equals(excelStyle.PatternBackgroundColor); } if (this.PatternColor != null) { flag = flag && this.PatternColor.Equals(excelStyle.PatternColor); } return(flag); }