EPPLUS Pivot Table headers in tabular layout doesn't work - c#

I have set the tabular layout according to this solution, but the filters on headers pivot table remains in Compact layout with unique "Row Label" in the first header with all filters.
Microsoft Compact/Tabular Layout
This is the expected result
I think this is a bug of EPPLUS, does anyone have any solution?
I use version 6.1.1.0 of EPPLUS
This is the configuration of my pivot table :
pivotTable.ColumnGrandTotals = true;
pivotTable.Compact = false;
pivotTable.CompactData = false;
pivotTable.DataCaption = "Values";
pivotTable.DataOnRows = false;
pivotTable.ErrorCaption = "[error]";
pivotTable.GridDropZones = true;
pivotTable.Outline = false;
pivotTable.OutlineData = false;
pivotTable.RowGrandTotals = true;
pivotTable.ShowColumnHeaders = true;
pivotTable.ShowError = true;
pivotTable.ShowHeaders = true;
pivotTable.ShowMemberPropertyTips = false;
pivotTable.ShowValuesRow = false;
This is the how I add the fields in RowFields :
var field = pivotTable.Fields[fieldName];
field.Outline = false;
field.Compact = false;
field.SubTotalFunctions = eSubTotalFunctions.None;
field = pivotTable.RowFields.Add(field);
field.ShowDropDowns = true;
field.Items.Refresh();

Found solution , set Outline and Compact to false for each fields of pivot table.
pivotTable.Fields.ForEach(field => { field.Outline = false; field.Compact = false; });

Related

How to get search result value with regular expressions in word document in vsto

I am trying to replace some words in a Word document, but the new text replaced varies depending on the search result. How do I get the value of that result and this My code
WordApp.Selection.Find.ClearFormatting();
//Options
matchWholeWord = true;
WordApp.Selection.Find.Text = #"<[0-9]#>";
WordApp.Selection.Find.Forward = true;
WordApp.Selection.Find.Wrap = Word.WdFindWrap.wdFindContinue;
WordApp.Selection.Find.MatchWholeWord = false;
WordApp.Selection.Find.MatchKashida = false;
WordApp.Selection.Find.MatchDiacritics = false;
WordApp.Selection.Find.MatchAlefHamza = false;
WordApp.Selection.Find.MatchControl = false;
WordApp.Selection.Find.MatchAllWordForms = false;
WordApp.Selection.Find.MatchSoundsLike = false;
WordApp.Selection.Find.MatchWildcards = true;
WordApp.Selection.Find.Execute();
var ResultText= ????;//My problem
string ReplacedText = ResultText.GetNewText();
My problem is that I can't get ResultText to be able to create the Replacedtext and then do the replacement

How can I make EPPlus excel format to tabular instead of Compact?

I tried to set some of the settings such as Compact =false, CompactData = false, etc but nothing worked.
I wanted to separate the "Reviewer and Engagement instead of them in one field. I have posted two photos. The first is the output I have, Second is the one that I am trying to achieve.
enter code
//define the data range on the source sheet
var dataRange = workSheetDataSource.Cells[workSheetDataSource.Dimension.Address];
//create the pivot table
var pivotTable = workSheetMgrAndEng.PivotTables.Add(workSheetMgrAndEng.Cells["A4"], dataRange, "PivotTable");
//label field
pivotTable.RowFields.Add(pivotTable.Fields["Reviewer"]);
pivotTable.RowFields.Add(pivotTable.Fields["Engagement"]);
//pivot field settings
pivotTable.Compact = false;
pivotTable.CompactData = false;
pivotTable.Indent = 0;
//pivotTable.RowGrandTotals = false;
pivotTable.UseAutoFormatting = true;
//pivotTable.ShowMemberPropertyTips = false;
pivotTable.DataOnRows = false;
//data fields
var field1 = pivotTable.DataFields.Add(pivotTable.Fields["Engagement"]);
field1.Name = "Count of Engagement";
field1.Function = DataFieldFunctions.Count;
var field2 = pivotTable.DataFields.Add(pivotTable.Fields["Prep Complete"]);
field2.Name = "Count of Prep Complete";
field2.Function = DataFieldFunctions.Count;
var field3 = pivotTable.DataFields.Add(pivotTable.Fields["Sent Delivered"]);
field3.Name = "Sent/Delivered";
field3.Function = DataFieldFunctions.Count;
var field4 = pivotTable.DataFields.Add(pivotTable.Fields["Return to Tax Office"]);
field4.Name = "Count of Return to Tax Office";
field4.Function = DataFieldFunctions.Count;
//data fields settings
//field1.Field.Outline = false;
field1.Field.Compact = false;
field1.Field.ShowAll = false;
//field1.Field.SubtotalTop = false;
//field2.Field.Outline = false;
field2.Field.Compact = false;
field2.Field.ShowAll = false;
//field2.Field.SubtotalTop = false;
//field3.Field.Outline = false;
field3.Field.Compact = false;
field3.Field.ShowAll = false;
//field3.Field.SubtotalTop = false;
//field4.Field.Outline = false;
field4.Field.Compact = false;
field4.Field.ShowAll = false;
//field4.Field.SubtotalTop = false;

Hiding filter in the pivot table worksheet programatically

I'm trying to find a way to hide the filter field from the worksheet pivot table.
This is my code
// Format the Pivot Table.
pivotTable[1].Format(IExcel.XlPivotFormatType.xlReport2);
pivotTable[1].InGridDropZones = false;
pivotTable[1].SmallGrid = false;
pivotTable[1].ShowTableStyleRowStripes = true;
pivotTable[1].TableStyle2 = "PivotStyleLight1";
// Page Field
FilterPivotField[1] = (IExcel.PivotField)pivotTable[1].PivotFields(2);
FilterPivotField[1].Orientation = IExcel.XlPivotFieldOrientation.xlPageField;
FilterPivotField[1].Position = 1;
FilterPivotField[1].CurrentPage = "0";
Any idea?
Thanks,
Y

A pivot table with page fields must be located above row 3. Current location is A1

Got into a problem with EPPlus.
Want to prepare a second pivottable based on the data of the first pivottable (done using CacheDefinition.SourceRange) and cannot add a filter (PageField).
When I run this is breaks on the last line of this code with the error: "A pivot table with page fields must be located above row 3. Currenct location is A1"...
Dont' know what's wrong here.
CODE:
var reportFilterNames = new List<string>() { "ProjectName" };
var valueNames = new List<string>() { "Value1", "Value2", "Value3" };
ExcelWorksheet wsChart = report.Workbook.Worksheets.Add("Chart-Projects");
var dataRange = pivotTableProjects.CacheDefinition.SourceRange;
ExcelPivotTable pivotTable = wsChart.PivotTables.Add(wsChart.Cells[1, 1], dataRange, "PivotTableChart");
pivotTable.MultipleFieldFilters = true;
pivotTable.RowGrandTotals = true;
pivotTable.ColumGrandTotals = true;
pivotTable.Compact = true;
pivotTable.CompactData = true;
pivotTable.GridDropZones = false;
pivotTable.Outline = false;
pivotTable.OutlineData = false;
pivotTable.ShowError = true;
pivotTable.ErrorCaption = "[ERROR]";
pivotTable.ShowHeaders = true;
pivotTable.UseAutoFormatting = true;
pivotTable.ApplyWidthHeightFormats = true;
pivotTable.ShowDrill = true;
//pivotTable.FirstDataCol = 2;
pivotTable.RowHeaderCaption = "Projects";
pivotTable.Indent = 0;
pivotTable.DataOnRows = true;
foreach (string reportFilterName in reportFilterNames)
pivotTable.PageFields.Add(pivotTable.Fields[reportFilterName]);
Any advise?
For all folkz, I figured it out!
Problem was, that there is NO room to add the filter selection...
When I tweaked that line:
ExcelPivotTable pivotTable = wsChart.PivotTables.Add(wsChart.Cells[1, 1], dataRange, "PivotTableChart");
To that:
ExcelPivotTable pivotTable = wsChart.PivotTables.Add(wsChart.Cells[3, 1], dataRange, "PivotTableChart");
This will give more space before the pivottable and then, the error is gone.
So be aware to add a higher starting row, if you want to add more than one filter.
Hopefully it could help someone in future to see this post.

How to get the datafield function to change to count from sum in EPPlus?

In my Pivot table, I have a data field which I want to be summarized as count. I tried changing the subtotalfunction property to count, but it still shows the sum. Can someone give me an example of how I can do this?
In other words can anyone give me an example of a pivot table in which you can see the count and not the sum.
I'm using EPPlus latest build. 3.1.1
Thanks a lot :)
EDIT: This is what I'm trying.
var wsPivot = package.Workbook.Worksheets.Add("Pivot");
var pivotTable = wsPivot.PivotTables.Add(wsPivot.Cells["A55"], dataRange, "Table");
pivotTable.MultipleFieldFilters = true;
pivotTable.RowGrandTotals = true;
pivotTable.ColumGrandTotals = true;
pivotTable.Compact = true;
pivotTable.CompactData = true;
pivotTable.GridDropZones = false;
pivotTable.Outline = false;
pivotTable.OutlineData = false;
pivotTable.ShowError = true;
pivotTable.ErrorCaption = "[error]";
pivotTable.ShowHeaders = true;
pivotTable.UseAutoFormatting = true;
pivotTable.ApplyWidthHeightFormats = true;
pivotTable.ShowDrill = true;
pivotTable.FirstDataCol = 3;
pivotTable.RowHeaderCaption = "Caption";
var pageField = pivotTable.Fields["field1"];
pivotTable.PageFields.Add(pageField);
var rowField = pivotTable.Fields["cust"];
pivotTable.RowFields.Add(rowField);
var dataField = pivotTable.Fields["id"];
dataField.SubTotalFunctions = OfficeOpenXml.Table.PivotTable.eSubTotalFunctions.Count;
pivotTable.DataFields.Add(dataField);
I figured it out. This worked for me
pivotTable.DataFields.Add(dataField);
pivotTable.DataFields[0].Function = DataFieldFunctions.Count;
This is my findings,
Dim Field As ExcelPivotTableField = pivotTable.Fields(strFieldName)
Dim DataField As ExcelPivotTableDataField = pivotTable.DataFields.Add(Field)
DataField.Function = DataFieldFunctions.Sum

Categories

Resources