Skip to content

Commit c5232a5

Browse files
authored
Subtotal for column specific formula (#265)
1 parent 8156eec commit c5232a5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ClosedXML.Report/Excel/XlExtensions.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,19 @@ public static void Subtotal(this IXLRange range, int groupBy, string function, i
186186
subtotal.GroupBy(groupBy, summaries, pageBreaks);
187187
}
188188
}
189-
189+
190+
public static void Subtotal(this IXLRange range, int groupBy, Dictionary<int, string> totalListWithFunctions, bool replace = true, bool pageBreaks = false, bool summaryAbove = false)
191+
{
192+
using (var subtotal = new Subtotal(range, summaryAbove))
193+
{
194+
if (replace)
195+
subtotal.Unsubtotal();
196+
var summaries = totalListWithFunctions.Select(x => new SummaryFuncTag { Name = x.Value.ToLower(), Cell = new TemplateCell { Column = x.Key } }).ToArray();
197+
subtotal.AddGrandTotal(summaries);
198+
subtotal.GroupBy(groupBy, summaries, pageBreaks);
199+
}
200+
}
201+
190202
public static bool IsSummary(this IXLRangeRow row)
191203
{
192204
return row.Cells(x => x.HasFormula && x.FormulaA1.ToLower().Contains("subtotal(")).Any();

0 commit comments

Comments
 (0)