• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPOffice / PhpSpreadsheet / 30316250040

28 Jul 2026 12:05AM UTC coverage: 97.119% (-0.05%) from 97.169%
30316250040

Pull #4942

github

web-flow
Merge 4e0bce88d into 540dfb463
Pull Request #4942: Feature/pivot table read

787 of 836 new or added lines in 12 files covered. (94.14%)

49176 of 50635 relevant lines covered (97.12%)

382.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/src/PhpSpreadsheet/Worksheet/PivotTable/PivotField.php
1
<?php
2

3
namespace PhpOffice\PhpSpreadsheet\Worksheet\PivotTable;
4

5
/**
6
 * Read-only representation of a single field within a pivot table.
7
 *
8
 * A pivot field describes how one of the source cache fields is used in the
9
 * pivot table: which axis it is placed on (row, column, page/filter or data),
10
 * and, for value fields, which aggregation function is applied.
11
 *
12
 * @see PivotTable
13
 */
14
class PivotField
15
{
16
    // Axis placement, taken from the pivotField@axis attribute (empty when the
17
    // field is only used as a data/value field or is unused).
18
    const AXIS_ROW = 'axisRow';
19
    const AXIS_COLUMN = 'axisCol';
20
    const AXIS_PAGE = 'axisPage';
21
    const AXIS_VALUES = 'axisValues';
22
    const AXIS_NONE = '';
23

24
    // Aggregation functions for a data (value) field. These map directly to the
25
    // dataField@subtotal attribute values defined by the OOXML spec.
26
    const SUBTOTAL_SUM = 'sum';
27
    const SUBTOTAL_COUNT = 'count';
28
    const SUBTOTAL_AVERAGE = 'average';
29
    const SUBTOTAL_MAX = 'max';
30
    const SUBTOTAL_MIN = 'min';
31
    const SUBTOTAL_PRODUCT = 'product';
32
    const SUBTOTAL_COUNT_NUMS = 'countNums';
33
    const SUBTOTAL_STD_DEV = 'stdDev';
34
    const SUBTOTAL_STD_DEV_P = 'stdDevp';
35
    const SUBTOTAL_VAR = 'var';
36
    const SUBTOTAL_VAR_P = 'varp';
37

38
    /**
39
     * Name of the field, taken from the source cache field it maps to.
40
     */
41
    private string $name;
42

43
    /**
44
     * Zero-based index of the field within the pivot table / cache definition.
45
     */
46
    private int $index;
47

48
    /**
49
     * Axis the field is placed on, one of the AXIS_* constants.
50
     */
51
    private string $axis = self::AXIS_NONE;
52

53
    /**
54
     * True when the field appears in the <dataFields> section (a value field).
55
     */
56
    private bool $dataField = false;
57

58
    /**
59
     * Aggregation function for a data field (e.g. sum, count, average).
60
     * Null when this is not a data field.
61
     */
62
    private ?string $subtotal = null;
63

64
    /**
65
     * Display caption for a data field (e.g. "Sum of Amount"). Null when this
66
     * is not a data field.
67
     */
68
    private ?string $dataFieldCaption = null;
69

70
    public function __construct(int $index, string $name = '')
19✔
71
    {
72
        $this->index = $index;
19✔
73
        $this->name = $name;
19✔
74
    }
75

76
    public function getIndex(): int
10✔
77
    {
78
        return $this->index;
10✔
79
    }
80

81
    public function getName(): string
13✔
82
    {
83
        return $this->name;
13✔
84
    }
85

NEW
86
    public function setName(string $name): self
×
87
    {
NEW
88
        $this->name = $name;
×
89

NEW
90
        return $this;
×
91
    }
92

93
    public function getAxis(): string
13✔
94
    {
95
        return $this->axis;
13✔
96
    }
97

98
    public function setAxis(string $axis): self
19✔
99
    {
100
        $this->axis = $axis;
19✔
101

102
        return $this;
19✔
103
    }
104

105
    public function isDataField(): bool
13✔
106
    {
107
        return $this->dataField;
13✔
108
    }
109

110
    public function setDataField(bool $dataField): self
19✔
111
    {
112
        $this->dataField = $dataField;
19✔
113

114
        return $this;
19✔
115
    }
116

117
    public function getSubtotal(): ?string
11✔
118
    {
119
        return $this->subtotal;
11✔
120
    }
121

122
    public function setSubtotal(?string $subtotal): self
19✔
123
    {
124
        $this->subtotal = $subtotal;
19✔
125

126
        return $this;
19✔
127
    }
128

129
    public function getDataFieldCaption(): ?string
11✔
130
    {
131
        return $this->dataFieldCaption;
11✔
132
    }
133

134
    public function setDataFieldCaption(?string $dataFieldCaption): self
11✔
135
    {
136
        $this->dataFieldCaption = $dataFieldCaption;
11✔
137

138
        return $this;
11✔
139
    }
140
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc