EPPlus:数据透视表列中的值 table
EPPlus: Values in column of pivot table
当您在 Excel 中创建数据透视表 table 并将字段添加到行和值时,您会在 GUI 中获得一个额外的字段 [Symbol Sigma] Values
,您可以将其拖放到列。
我正在使用 EPPlus
创建一个 pivot table
。如何将此 [Symbol Sigma] Values
字段添加到我的列字段?
编辑:这是一些代码。我不明白这应该有什么帮助,它被要求做什么。
private static ExcelWorksheet CreatePivotWorksheet(ExcelPackage excel, ExcelWorksheet dataWorksheet)
{
string worksheetName = "Pivot";
ExcelWorksheet pivotWorksheet = excel.Workbook.Worksheets.Add(worksheetName);
ExcelRangeBase dataRange = dataWorksheet.Cells[dataWorksheet.Dimension.Address];
ExcelPivotTable pivotTable = pivotWorksheet.PivotTables.Add(pivotWorksheet.Cells[1,1], dataRange, "pivotTable");
pivotTable.RowGrandTotals = false;
pivotTable.RowFields.Add(pivotTable.Fields["BaseValue"]);
pivotTable.RowFields.Add(pivotTable.Fields["Remaining Runtime"])
.AddNumericGrouping(0, 500000, 30);
pivotTable.RowFields.Add(pivotTable.Fields["Emittent"]);
pivotTable.RowFields.Add(pivotTable.Fields["CountIfs"]);
pivotTable.RowFields.Add(pivotTable.Fields["ISIN"]);
var stressField = pivotTable.DataFields.Add(pivotTable.Fields["StressScenario - Percent"]);
stressField.Function = DataFieldFunctions.Average;
stressField.Format = "0.00%";
var pessimisticField = pivotTable.DataFields.Add(pivotTable.Fields["PessimisticScenario - Percent"]);
pessimisticField.Function = DataFieldFunctions.Average;
pessimisticField.Format = "0.00%";
var mediumField = pivotTable.DataFields.Add(pivotTable.Fields["MediumScenario - Percent"]);
mediumField.Function = DataFieldFunctions.Average;
mediumField.Format = "0.00%";
var optimisticField = pivotTable.DataFields.Add(pivotTable.Fields["optimisticScenario - Percent"]);
optimisticField.Function = DataFieldFunctions.Average;
optimisticField.Format = "0.00%";
// remove subtotals, this has to be done _after_ adding the field (see
foreach (ExcelPivotTableField rowField in pivotTable.RowFields)
{
rowField.SubTotalFunctions = eSubTotalFunctions.None;
}
return pivotWorksheet;
}
尝试设置 pivotTable.DataOnRows = false
以获得这样的枢轴 table 行为
尝试将值行字段更改为列。这里 3 是 Values 字段索引。
PivotField row = (PivotField)oPivotTable.RowFields[3];
row.Orientation = XlPivotFieldOrientation.xlColumnField;
我已经为您的案例找到了解决方案。
您应该在数据字段的代码中添加几个字符串。
数据字段示例 "stressField":
stressField.Field.Outline = true;
stressField.Field.ShowInFieldList=true;
以及其他:
pessimisticField.Field.Outline = true;
pessimisticField.Field.ShowInFieldList=true;
mediumField.Field.Outline = true;
mediumField.Field.ShowInFieldList=true;
optimisticField.Field.Outline = true;
optimisticField.Field.ShowInFieldList=true;
当您在 Excel 中创建数据透视表 table 并将字段添加到行和值时,您会在 GUI 中获得一个额外的字段 [Symbol Sigma] Values
,您可以将其拖放到列。
我正在使用 EPPlus
创建一个 pivot table
。如何将此 [Symbol Sigma] Values
字段添加到我的列字段?
编辑:这是一些代码。我不明白这应该有什么帮助,它被要求做什么。
private static ExcelWorksheet CreatePivotWorksheet(ExcelPackage excel, ExcelWorksheet dataWorksheet)
{
string worksheetName = "Pivot";
ExcelWorksheet pivotWorksheet = excel.Workbook.Worksheets.Add(worksheetName);
ExcelRangeBase dataRange = dataWorksheet.Cells[dataWorksheet.Dimension.Address];
ExcelPivotTable pivotTable = pivotWorksheet.PivotTables.Add(pivotWorksheet.Cells[1,1], dataRange, "pivotTable");
pivotTable.RowGrandTotals = false;
pivotTable.RowFields.Add(pivotTable.Fields["BaseValue"]);
pivotTable.RowFields.Add(pivotTable.Fields["Remaining Runtime"])
.AddNumericGrouping(0, 500000, 30);
pivotTable.RowFields.Add(pivotTable.Fields["Emittent"]);
pivotTable.RowFields.Add(pivotTable.Fields["CountIfs"]);
pivotTable.RowFields.Add(pivotTable.Fields["ISIN"]);
var stressField = pivotTable.DataFields.Add(pivotTable.Fields["StressScenario - Percent"]);
stressField.Function = DataFieldFunctions.Average;
stressField.Format = "0.00%";
var pessimisticField = pivotTable.DataFields.Add(pivotTable.Fields["PessimisticScenario - Percent"]);
pessimisticField.Function = DataFieldFunctions.Average;
pessimisticField.Format = "0.00%";
var mediumField = pivotTable.DataFields.Add(pivotTable.Fields["MediumScenario - Percent"]);
mediumField.Function = DataFieldFunctions.Average;
mediumField.Format = "0.00%";
var optimisticField = pivotTable.DataFields.Add(pivotTable.Fields["optimisticScenario - Percent"]);
optimisticField.Function = DataFieldFunctions.Average;
optimisticField.Format = "0.00%";
// remove subtotals, this has to be done _after_ adding the field (see
foreach (ExcelPivotTableField rowField in pivotTable.RowFields)
{
rowField.SubTotalFunctions = eSubTotalFunctions.None;
}
return pivotWorksheet;
}
尝试设置 pivotTable.DataOnRows = false
以获得这样的枢轴 table 行为
尝试将值行字段更改为列。这里 3 是 Values 字段索引。
PivotField row = (PivotField)oPivotTable.RowFields[3];
row.Orientation = XlPivotFieldOrientation.xlColumnField;
我已经为您的案例找到了解决方案。 您应该在数据字段的代码中添加几个字符串。 数据字段示例 "stressField":
stressField.Field.Outline = true;
stressField.Field.ShowInFieldList=true;
以及其他:
pessimisticField.Field.Outline = true;
pessimisticField.Field.ShowInFieldList=true;
mediumField.Field.Outline = true;
mediumField.Field.ShowInFieldList=true;
optimisticField.Field.Outline = true;
optimisticField.Field.ShowInFieldList=true;