/// <summary> /// Calculates a grand grand total value for a pivot table cell. /// </summary> /// <param name="backingData">The backing data for the grand total cell to calculate.</param> /// <returns>An object value for the cell.</returns> public override object CalculateGrandGrandTotalValue(PivotCellBackingData backingData) { if (Convert.ToDouble(backingData.Result) == 0) { return(null); } else { return(1); } }
/// <summary> /// Calculates a grand grand total value for a pivot table cell. /// </summary> /// <param name="backingData">The backing data for the grand total cell to calculate.</param> /// <returns>An object value for the cell.</returns> public override object CalculateGrandGrandTotalValue(PivotCellBackingData backingData) { var dataField = base.PivotTable.DataFields[base.DataFieldCollectionIndex]; if (!base.PivotTable.RowFields.Any(f => f.Index == dataField.BaseField) && !base.PivotTable.ColumnFields.Any(f => f.Index == dataField.BaseField)) { // If the dataField.BaseField is not a row or column field, all values #N/A! return(ExcelErrorValue.Create(eErrorType.NA)); } return(null); }
/// <summary> /// Calculates a grand total value for a cell. /// </summary> /// <param name="headers">The headers for the grand totals.</param> /// <param name="cellBackingData">The backing data for the current grand total cell.</param> /// <param name="isRowTotal">A value indicating if this is a row grand total.</param> /// <param name="isParentColumnTotal">Bool indicating if % of Parent Total is used.</param> /// <returns>An object value for a cell.</returns> protected object CalculateGrandTotalValue(List <PivotTableHeader> headers, PivotCellBackingData cellBackingData, bool isRowTotal, bool isParentColumnTotal = false) { var currentHeader = headers[cellBackingData.MajorAxisIndex]; List <Tuple <int, int> > parentRowHeaderIndices, parentColumnHeaderIndices; string rowTotalType = string.Empty, columnTotalType = string.Empty; // Data fields do not get a value. if (currentHeader.CacheRecordIndices.Count == 1 && currentHeader.CacheRecordIndices.First().Item1 == -2) { return(null); } // Find the parent indices in order to calculate the parent total value. var headerIndices = currentHeader.CacheRecordIndices.Take(currentHeader.CacheRecordIndices.Count - 1).ToList(); parentRowHeaderIndices = new List <Tuple <int, int> >(); parentColumnHeaderIndices = isParentColumnTotal ? new List <Tuple <int, int> >() : headerIndices; if (!isRowTotal) { // Use the datafield tuple if it exists (for parent row calculator), otherwise, use the tuple list passed in. if (currentHeader.CacheRecordIndices.Any(i => i.Item1 == -2) && currentHeader.CacheRecordIndices.First().Item1 != -2) { parentColumnHeaderIndices = currentHeader.CacheRecordIndices.Where(i => i.Item1 == -2).ToList(); } } var parentBackingData = PivotTableDataManager.GetParentBackingCellValues( this.PivotTable, this.DataFieldCollectionIndex, parentRowHeaderIndices, parentColumnHeaderIndices, rowTotalType, columnTotalType, this.TotalsCalculator); var baseValue = parentBackingData.Result; if (cellBackingData?.Result == null) { // If both are null, write null. if (baseValue == null) { return(null); } // If the parent has a value, write out 0. return(0); } else if (baseValue == null) { return(1); } return(this.CalculatePercentage(Convert.ToDouble(cellBackingData.Result), Convert.ToDouble(baseValue), true)); }
private object GetCellNoCalculationValue(PivotCellBackingData cellBackingData) { // Non-null backing data indicates that this cell is eligible for a value. if (cellBackingData != null && cellBackingData.Result == null && cellBackingData.ShowValue) { if (base.PivotTable.ShowMissing) { return(base.PivotTable.MissingCaption); } return(0); } return(cellBackingData?.Result); }
/// <summary> /// Writes the grand total for the specified <paramref name="backingData"/> in the cell at the specified <paramref name="index"/>. /// </summary> /// <param name="index">The major index of the cell to write the total to.</param> /// <param name="dataField">The data field to use the number format of.</param> /// <param name="backingData">The data to use to calculate the total.</param> protected override void WriteCellTotal(int index, ExcelPivotTableDataField dataField, PivotCellBackingData backingData) { var cell = this.PivotTable.Worksheet.Cells[index, this.PivotTable.Address.End.Column]; var cacheField = this.PivotTable.CacheDefinition.CacheFields[dataField.Index]; var styles = this.PivotTable.Worksheet.Workbook.Styles; base.TotalsCalculator.WriteCellTotal(cell, dataField, backingData, styles); }
/// <summary> /// Updates the specified <paramref name="backingData"/> with the grand total result and corresponding cell location. /// </summary> /// <param name="index">The major index of the corresponding cell.</param> /// <param name="dataFieldCollectionIndex">The index of the data field to use the formula of.</param> /// <param name="backingData">The values to use to calculate the total.</param> protected override void UpdateGrandGrandTotalBackingDataTotal(int index, int dataFieldCollectionIndex, PivotCellBackingData backingData) { var dataField = this.PivotTable.DataFields[dataFieldCollectionIndex]; var value = base.TotalsCalculator.CalculateCellTotal(dataField, backingData); backingData.SheetRow = index; backingData.SheetColumn = this.PivotTable.Address.End.Column; backingData.DataFieldCollectionIndex = dataFieldCollectionIndex; backingData.Result = value; }
/// <summary> /// Calculates a grand grand total value for a pivot table cell. /// </summary> /// <param name="backingData">The backing data for the grand total cell to calculate.</param> /// <returns>An object value for the cell.</returns> public override object CalculateGrandGrandTotalValue(PivotCellBackingData backingData) { return(this.GetCellNoCalculationValue(backingData)); }
/// <summary> /// Calculates a grand grand total value for a pivot table cell. /// </summary> /// <param name="backingData">The backing data for the grand total cell to calculate.</param> /// <returns>An object value for the cell.</returns> public override object CalculateGrandGrandTotalValue(PivotCellBackingData backingData) => 1;
/// <summary> /// Calculates a grand grand total value for a pivot table cell. /// </summary> /// <param name="backingData">The backing data for the grand total cell to calculate.</param> /// <returns>An object value for the cell.</returns> public abstract object CalculateGrandGrandTotalValue(PivotCellBackingData backingData);