Skip to content

Commit f4e926b

Browse files
authored
Small fixes and cleanups (#74)
* pivot small fixes * more small fixes for pivot
1 parent 403a7db commit f4e926b

File tree

6 files changed

+10
-11
lines changed

6 files changed

+10
-11
lines changed

ClosedXML.Report/Excel/Subtotal.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ public void GroupBy(int groupBy, SubtotalSummaryFunc[] summaries, bool pageBreak
7171
_pageBreaks = pageBreaks;
7272
_getGroupLabel = getGroupLabel;
7373

74-
int level;
7574
var rows = Sheet.Rows(_range.RangeAddress.FirstAddress.RowNumber, _range.RangeAddress.LastAddress.RowNumber);
76-
level = Math.Min(8, rows.Max(r => r.OutlineLevel) + 1);
75+
var level = Math.Min(8, rows.Max(r => r.OutlineLevel) + 1);
7776

7877
var grRanges = ScanRange(groupBy);
7978
int grCnt = grRanges.Count(x => x.Type == RangeType.DataRange);
@@ -302,9 +301,8 @@ public SubtotalGroup[] ScanForGroups(int groupBy)
302301
{
303302
var grRanges = ScanRange(groupBy);
304303
var result = new List<SubtotalGroup>(grRanges.Length);
305-
int level;
306304
var rows = Sheet.Rows(_range.RangeAddress.FirstAddress.RowNumber, _range.RangeAddress.LastAddress.RowNumber);
307-
level = Math.Min(8, rows.Max(r => r.OutlineLevel) + 1);
305+
var level = Math.Min(8, rows.Max(r => r.OutlineLevel) + 1);
308306

309307
foreach (var moveData in grRanges)
310308
{

ClosedXML.Report/Excel/XlExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ public static void ReplaceCFFormulaeToA1(this IXLWorksheet worksheet)
301301
{
302302
foreach (var format in worksheet.ConditionalFormats)
303303
{
304-
var target = format.Range.FirstCell();
304+
var target = format.Ranges.OrderBy(x=>x.RangeAddress.FirstAddress.RowNumber)
305+
.ThenBy(x=> x.RangeAddress.FirstAddress.ColumnNumber)
306+
.First().FirstCell();
305307
foreach (var v in format.Values.Where(v => v.Value.Value.StartsWith("&=")).ToList())
306308
{
307309
var f = v.Value.Value.Substring(1);

ClosedXML.Report/Options/OnlyValuesTag.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ OPTION OBJECTS
66
================================================
77
*/
88

9-
using ClosedXML.Excel;
109
using MoreLinq;
1110

1211
namespace ClosedXML.Report.Options

ClosedXML.Report/Options/PivotTag.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ private void BuildFormatting(PivotTag pivot, DataPivotTag tag, IXLPivotValue pf)
189189

190190
private IXLPivotTable CreatePivot(PivotTag pivot, ProcessingContext context, IXLWorksheet targetSheet, string tableName, IXLCell targetCell)
191191
{
192-
IXLRange srcRange = context.Range.Offset(-1, 1, context.Range.RowCount(), context.Range.ColumnCount() - 1);
192+
var rowOffset = context.Range.RangeAddress.FirstAddress.RowNumber > 1 ? -1 : 0;
193+
IXLRange srcRange = context.Range.Offset(rowOffset, 1, context.Range.RowCount(), context.Range.ColumnCount() - 1);
193194
var pt = targetSheet.PivotTables.Add(tableName, targetCell, srcRange);
194195
pt.MergeAndCenterWithLabels = pivot.HasParameter("MergeLabels");
195196
pt.ShowExpandCollapseButtons = pivot.HasParameter("ShowButtons");

ClosedXML.Report/Options/ProtectedTag.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ OPTION PARAMS OBJECTS
77
================================================
88
*/
99
using System;
10-
using System.Collections;
1110
using ClosedXML.Excel;
1211
using ClosedXML.Report.Excel;
1312
using MoreLinq;

ClosedXML.Report/RangeInterpreter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Collections;
1+
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
3-
using System.Diagnostics;
44
using System.Linq;
55
using System.Reflection;
66
using ClosedXML.Excel;
@@ -17,7 +17,7 @@ internal class RangeInterpreter
1717
private readonly string _alias;
1818
private readonly FormulaEvaluator _evaluator;
1919
private readonly TagsEvaluator _tagsEvaluator;
20-
private readonly Dictionary<string, object> _variables = new Dictionary<string, object>();
20+
private readonly Dictionary<string, object> _variables = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
2121
private readonly Dictionary<string, TagsList> _tags = new Dictionary<string, TagsList>();
2222
private readonly TemplateErrors _errors;
2323

0 commit comments

Comments
 (0)