diff --git a/ClosedXML/Excel/PivotTables/PivotValues/XLPivotValues.cs b/ClosedXML/Excel/PivotTables/PivotValues/XLPivotValues.cs index ef16caf..e1c4a73 100644 --- a/ClosedXML/Excel/PivotTables/PivotValues/XLPivotValues.cs +++ b/ClosedXML/Excel/PivotTables/PivotValues/XLPivotValues.cs @@ -38,7 +38,7 @@ var pivotValue = new XLPivotValue(sourceName) { CustomName = customName }; _pivotValues.Add(customName, pivotValue); - if (_pivotValues.Count > 1 && !this._pivotTable.ColumnLabels.Any(cl => cl.SourceName == XLConstants.PivotTableValuesSentinalLabel) && !this._pivotTable.RowLabels.Any(rl => rl.SourceName == XLConstants.PivotTableValuesSentinalLabel)) + if (_pivotValues.Count > 1 && this._pivotTable.ColumnLabels.All(cl => cl.SourceName != XLConstants.PivotTableValuesSentinalLabel) && this._pivotTable.RowLabels.All(rl => rl.SourceName != XLConstants.PivotTableValuesSentinalLabel)) _pivotTable.ColumnLabels.Add(XLConstants.PivotTableValuesSentinalLabel); return pivotValue; diff --git a/ClosedXML/Excel/Tables/XLTable.cs b/ClosedXML/Excel/Tables/XLTable.cs index 81429f2..b343b51 100644 --- a/ClosedXML/Excel/Tables/XLTable.cs +++ b/ClosedXML/Excel/Tables/XLTable.cs @@ -28,7 +28,7 @@ while (true) { string tableName = String.Concat("Table", id); - if (!Worksheet.Tables.Any(t => t.Name == tableName)) + if (Worksheet.Tables.All(t => t.Name != tableName)) { Name = tableName; AddToTables(range, addToTables); @@ -119,7 +119,7 @@ Int32 colCount = ColumnCount(); for (Int32 i = 1; i <= colCount; i++) { - if (!_fieldNames.Values.Any(f => f.Index == i - 1)) + if (_fieldNames.Values.All(f => f.Index != i - 1)) { var name = "Column" + i; diff --git a/ClosedXML/Excel/XLWorkbook.cs b/ClosedXML/Excel/XLWorkbook.cs index ac9e0d7..20ca064 100644 --- a/ClosedXML/Excel/XLWorkbook.cs +++ b/ClosedXML/Excel/XLWorkbook.cs @@ -546,7 +546,7 @@ private void checkForWorksheetsPresent() { - if (Worksheets.Count() == 0) + if (!Worksheets.Any()) throw new InvalidOperationException("Workbooks need at least one worksheet."); } diff --git a/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/Excel/XLWorkbook_Load.cs index aacb2ab..e5991e1 100644 --- a/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/Excel/XLWorkbook_Load.cs @@ -1248,12 +1248,12 @@ var comment = definedName.Comment; if (localSheetId == null) { - if (!NamedRanges.Any(nr => nr.Name == name)) + if (NamedRanges.All(nr => nr.Name != name)) (NamedRanges as XLNamedRanges).Add(name, text, comment, true).Visible = visible; } else { - if (!Worksheet(Int32.Parse(localSheetId) + 1).NamedRanges.Any(nr => nr.Name == name)) + if (Worksheet(Int32.Parse(localSheetId) + 1).NamedRanges.All(nr => nr.Name != name)) (Worksheet(Int32.Parse(localSheetId) + 1).NamedRanges as XLNamedRanges).Add(name, text, comment, true).Visible = visible; } } @@ -1729,7 +1729,7 @@ if (columns == null) return; var wsDefaultColumn = - columns.Elements().Where(c => c.Max == XLHelper.MaxColumnNumber).FirstOrDefault(); + columns.Elements().FirstOrDefault(c => c.Max == XLHelper.MaxColumnNumber); if (wsDefaultColumn != null && wsDefaultColumn.Width != null) ws.ColumnWidth = wsDefaultColumn.Width - ColumnWidthOffset; diff --git a/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/Excel/XLWorkbook_Save.cs index 3411fea..e4a1a5d 100644 --- a/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/Excel/XLWorkbook_Save.cs @@ -309,10 +309,10 @@ } // Remove any orphaned references - maybe more types? - foreach (var orphan in worksheetPart.Worksheet.OfType().Where(lg => !worksheetPart.Parts.Any(p => p.RelationshipId == lg.Id))) + foreach (var orphan in worksheetPart.Worksheet.OfType().Where(lg => worksheetPart.Parts.All(p => p.RelationshipId != lg.Id))) worksheetPart.Worksheet.RemoveChild(orphan); - foreach (var orphan in worksheetPart.Worksheet.OfType().Where(d => !worksheetPart.Parts.Any(p => p.RelationshipId == d.Id))) + foreach (var orphan in worksheetPart.Worksheet.OfType().Where(d => worksheetPart.Parts.All(p => p.RelationshipId != d.Id))) worksheetPart.Worksheet.RemoveChild(orphan); } @@ -668,7 +668,7 @@ rId = xlSheet.RelId; } - if (!workbook.Sheets.Cast().Any(s => s.Id == rId)) + if (workbook.Sheets.Cast().All(s => s.Id != rId)) { var newSheet = new Sheet { @@ -2606,7 +2606,7 @@ pivotTableDefinition.AppendChild(rowItems); } - if (!pt.ColumnLabels.Any(cl => cl.CustomName != XLConstants.PivotTableValuesSentinalLabel)) + if (pt.ColumnLabels.All(cl => cl.CustomName == XLConstants.PivotTableValuesSentinalLabel)) { for (int i = 0; i < pt.Values.Count(); i++) { @@ -4994,7 +4994,7 @@ } var exlst = from c in xlWorksheet.ConditionalFormats where c.ConditionalFormatType == XLConditionalFormatType.DataBar && c.Colors.Count > 1 && typeof(IXLConditionalFormat).IsAssignableFrom(c.GetType()) select c; - if (exlst != null && exlst.Count() > 0) + if (exlst != null && exlst.Any()) { if (!worksheetPart.Worksheet.Elements().Any()) { diff --git a/ClosedXML/Utils/OpenXmlHelper.cs b/ClosedXML/Utils/OpenXmlHelper.cs index 6f0c7a2..950ed19 100644 --- a/ClosedXML/Utils/OpenXmlHelper.cs +++ b/ClosedXML/Utils/OpenXmlHelper.cs @@ -11,7 +11,7 @@ public static bool GetBooleanValueAsBool(BooleanValue value, bool defaultValue) { - return value == null ? defaultValue : value.Value; + return value.HasValue ? value.Value : defaultValue; } } -} \ No newline at end of file +}