ooxml-core 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/PptxHandler-5UURGJEV.mjs +2 -0
  2. package/dist/{PptxHandler-EX4WBIQQ.mjs → PptxHandler-ADEFY476.mjs} +2 -2
  3. package/dist/PptxHandler-U5XB2HUE.cjs +11 -0
  4. package/dist/automation/index.cjs +744 -192
  5. package/dist/automation/index.mjs +744 -192
  6. package/dist/{chunk-SWF7KVL5.cjs → chunk-3N6XMMTT.cjs} +1365 -1062
  7. package/dist/{chunk-FIELY5PI.mjs → chunk-5NVJN4E6.mjs} +30 -2
  8. package/dist/{chunk-IGOA57LE.mjs → chunk-A6P7G3UK.mjs} +1 -1
  9. package/dist/{chunk-CPKNMQLX.cjs → chunk-AWIDASUW.cjs} +25 -2
  10. package/dist/{chunk-SVQZXP3F.mjs → chunk-CBNKBVX5.mjs} +25 -2
  11. package/dist/{chunk-OXHMZS7B.mjs → chunk-CCHYFCPD.mjs} +649 -172
  12. package/dist/{chunk-OB277ZGE.mjs → chunk-R6KSBNKX.mjs} +27 -1
  13. package/dist/{chunk-AT66SA5M.cjs → chunk-S6DOCMQC.cjs} +28 -0
  14. package/dist/{chunk-WSO4T2LJ.mjs → chunk-WUE5ZHU3.mjs} +26 -3
  15. package/dist/{chunk-LCS3J3QI.mjs → chunk-ZE53K7DH.mjs} +474 -171
  16. package/dist/{chunk-M76PHYRR.mjs → chunk-ZOUGMAZG.mjs} +1 -1
  17. package/dist/docx/layout/adapt-table.d.ts +2 -2
  18. package/dist/docx/layout/adapt-table.d.ts.map +1 -1
  19. package/dist/docx/layout/flow-table.d.ts.map +1 -1
  20. package/dist/docx/layout/index.cjs +477 -75
  21. package/dist/docx/layout/index.mjs +477 -76
  22. package/dist/docx/layout/nested-frame-profile.d.ts +9 -0
  23. package/dist/docx/layout/nested-frame-profile.d.ts.map +1 -0
  24. package/dist/docx/layout/page-cursor.d.ts +2 -0
  25. package/dist/docx/layout/page-cursor.d.ts.map +1 -1
  26. package/dist/docx/layout/result.d.ts +13 -0
  27. package/dist/docx/layout/result.d.ts.map +1 -1
  28. package/dist/docx/layout/table-border-layout.d.ts +16 -0
  29. package/dist/docx/layout/table-border-layout.d.ts.map +1 -0
  30. package/dist/docx/layout/table-cell-layout.d.ts +2 -1
  31. package/dist/docx/layout/table-cell-layout.d.ts.map +1 -1
  32. package/dist/docx/layout/table-content.d.ts +4 -0
  33. package/dist/docx/layout/table-content.d.ts.map +1 -0
  34. package/dist/docx/layout/table-footnotes.d.ts +5 -0
  35. package/dist/docx/layout/table-footnotes.d.ts.map +1 -1
  36. package/dist/docx/layout/table-frames.d.ts +4 -0
  37. package/dist/docx/layout/table-frames.d.ts.map +1 -0
  38. package/dist/docx/layout/table-layout.d.ts +8 -3
  39. package/dist/docx/layout/table-layout.d.ts.map +1 -1
  40. package/dist/docx/layout/table-note-completion.d.ts +5 -0
  41. package/dist/docx/layout/table-note-completion.d.ts.map +1 -0
  42. package/dist/docx/layout/table-note-stories.d.ts +6 -0
  43. package/dist/docx/layout/table-note-stories.d.ts.map +1 -0
  44. package/dist/pptx/automation/index.cjs +535 -182
  45. package/dist/pptx/automation/index.d.ts +4 -4
  46. package/dist/pptx/automation/index.mjs +5 -5
  47. package/dist/pptx/chunks/{index-BZh-IMkN.d.ts → index-Cuxtr76Y.d.ts} +17 -3
  48. package/dist/pptx/chunks/index-Cuxtr76Y.d.ts.map +1 -0
  49. package/dist/pptx/chunks/{index-B4cnSPNz.d.ts → index-DUCGeZh7.d.ts} +65 -5
  50. package/dist/pptx/chunks/index-DUCGeZh7.d.ts.map +1 -0
  51. package/dist/pptx/chunks/{smart-art-Q2kZQtHh.d.ts → smart-art-D-sXa_Nb.d.ts} +11 -1
  52. package/dist/pptx/chunks/smart-art-D-sXa_Nb.d.ts.map +1 -0
  53. package/dist/pptx/chunks/{text-operations-BLodkuXE.d.ts → text-operations-BqHmLaLA.d.ts} +26 -2
  54. package/dist/pptx/chunks/text-operations-BqHmLaLA.d.ts.map +1 -0
  55. package/dist/pptx/cli/index.cjs +535 -182
  56. package/dist/pptx/cli/index.d.ts +1 -1
  57. package/dist/pptx/cli/index.mjs +4 -4
  58. package/dist/pptx/converter/index.cjs +1 -0
  59. package/dist/pptx/converter/index.d.ts +1 -1
  60. package/dist/pptx/converter/index.mjs +2 -2
  61. package/dist/pptx/editor/render/collaboration-live-patch-target.cjs +2 -2
  62. package/dist/pptx/editor/render/collaboration-live-patch-target.mjs +1 -1
  63. package/dist/pptx/editor/render/find-replace.cjs +18 -18
  64. package/dist/pptx/editor/render/find-replace.d.ts +2 -2
  65. package/dist/pptx/editor/render/find-replace.mjs +2 -2
  66. package/dist/pptx/editor/render/remap-text.cjs +2 -2
  67. package/dist/pptx/editor/render/remap-text.d.ts.map +1 -1
  68. package/dist/pptx/editor/render/remap-text.mjs +1 -1
  69. package/dist/pptx/editor/render/slide-operations.cjs +8 -8
  70. package/dist/pptx/editor/render/slide-operations.mjs +2 -2
  71. package/dist/pptx/index.cjs +762 -182
  72. package/dist/pptx/index.d.ts +5 -5
  73. package/dist/pptx/index.mjs +5 -5
  74. package/dist/pptx/smartart-layouts/index.d.ts +1 -1
  75. package/dist/teams/index.cjs +486 -114
  76. package/dist/teams/index.mjs +486 -114
  77. package/dist/visio/date-cache.d.ts +3 -0
  78. package/dist/visio/date-cache.d.ts.map +1 -0
  79. package/dist/visio/edit-text-field.d.ts.map +1 -1
  80. package/dist/visio/index.cjs +131 -22
  81. package/dist/visio/index.mjs +131 -22
  82. package/dist/visio/shape-metadata.d.ts.map +1 -1
  83. package/dist/visio/text-field-display.d.ts.map +1 -1
  84. package/dist/visio/text-field-fraction.d.ts +3 -0
  85. package/dist/visio/text-field-fraction.d.ts.map +1 -0
  86. package/dist/visio/text-field-numeric.d.ts +1 -1
  87. package/dist/visio/text-field-numeric.d.ts.map +1 -1
  88. package/dist/visio/text-field-system-date.d.ts +4 -0
  89. package/dist/visio/text-field-system-date.d.ts.map +1 -0
  90. package/dist/visio/text-fields.d.ts +1 -0
  91. package/dist/visio/text-fields.d.ts.map +1 -1
  92. package/dist/visio/ui/index.cjs +132 -22
  93. package/dist/visio/ui/index.mjs +132 -22
  94. package/dist/visio/ui/text-field-catalog.d.ts.map +1 -1
  95. package/dist/xlsx/edit/pivots.d.ts.map +1 -1
  96. package/dist/xlsx/index.cjs +614 -170
  97. package/dist/xlsx/index.mjs +614 -170
  98. package/dist/xlsx/load/index.cjs +575 -163
  99. package/dist/xlsx/load/index.mjs +575 -163
  100. package/dist/xlsx/model-pivots.d.ts +23 -2
  101. package/dist/xlsx/model-pivots.d.ts.map +1 -1
  102. package/dist/xlsx/pivot/admission.d.ts.map +1 -1
  103. package/dist/xlsx/pivot/aggregate.d.ts +3 -1
  104. package/dist/xlsx/pivot/aggregate.d.ts.map +1 -1
  105. package/dist/xlsx/pivot/data.d.ts +1 -1
  106. package/dist/xlsx/pivot/data.d.ts.map +1 -1
  107. package/dist/xlsx/pivot/hierarchy-first.d.ts +21 -0
  108. package/dist/xlsx/pivot/hierarchy-first.d.ts.map +1 -0
  109. package/dist/xlsx/pivot/hierarchy.d.ts +2 -4
  110. package/dist/xlsx/pivot/hierarchy.d.ts.map +1 -1
  111. package/dist/xlsx/pivot/measures.d.ts +13 -0
  112. package/dist/xlsx/pivot/measures.d.ts.map +1 -0
  113. package/dist/xlsx/pivot/read.d.ts.map +1 -1
  114. package/dist/xlsx/pivot/table-xml.d.ts.map +1 -1
  115. package/dist/xlsx/pivot/values-axis.d.ts +9 -0
  116. package/dist/xlsx/pivot/values-axis.d.ts.map +1 -0
  117. package/dist/xlsx/ui/commands/i18n/pivots.d.ts.map +1 -1
  118. package/dist/xlsx/ui/index.cjs +547 -127
  119. package/dist/xlsx/ui/index.mjs +547 -127
  120. package/package.json +1 -1
  121. package/dist/PptxHandler-AT7FVG5Q.mjs +0 -2
  122. package/dist/PptxHandler-VFSCECPL.cjs +0 -11
  123. package/dist/pptx/chunks/index-B4cnSPNz.d.ts.map +0 -1
  124. package/dist/pptx/chunks/index-BZh-IMkN.d.ts.map +0 -1
  125. package/dist/pptx/chunks/smart-art-Q2kZQtHh.d.ts.map +0 -1
  126. package/dist/pptx/chunks/text-operations-BLodkuXE.d.ts.map +0 -1
@@ -20008,6 +20008,25 @@ function validatePivotFields(pivot) {
20008
20008
  ...pivot.columnField ? [pivot.columnField] : [],
20009
20009
  pivot.valueField
20010
20010
  ];
20011
+ const extras = pivot.additionalValues ?? [];
20012
+ if (pivot.valuesAxis !== void 0 && !["columns", "rows"].includes(pivot.valuesAxis))
20013
+ throw new Error("Choose a valid Values axis.");
20014
+ if (pivot.valuesPosition !== void 0 && !["last", "between", "first"].includes(pivot.valuesPosition))
20015
+ throw new Error("Choose a valid Values position.");
20016
+ if ((pivot.valuesPosition === "between" || pivot.valuesPosition === "first") && (pivot.valuesAxis !== "rows" || !pivot.secondRowField))
20017
+ throw new Error("Values before or between fields require two row fields and Values on rows.");
20018
+ if (pivot.valuesAxis === "rows" && (!Array.isArray(extras) || !extras.length))
20019
+ throw new Error("Values on rows require multiple measures.");
20020
+ if (extras.length > 0 && pivot.sourceXml && parseXml(pivot.sourceXml).documentElement.getAttribute("dataCaption") !== "Values")
20021
+ throw new Error("This PivotTable uses unsupported Values header captions.");
20022
+ if (!Array.isArray(extras) || extras.length > 15 || extras.some(
20023
+ (measure) => !measure || !pivot.fields.includes(measure.field) || !PIVOT_AGGREGATES.includes(measure.aggregate) || typeof measure.caption !== "string" || !measure.caption.trim() || measure.caption.length > 255 || pivot.fields.some((field) => field.toLowerCase() === measure.caption.toLowerCase())
20024
+ ) || new Set(
20025
+ [pivot.valueCaption, ...extras.map((measure) => measure.caption)].map(
20026
+ (caption) => caption?.toLowerCase()
20027
+ )
20028
+ ).size !== extras.length + 1)
20029
+ throw new Error("Choose PivotTable value fields with valid aggregates and unique captions.");
20011
20030
  if (pivot.layout !== void 0 && !["tabular", "compact", "outline"].includes(pivot.layout) || pivot.subtotalPosition !== void 0 && !["top", "bottom"].includes(pivot.subtotalPosition) || !PIVOT_AGGREGATES.includes(pivot.aggregate) || used.some((field) => !pivot.fields.includes(field)) || new Set([pivot.rowField, pivot.secondRowField, pivot.columnField].filter(Boolean)).size !== [pivot.rowField, pivot.secondRowField, pivot.columnField].filter(Boolean).length || pivot.subtotals !== void 0 && typeof pivot.subtotals !== "boolean" || pivot.repeatLabels !== void 0 && typeof pivot.repeatLabels !== "boolean")
20012
20031
  throw new Error("Choose valid PivotTable fields; row and column fields must differ.");
20013
20032
  }
@@ -20015,6 +20034,7 @@ var PIVOT_AGGREGATES;
20015
20034
  var init_data = __esm({
20016
20035
  "xlsx/pivot/data.ts"() {
20017
20036
  init_model();
20037
+ init_xml2();
20018
20038
  PIVOT_AGGREGATES = ["sum", "count", "average", "min", "max"];
20019
20039
  }
20020
20040
  });
@@ -20072,20 +20092,186 @@ var init_cache_xml = __esm({
20072
20092
  }
20073
20093
  });
20074
20094
 
20095
+ // xlsx/pivot/measures.ts
20096
+ function aggregate2(records, field, type) {
20097
+ if (!records.length) return null;
20098
+ const values2 = records.map((record) => record[field] ?? null);
20099
+ if (type === "count") return values2.filter((value) => value !== null && value !== "").length;
20100
+ const error = values2.find(isCellError);
20101
+ if (error) return error;
20102
+ const numbers3 = values2.filter((value) => typeof value === "number");
20103
+ if (!numbers3.length) return type === "average" ? { error: "#DIV/0!" } : 0;
20104
+ if (type === "min") return numbers3.reduce((a2, b) => Math.min(a2, b));
20105
+ if (type === "max") return numbers3.reduce((a2, b) => Math.max(a2, b));
20106
+ const sum2 = numbers3.reduce((total2, value) => total2 + value, 0);
20107
+ return type === "average" ? sum2 / numbers3.length : sum2;
20108
+ }
20109
+ function pivotHeaderDimensions(pivot, columnItems, rowLabels) {
20110
+ const measures = 1 + (pivot.additionalValues?.length ?? 0);
20111
+ if (pivot.valuesAxis === "rows")
20112
+ return {
20113
+ rows: pivot.columnField ? 2 : 1,
20114
+ width: rowLabels + (pivot.columnField ? columnItems + 1 : 1)
20115
+ };
20116
+ return {
20117
+ rows: pivot.columnField ? measures > 1 ? 3 : 2 : 1,
20118
+ width: rowLabels + (pivot.columnField ? measures === 1 ? Math.max(1, columnItems) + 1 : (columnItems + 1) * measures : measures)
20119
+ };
20120
+ }
20121
+ function pivotHeaders(pivot, columns, labels, label3) {
20122
+ const measures = pivotMeasures(pivot);
20123
+ if (pivot.valuesAxis === "rows") {
20124
+ const rowLabels = pivot.layout === "compact" ? ["Row Labels"] : pivot.valuesPosition === "first" ? ["Values", ...labels] : pivot.valuesPosition === "between" ? [labels[0], "Values", labels[1]] : [...labels, "Values"];
20125
+ return pivot.columnField ? [
20126
+ [
20127
+ ...rowLabels.map(() => null),
20128
+ pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
20129
+ ...columns.map(() => null)
20130
+ ],
20131
+ [...rowLabels, ...columns.map(label3), "Grand Total"]
20132
+ ] : [[...rowLabels, null]];
20133
+ }
20134
+ if (!pivot.columnField) return [[...labels, ...measures.map((measure) => measure.caption)]];
20135
+ if (measures.length === 1)
20136
+ return [
20137
+ [
20138
+ pivot.valueCaption,
20139
+ ...labels.slice(1).map(() => null),
20140
+ pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
20141
+ ...columns.slice(1).map(() => null),
20142
+ null
20143
+ ],
20144
+ [...labels, ...columns.map(label3), "Grand Total"]
20145
+ ];
20146
+ const { width } = pivotHeaderDimensions(pivot, columns.length, labels.length);
20147
+ const first2 = Array(width).fill(null);
20148
+ first2[labels.length] = pivot.layout === "compact" ? "Column Labels" : pivot.columnField;
20149
+ if (pivot.layout !== "compact") first2[labels.length + 1] = "Values";
20150
+ return [
20151
+ first2,
20152
+ [
20153
+ ...labels.map(() => null),
20154
+ ...columns.flatMap((column) => [label3(column), ...measures.slice(1).map(() => null)]),
20155
+ ...measures.map((measure) => `Total ${measure.caption}`)
20156
+ ],
20157
+ [
20158
+ ...labels,
20159
+ ...columns.flatMap(() => measures.map((measure) => measure.caption)),
20160
+ ...measures.map(() => null)
20161
+ ]
20162
+ ];
20163
+ }
20164
+ var pivotMeasures, pivotMeasureNumber, pivotNumbers;
20165
+ var init_measures = __esm({
20166
+ "xlsx/pivot/measures.ts"() {
20167
+ init_model();
20168
+ pivotMeasures = (pivot) => [
20169
+ { field: pivot.valueField, aggregate: pivot.aggregate, caption: pivot.valueCaption },
20170
+ ...pivot.additionalValues ?? []
20171
+ ];
20172
+ pivotMeasureNumber = (pivot, records, measure) => aggregate2(records, pivot.fields.indexOf(measure.field), measure.aggregate);
20173
+ pivotNumbers = (pivot, records) => pivotMeasures(pivot).map((measure) => pivotMeasureNumber(pivot, records, measure));
20174
+ }
20175
+ });
20176
+
20177
+ // xlsx/pivot/hierarchy-first.ts
20178
+ function appendFirstPivotValues(pivot, context) {
20179
+ const {
20180
+ rowItems,
20181
+ secondRowItems,
20182
+ columnItems,
20183
+ children: children2,
20184
+ innerIndices,
20185
+ groups,
20186
+ details,
20187
+ buckets,
20188
+ width,
20189
+ rowLabels,
20190
+ top,
20191
+ bottom,
20192
+ append
20193
+ } = context;
20194
+ const compact = pivot.layout === "compact";
20195
+ const tabular = !pivot.layout || pivot.layout === "tabular";
20196
+ const blank = () => Array(width - rowLabels).fill(null);
20197
+ pivotMeasures(pivot).forEach((measure, m) => {
20198
+ const numbers3 = (keys, records) => [
20199
+ ...columnItems.map(
20200
+ (column) => pivotMeasureNumber(
20201
+ pivot,
20202
+ buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
20203
+ measure
20204
+ )
20205
+ ),
20206
+ pivotMeasureNumber(pivot, records, measure)
20207
+ ];
20208
+ if (!tabular)
20209
+ append([measure.caption, ...Array(rowLabels - 1).fill(null)], blank(), {
20210
+ indices: [m],
20211
+ measure: m
20212
+ });
20213
+ let first2 = true;
20214
+ rowItems.forEach((outer, outerIndex) => {
20215
+ const key = pivotValueKey(outer);
20216
+ const group = groups.get(key) ?? [];
20217
+ if (!tabular)
20218
+ append(
20219
+ compact ? [pivotItemLabel(outer)] : [null, pivotItemLabel(outer), null],
20220
+ top ? numbers3([key], group) : blank(),
20221
+ { indices: [m, outerIndex], measure: m },
20222
+ compact ? 1 : 0
20223
+ );
20224
+ const innerKeys = [...children2.get(key)].sort(
20225
+ (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
20226
+ );
20227
+ innerKeys.forEach((innerKey, child3) => {
20228
+ const innerIndex = innerIndices.get(innerKey);
20229
+ append(
20230
+ compact ? [pivotItemLabel(secondRowItems[innerIndex])] : [
20231
+ tabular && first2 ? measure.caption : null,
20232
+ pivot.repeatLabels || tabular && child3 === 0 ? pivotItemLabel(outer) : null,
20233
+ pivotItemLabel(secondRowItems[innerIndex])
20234
+ ],
20235
+ numbers3([key, innerKey], details.get(JSON.stringify([key, innerKey]))),
20236
+ { indices: [m, outerIndex, innerIndex], measure: m },
20237
+ compact ? 2 : 0
20238
+ );
20239
+ first2 = false;
20240
+ });
20241
+ if (bottom)
20242
+ append(
20243
+ compact ? [`${String(pivotItemLabel(outer))} Total`] : [null, `${String(pivotItemLabel(outer))} Total`, null],
20244
+ numbers3([key], group),
20245
+ { indices: [m, outerIndex], measure: m, type: "default" },
20246
+ compact ? 1 : 0
20247
+ );
20248
+ });
20249
+ });
20250
+ }
20251
+ var init_hierarchy_first = __esm({
20252
+ "xlsx/pivot/hierarchy-first.ts"() {
20253
+ init_data();
20254
+ init_measures();
20255
+ }
20256
+ });
20257
+
20075
20258
  // xlsx/pivot/hierarchy.ts
20076
- function hierarchicalPivotGrid(pivot, aggregate3) {
20259
+ function hierarchicalPivotGrid(pivot) {
20077
20260
  const rowItems = pivotItems(pivot, pivot.rowField);
20078
20261
  const secondRowItems = pivotItems(pivot, pivot.secondRowField);
20079
20262
  const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
20080
20263
  const outerField = pivot.fields.indexOf(pivot.rowField);
20081
20264
  const innerField = pivot.fields.indexOf(pivot.secondRowField);
20082
20265
  const columnField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
20083
- const valueField = pivot.fields.indexOf(pivot.valueField);
20084
20266
  const layout2 = pivot.layout ?? "tabular";
20085
20267
  const compact = layout2 === "compact";
20086
- const top = layout2 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
20268
+ const rowsAxis = pivot.valuesAxis === "rows";
20269
+ const firstValues = rowsAxis && pivot.valuesPosition === "first";
20270
+ const between = rowsAxis && pivot.valuesPosition === "between";
20271
+ const measures = pivotMeasures(pivot);
20272
+ const top = (!rowsAxis || firstValues) && layout2 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
20087
20273
  const bottom = pivot.subtotals !== false && !top;
20088
- const rowLabelColumns = compact ? 1 : 2;
20274
+ const rowLabelColumns = compact ? 1 : rowsAxis ? 3 : 2;
20089
20275
  const groups = /* @__PURE__ */ new Map();
20090
20276
  const details = /* @__PURE__ */ new Map();
20091
20277
  const children2 = /* @__PURE__ */ new Map();
@@ -20109,20 +20295,12 @@ function hierarchicalPivotGrid(pivot, aggregate3) {
20109
20295
  collect(buckets, JSON.stringify([...key, column]), record);
20110
20296
  }
20111
20297
  }
20112
- const rows = details.size + rowItems.length * (Number(layout2 !== "tabular") + Number(bottom)) + 3;
20113
- if (rows * (columnItems.length + 3) > 1e6)
20114
- throw new Error("The PivotTable result is too large.");
20298
+ const dimensions = pivotHeaderDimensions(pivot, columnItems.length, rowLabelColumns);
20299
+ const rows = (details.size + rowItems.length * Number(bottom) + 1) * (rowsAxis ? measures.length : 1) + rowItems.length * Number(layout2 !== "tabular") * (firstValues ? measures.length : 1) + (firstValues ? measures.length : between ? rowItems.length * measures.length : details.size) * Number(rowsAxis && layout2 !== "tabular") + dimensions.rows;
20300
+ if (rows * dimensions.width > 1e6) throw new Error("The PivotTable result is too large.");
20115
20301
  const labels = compact ? ["Row Labels"] : [pivot.rowField, pivot.secondRowField];
20116
- const values2 = pivot.columnField ? [
20117
- [
20118
- pivot.valueCaption,
20119
- ...compact ? [] : [null],
20120
- compact ? "Column Labels" : pivot.columnField,
20121
- ...columnItems.slice(1).map(() => null),
20122
- null
20123
- ],
20124
- [...labels, ...columnItems.map(label2), "Grand Total"]
20125
- ] : [[...labels, pivot.valueCaption]];
20302
+ const values2 = pivotHeaders(pivot, columnItems, labels, label2);
20303
+ const firstDataRow = values2.length;
20126
20304
  const indents = values2.map(() => 0);
20127
20305
  const rowEntries = [];
20128
20306
  const append = (labels2, numbers4, entry3, indent = 0) => {
@@ -20130,98 +20308,193 @@ function hierarchicalPivotGrid(pivot, aggregate3) {
20130
20308
  rowEntries.push(entry3);
20131
20309
  indents.push(indent);
20132
20310
  };
20133
- const numbers3 = (keys, records) => [
20311
+ const bands = (keys, records) => [
20134
20312
  ...columnItems.map(
20135
- (column) => aggregate3(
20136
- buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
20137
- valueField,
20138
- pivot.aggregate
20139
- )
20313
+ (column) => pivotNumbers(pivot, buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [])
20140
20314
  ),
20141
- aggregate3(records, valueField, pivot.aggregate)
20315
+ pivotNumbers(pivot, records)
20142
20316
  ];
20143
- rowItems.forEach((outer, outerIndex) => {
20144
- const key = pivotValueKey(outer);
20145
- if (layout2 !== "tabular")
20146
- append(
20147
- [label2(outer), ...compact ? [] : [null]],
20148
- top ? numbers3([key], groups.get(key) ?? []) : Array(columnItems.length + 1).fill(null),
20149
- { indices: [outerIndex] }
20150
- );
20151
- let first2 = true;
20152
- [...children2.get(key)].sort((a2, b) => innerIndices.get(a2) - innerIndices.get(b)).forEach((innerKey) => {
20153
- const innerIndex = innerIndices.get(innerKey);
20154
- const inner = secondRowItems[innerIndex];
20155
- const keys = [key, innerKey];
20156
- const records = details.get(JSON.stringify(keys));
20157
- if (!records) return;
20158
- append(
20159
- compact ? [label2(inner)] : [
20160
- pivot.repeatLabels || layout2 === "tabular" && first2 ? label2(outer) : null,
20161
- label2(inner)
20317
+ const numbers3 = (keys, records) => bands(keys, records).flat();
20318
+ const appendMeasures = (labels2, keys, records, indices, type) => {
20319
+ const values3 = bands(keys, records);
20320
+ measures.forEach(
20321
+ (measure, m) => append(
20322
+ type ? [
20323
+ `${type === "grand" ? "Total" : String(labels2[0])} ${measure.caption}`,
20324
+ ...Array(rowLabelColumns - 1).fill(null)
20325
+ ] : compact ? [measure.caption] : [
20326
+ ...labels2.map(
20327
+ (label3) => layout2 === "tabular" && m === 0 || pivot.repeatLabels ? label3 : null
20328
+ ),
20329
+ measure.caption
20162
20330
  ],
20163
- numbers3(keys, records),
20164
- { indices: [outerIndex, innerIndex] },
20165
- compact ? 1 : 0
20166
- );
20167
- first2 = false;
20331
+ values3.map((band) => band[m] ?? null),
20332
+ { indices: type ? indices : [...indices, m], measure: m, ...type ? { type } : {} },
20333
+ compact && !type ? 2 : 0
20334
+ )
20335
+ );
20336
+ };
20337
+ if (firstValues)
20338
+ appendFirstPivotValues(pivot, {
20339
+ rowItems,
20340
+ secondRowItems,
20341
+ columnItems,
20342
+ children: children2,
20343
+ innerIndices,
20344
+ groups,
20345
+ details,
20346
+ buckets,
20347
+ width: dimensions.width,
20348
+ rowLabels: rowLabelColumns,
20349
+ top,
20350
+ bottom,
20351
+ append
20168
20352
  });
20169
- if (bottom) {
20170
- const caption = String(label2(outer));
20171
- append(
20172
- [`${caption} Total`, ...compact ? [] : [null]],
20173
- numbers3([key], groups.get(key) ?? []),
20174
- { indices: [outerIndex], type: "default" }
20353
+ else
20354
+ rowItems.forEach((outer, outerIndex) => {
20355
+ const key = pivotValueKey(outer);
20356
+ if (layout2 !== "tabular")
20357
+ append(
20358
+ [label2(outer), ...Array(rowLabelColumns - 1).fill(null)],
20359
+ top ? numbers3([key], groups.get(key) ?? []) : Array(dimensions.width - rowLabelColumns).fill(null),
20360
+ { indices: [outerIndex] }
20361
+ );
20362
+ let first2 = true;
20363
+ const innerKeys = [...children2.get(key)].sort(
20364
+ (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
20175
20365
  );
20176
- }
20177
- });
20178
- append(["Grand Total", ...compact ? [] : [null]], numbers3([], pivot.records), {
20179
- indices: [0],
20180
- type: "grand"
20181
- });
20366
+ if (between)
20367
+ measures.forEach((measure, m) => {
20368
+ if (layout2 !== "tabular")
20369
+ append(
20370
+ compact ? [measure.caption] : [pivot.repeatLabels ? label2(outer) : null, measure.caption, null],
20371
+ Array(dimensions.width - rowLabelColumns).fill(null),
20372
+ { indices: [outerIndex, m], measure: m },
20373
+ compact ? 1 : 0
20374
+ );
20375
+ innerKeys.forEach((innerKey, child3) => {
20376
+ const innerIndex = innerIndices.get(innerKey);
20377
+ const keys = [key, innerKey];
20378
+ const records = details.get(JSON.stringify(keys));
20379
+ append(
20380
+ compact ? [label2(secondRowItems[innerIndex])] : [
20381
+ pivot.repeatLabels || layout2 === "tabular" && m === 0 && child3 === 0 ? label2(outer) : null,
20382
+ layout2 === "tabular" && child3 === 0 ? measure.caption : null,
20383
+ label2(secondRowItems[innerIndex])
20384
+ ],
20385
+ [
20386
+ ...columnItems.map(
20387
+ (column) => pivotMeasureNumber(
20388
+ pivot,
20389
+ buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
20390
+ measure
20391
+ )
20392
+ ),
20393
+ pivotMeasureNumber(pivot, records, measure)
20394
+ ],
20395
+ { indices: [outerIndex, m, innerIndex], measure: m },
20396
+ compact ? 2 : 0
20397
+ );
20398
+ });
20399
+ });
20400
+ else
20401
+ innerKeys.forEach((innerKey) => {
20402
+ const innerIndex = innerIndices.get(innerKey);
20403
+ const inner = secondRowItems[innerIndex];
20404
+ const keys = [key, innerKey];
20405
+ const records = details.get(JSON.stringify(keys));
20406
+ if (!records) return;
20407
+ if (rowsAxis) {
20408
+ if (layout2 !== "tabular")
20409
+ append(
20410
+ compact ? [label2(inner)] : [pivot.repeatLabels ? label2(outer) : null, label2(inner), null],
20411
+ Array(dimensions.width - rowLabelColumns).fill(null),
20412
+ { indices: [outerIndex, innerIndex] },
20413
+ compact ? 1 : 0
20414
+ );
20415
+ appendMeasures(
20416
+ [pivot.repeatLabels || first2 ? label2(outer) : null, label2(inner)],
20417
+ keys,
20418
+ records,
20419
+ [outerIndex, innerIndex]
20420
+ );
20421
+ first2 = false;
20422
+ return;
20423
+ }
20424
+ append(
20425
+ compact ? [label2(inner)] : [
20426
+ pivot.repeatLabels || layout2 === "tabular" && first2 ? label2(outer) : null,
20427
+ label2(inner)
20428
+ ],
20429
+ numbers3(keys, records),
20430
+ { indices: [outerIndex, innerIndex] },
20431
+ compact ? 1 : 0
20432
+ );
20433
+ first2 = false;
20434
+ });
20435
+ if (bottom) {
20436
+ if (rowsAxis) {
20437
+ appendMeasures([label2(outer)], [key], groups.get(key) ?? [], [outerIndex], "default");
20438
+ return;
20439
+ }
20440
+ const caption = String(label2(outer));
20441
+ append(
20442
+ [`${caption} Total`, ...compact ? [] : [null]],
20443
+ numbers3([key], groups.get(key) ?? []),
20444
+ { indices: [outerIndex], type: "default" }
20445
+ );
20446
+ }
20447
+ });
20448
+ if (rowsAxis) appendMeasures([], [], pivot.records, [0], "grand");
20449
+ else
20450
+ append(["Grand Total", ...compact ? [] : [null]], numbers3([], pivot.records), {
20451
+ indices: [0],
20452
+ type: "grand"
20453
+ });
20182
20454
  return {
20183
20455
  values: values2,
20184
20456
  rowItems,
20185
20457
  secondRowItems,
20186
20458
  columnItems,
20187
20459
  rowEntries,
20188
- firstDataRow: pivot.columnField ? 2 : 1,
20460
+ firstDataRow,
20189
20461
  rowLabelColumns,
20190
- indents
20462
+ indents,
20463
+ ...rowsAxis ? { firstHeaderRow: 1 } : {}
20191
20464
  };
20192
20465
  }
20193
20466
  var label2;
20194
20467
  var init_hierarchy2 = __esm({
20195
20468
  "xlsx/pivot/hierarchy.ts"() {
20196
20469
  init_data();
20470
+ init_hierarchy_first();
20471
+ init_measures();
20197
20472
  label2 = pivotItemLabel;
20198
20473
  }
20199
20474
  });
20200
20475
 
20201
20476
  // xlsx/pivot/aggregate.ts
20202
- function aggregate2(records, field, type) {
20203
- if (!records.length) return null;
20204
- const values2 = records.map((record) => record[field] ?? null);
20205
- if (type === "count") return values2.filter((value) => value !== null && value !== "").length;
20206
- const error = values2.find(isCellError);
20207
- if (error) return error;
20208
- const numbers3 = values2.filter((value) => typeof value === "number");
20209
- if (!numbers3.length) return type === "average" ? { error: "#DIV/0!" } : 0;
20210
- if (type === "min") return numbers3.reduce((a2, b) => Math.min(a2, b));
20211
- if (type === "max") return numbers3.reduce((a2, b) => Math.max(a2, b));
20212
- const sum2 = numbers3.reduce((total2, value) => total2 + value, 0);
20213
- return type === "average" ? sum2 / numbers3.length : sum2;
20214
- }
20215
20477
  function pivotGrid(pivot) {
20216
20478
  validatePivotFields(pivot);
20217
- if (pivot.secondRowField) return hierarchicalPivotGrid(pivot, aggregate2);
20479
+ if (pivot.secondRowField) return hierarchicalPivotGrid(pivot);
20218
20480
  const rowItems = pivotItems(pivot, pivot.rowField);
20219
20481
  const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
20220
- if ((rowItems.length + 3) * (columnItems.length + 2) > 1e6)
20482
+ const rowsAxis = pivot.valuesAxis === "rows";
20483
+ const compact = pivot.layout === "compact";
20484
+ const headings = rowsAxis && pivot.layout !== void 0 && pivot.layout !== "tabular";
20485
+ const dimensions = pivotHeaderDimensions(pivot, columnItems.length, rowsAxis && !compact ? 2 : 1);
20486
+ const dataRows = (rowItems.length + 1) * (rowsAxis ? 1 + (pivot.additionalValues?.length ?? 0) : 1) + (headings ? rowItems.length : 0);
20487
+ if ((dataRows + dimensions.rows) * dimensions.width > 1e6)
20221
20488
  throw new Error("The PivotTable result is too large.");
20489
+ const label3 = pivotItemLabel;
20490
+ const values2 = pivotHeaders(
20491
+ pivot,
20492
+ columnItems,
20493
+ [pivot.layout === "compact" ? "Row Labels" : pivot.rowField],
20494
+ label3
20495
+ );
20222
20496
  const rowField = pivot.fields.indexOf(pivot.rowField);
20223
20497
  const colField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
20224
- const valueField = pivot.fields.indexOf(pivot.valueField);
20225
20498
  const groups = /* @__PURE__ */ new Map();
20226
20499
  const cells2 = /* @__PURE__ */ new Map();
20227
20500
  const columns = /* @__PURE__ */ new Map();
@@ -20239,48 +20512,117 @@ function pivotGrid(pivot) {
20239
20512
  collect(cells2, JSON.stringify([key, col]), record);
20240
20513
  }
20241
20514
  }
20242
- const label3 = pivotItemLabel;
20243
- const values2 = pivot.columnField ? [
20244
- [
20245
- pivot.valueCaption,
20246
- pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
20247
- ...columnItems.slice(1).map(() => null),
20248
- null
20249
- ],
20250
- [
20251
- pivot.layout === "compact" ? "Row Labels" : pivot.rowField,
20252
- ...columnItems.map(label3),
20253
- "Grand Total"
20254
- ]
20255
- ] : [[pivot.layout === "compact" ? "Row Labels" : pivot.rowField, pivot.valueCaption]];
20515
+ const firstDataRow = values2.length;
20516
+ if (rowsAxis) {
20517
+ const measures = pivotMeasures(pivot);
20518
+ const rowEntries = [];
20519
+ const indents = values2.map(() => 0);
20520
+ const append = (caption, bands, index2, grand = false) => {
20521
+ measures.forEach((measure, m) => {
20522
+ values2.push([
20523
+ ...compact ? [grand ? `Total ${measure.caption}` : measure.caption] : [
20524
+ grand ? `Total ${measure.caption}` : pivot.repeatLabels || !headings && m === 0 ? caption : null,
20525
+ grand ? null : measure.caption
20526
+ ],
20527
+ ...bands.map((band) => band[m] ?? null)
20528
+ ]);
20529
+ indents.push(compact && !grand ? 1 : 0);
20530
+ rowEntries.push({
20531
+ indices: grand ? [0] : [index2, m],
20532
+ measure: m,
20533
+ ...grand ? { type: "grand" } : {}
20534
+ });
20535
+ });
20536
+ };
20537
+ rowItems.forEach((item, index2) => {
20538
+ const key = pivotValueKey(item);
20539
+ if (headings) {
20540
+ values2.push([label3(item), ...Array(dimensions.width - 1).fill(null)]);
20541
+ rowEntries.push({ indices: [index2] });
20542
+ indents.push(0);
20543
+ }
20544
+ append(
20545
+ label3(item),
20546
+ [
20547
+ ...columnItems.map(
20548
+ (col) => pivotNumbers(pivot, cells2.get(JSON.stringify([key, pivotValueKey(col)])) ?? [])
20549
+ ),
20550
+ pivotNumbers(pivot, groups.get(key) ?? [])
20551
+ ],
20552
+ index2
20553
+ );
20554
+ });
20555
+ append(
20556
+ "Grand Total",
20557
+ [
20558
+ ...columnItems.map((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
20559
+ pivotNumbers(pivot, pivot.records)
20560
+ ],
20561
+ 0,
20562
+ true
20563
+ );
20564
+ return {
20565
+ values: values2,
20566
+ rowItems,
20567
+ columnItems,
20568
+ firstDataRow,
20569
+ rowLabelColumns: compact ? 1 : 2,
20570
+ indents,
20571
+ firstHeaderRow: 1,
20572
+ rowEntries
20573
+ };
20574
+ }
20256
20575
  for (const row2 of rowItems) {
20257
20576
  const records = groups.get(pivotValueKey(row2)) ?? [];
20258
20577
  values2.push([
20259
20578
  label3(row2),
20260
- ...columnItems.map(
20261
- (col) => aggregate2(
20262
- cells2.get(JSON.stringify([pivotValueKey(row2), pivotValueKey(col)])) ?? [],
20263
- valueField,
20264
- pivot.aggregate
20579
+ ...columnItems.flatMap(
20580
+ (col) => pivotNumbers(
20581
+ pivot,
20582
+ cells2.get(JSON.stringify([pivotValueKey(row2), pivotValueKey(col)])) ?? []
20265
20583
  )
20266
20584
  ),
20267
- aggregate2(records, valueField, pivot.aggregate)
20585
+ ...pivotNumbers(pivot, records)
20268
20586
  ]);
20269
20587
  }
20270
20588
  values2.push([
20271
20589
  "Grand Total",
20272
- ...columnItems.map(
20273
- (col) => aggregate2(columns.get(pivotValueKey(col)) ?? [], valueField, pivot.aggregate)
20274
- ),
20275
- aggregate2(pivot.records, valueField, pivot.aggregate)
20590
+ ...columnItems.flatMap((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
20591
+ ...pivotNumbers(pivot, pivot.records)
20276
20592
  ]);
20277
- return { values: values2, rowItems, columnItems, firstDataRow: pivot.columnField ? 2 : 1 };
20593
+ return { values: values2, rowItems, columnItems, firstDataRow };
20278
20594
  }
20279
20595
  var init_aggregate = __esm({
20280
20596
  "xlsx/pivot/aggregate.ts"() {
20281
- init_model();
20282
20597
  init_data();
20283
20598
  init_hierarchy2();
20599
+ init_measures();
20600
+ }
20601
+ });
20602
+
20603
+ // xlsx/pivot/values-axis.ts
20604
+ function pivotValueAxisItems(measures, columns) {
20605
+ const entries = [];
20606
+ if (columns === void 0) {
20607
+ for (let measure = 0; measure < measures; measure++)
20608
+ entries.push(
20609
+ `<i${attrs({ i: measure || void 0 })}><x${attrs({ v: measure || void 0 })}/></i>`
20610
+ );
20611
+ } else {
20612
+ for (let column = 0; column < columns; column++)
20613
+ for (let measure = 0; measure < measures; measure++) {
20614
+ entries.push(
20615
+ `<i${attrs({ r: measure ? 1 : void 0, i: measure || void 0 })}>${measure ? "" : `<x${attrs({ v: column || void 0 })}/>`}<x${attrs({ v: measure || void 0 })}/></i>`
20616
+ );
20617
+ }
20618
+ for (let measure = 0; measure < measures; measure++)
20619
+ entries.push(`<i${attrs({ t: "grand", i: measure || void 0 })}><x/></i>`);
20620
+ }
20621
+ return `<colItems count="${entries.length}">${entries.join("")}</colItems>`;
20622
+ }
20623
+ var init_values_axis = __esm({
20624
+ "xlsx/pivot/values-axis.ts"() {
20625
+ init_xml_out();
20284
20626
  }
20285
20627
  });
20286
20628
 
@@ -20290,7 +20632,9 @@ function pivotTableXml(pivot, cacheId, cache2) {
20290
20632
  const row2 = pivot.fields.indexOf(pivot.rowField);
20291
20633
  const second = pivot.secondRowField ? pivot.fields.indexOf(pivot.secondRowField) : -1;
20292
20634
  const col = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
20293
- const value = pivot.fields.indexOf(pivot.valueField);
20635
+ const measures = pivotMeasures(pivot);
20636
+ const multiple = measures.length > 1;
20637
+ const rowsAxis = pivot.valuesAxis === "rows";
20294
20638
  const compact = pivot.layout === "compact";
20295
20639
  const outline = pivot.layout === "compact" || pivot.layout === "outline";
20296
20640
  const top = (pivot.subtotalPosition ?? (outline ? "top" : "bottom")) === "top";
@@ -20298,36 +20642,61 @@ function pivotTableXml(pivot, cacheId, cache2) {
20298
20642
  const items2 = index2 === row2 ? grid.rowItems : index2 === second ? grid.secondRowItems : index2 === col ? grid.columnItems : void 0;
20299
20643
  const subtotal = !(index2 === row2 && pivot.subtotals === false);
20300
20644
  const repeated = pivot.repeatLabels && (index2 === row2 || index2 === second) ? '<extLst><ext uri="{2946ED86-A175-432a-8AC1-64E0C546D7DE}"><x14:pivotField xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" fillDownLabels="1"/></ext></extLst>' : "";
20301
- return `<pivotField${attrs({ axis: index2 === row2 || index2 === second ? "axisRow" : index2 === col ? "axisCol" : void 0, dataField: index2 === value ? true : void 0, compact, outline, showAll: false, subtotalTop: index2 === row2 ? top : void 0, defaultSubtotal: subtotal ? void 0 : false })}>${items2 ? `<items count="${items2.length + Number(subtotal)}">${items2.map((item) => `<item x="${cache2.indices[index2].get(pivotValueKey(item))}"/>`).join("")}${subtotal ? '<item t="default"/>' : ""}</items>` : ""}${repeated}</pivotField>`;
20645
+ return `<pivotField${attrs({ axis: index2 === row2 || index2 === second ? "axisRow" : index2 === col ? "axisCol" : void 0, dataField: measures.some((measure) => pivot.fields.indexOf(measure.field) === index2) ? true : void 0, compact, outline, showAll: false, subtotalTop: index2 === row2 ? top : void 0, defaultSubtotal: subtotal ? void 0 : false })}>${items2 ? `<items count="${items2.length + Number(subtotal)}">${items2.map((item) => `<item x="${cache2.indices[index2].get(pivotValueKey(item))}"/>`).join("")}${subtotal ? '<item t="default"/>' : ""}</items>` : ""}${repeated}</pivotField>`;
20302
20646
  }).join("");
20303
20647
  const items = (count2) => Array.from({ length: count2 }, (_v, i) => `<i><x v="${i}"/></i>`).join("") + '<i t="grand"><x/></i>';
20304
- const header = grid.firstDataRow - 1;
20305
- const rowIndices = [row2, ...second >= 0 ? [second] : []];
20648
+ const header = grid.firstHeaderRow ?? (multiple && col >= 0 ? 1 : grid.firstDataRow - 1);
20649
+ const rowIndices = rowsAxis && pivot.valuesPosition === "first" ? [-2, row2, second] : rowsAxis && pivot.valuesPosition === "between" ? [row2, -2, second] : [row2, ...second >= 0 ? [second] : [], ...rowsAxis ? [-2] : []];
20306
20650
  let previous = [];
20307
20651
  const rowItems = grid.rowEntries?.map((entry3) => {
20308
20652
  let prefix = 0;
20309
- if (!entry3.type)
20653
+ if (entry3.type === "default" && rowsAxis && pivot.valuesPosition === "first") prefix = 1;
20654
+ else if (!entry3.type)
20310
20655
  while (prefix < entry3.indices.length - 1 && entry3.indices[prefix] === previous[prefix])
20311
20656
  prefix++;
20312
- previous = entry3.type ? [] : entry3.indices;
20313
- return `<i${attrs({ t: entry3.type, r: prefix || void 0 })}>${entry3.indices.slice(prefix).map((index2) => `<x${attrs({ v: index2 || void 0 })}/>`).join("")}</i>`;
20657
+ previous = entry3.type && !(entry3.type === "default" && pivot.valuesPosition === "first") ? [] : entry3.indices;
20658
+ return `<i${attrs({ t: entry3.type, r: prefix || void 0, i: entry3.measure || void 0 })}>${entry3.indices.slice(prefix).map((index2) => `<x${attrs({ v: index2 || void 0 })}/>`).join("")}</i>`;
20314
20659
  }).join("") ?? items(grid.rowItems.length);
20315
20660
  let body = `<location${attrs({ ref: formatRange(pivot.location), firstHeaderRow: header, firstDataRow: grid.firstDataRow, firstDataCol: grid.rowLabelColumns ?? 1 })}/><pivotFields count="${pivot.fields.length}">${fields}</pivotFields><rowFields count="${rowIndices.length}">${rowIndices.map((index2) => `<field x="${index2}"/>`).join("")}</rowFields><rowItems count="${grid.rowEntries?.length ?? grid.rowItems.length + 1}">${rowItems}</rowItems>`;
20316
- if (col >= 0)
20661
+ if (multiple && !rowsAxis)
20662
+ body += `<colFields count="${col >= 0 ? 2 : 1}">${col >= 0 ? `<field x="${col}"/>` : ""}<field x="-2"/></colFields>${pivotValueAxisItems(measures.length, col >= 0 ? grid.columnItems.length : void 0)}`;
20663
+ else if (col >= 0)
20317
20664
  body += `<colFields count="1"><field x="${col}"/></colFields><colItems count="${grid.columnItems.length + 1}">${items(grid.columnItems.length)}</colItems>`;
20318
- else body += '<colItems count="1"><i><x/></i></colItems>';
20319
- body += `<dataFields count="1"><dataField${attrs({ name: encodeEscapes(pivot.valueCaption), fld: value, subtotal: pivot.aggregate, baseField: 0, baseItem: 0 })}/></dataFields>`;
20665
+ else
20666
+ body += rowsAxis ? '<colItems count="1"><i/></colItems>' : '<colItems count="1"><i><x/></i></colItems>';
20667
+ body += `<dataFields count="${measures.length}">${measures.map((measure) => `<dataField${attrs({ name: encodeEscapes(measure.caption), fld: pivot.fields.indexOf(measure.field), subtotal: measure.aggregate, baseField: 0, baseItem: 0 })}/>`).join("")}</dataFields>`;
20320
20668
  const doc = parseXml(
20321
20669
  pivot.sourceXml ?? `<pivotTableDefinition xmlns="${NS.x}" dataCaption="Values" updatedVersion="6" minRefreshableVersion="3" createdVersion="6"><pivotTableStyleInfo name="PivotStyleLight16" showRowHeaders="1" showColHeaders="1" showRowStripes="0" showColStripes="0" showLastColumn="1"/></pivotTableDefinition>`
20322
20670
  );
20323
20671
  const root = doc.documentElement;
20324
20672
  root.setAttribute("name", pivot.name);
20325
20673
  root.setAttribute("cacheId", String(cacheId));
20674
+ root.setAttribute("dataOnRows", rowsAxis ? "1" : "0");
20675
+ if (rowsAxis && (pivot.valuesPosition === "between" || pivot.valuesPosition === "first"))
20676
+ root.setAttribute("dataPosition", pivot.valuesPosition === "first" ? "0" : "1");
20677
+ else root.removeAttribute("dataPosition");
20326
20678
  root.setAttribute("compact", compact ? "1" : "0");
20327
20679
  root.setAttribute("compactData", compact ? "1" : "0");
20328
20680
  root.setAttribute("outline", outline ? "1" : "0");
20329
20681
  root.setAttribute("outlineData", outline ? "1" : "0");
20330
20682
  if (compact) root.setAttribute("indent", "0");
20683
+ if (multiple && !elements(first(root, "extLst", NS.x) ?? parseXml("<root/>").documentElement).some(
20684
+ (extension) => first(
20685
+ extension,
20686
+ "pivotTableDefinition",
20687
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
20688
+ )
20689
+ )) {
20690
+ let list = first(root, "extLst", NS.x);
20691
+ if (!list) {
20692
+ list = doc.createElementNS(NS.x, "extLst");
20693
+ root.appendChild(list);
20694
+ }
20695
+ const extension = parseXml(
20696
+ `<ext xmlns="${NS.x}" uri="{962EF5D1-5CA2-4c93-8EF4-DBF5C05439D2}"><x14:pivotTableDefinition xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" hideValuesRow="1"/></ext>`
20697
+ ).documentElement;
20698
+ list.appendChild(doc.importNode(extension, true));
20699
+ }
20331
20700
  root.setAttribute("rowGrandTotals", "1");
20332
20701
  root.setAttribute("colGrandTotals", "1");
20333
20702
  for (const extension of elements(
@@ -20338,6 +20707,7 @@ function pivotTableXml(pivot, cacheId, cache2) {
20338
20707
  "pivotTableDefinition",
20339
20708
  "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
20340
20709
  );
20710
+ if (multiple && definition) definition.setAttribute("hideValuesRow", "1");
20341
20711
  if (definition?.hasAttribute("fillDownLabelsDefault"))
20342
20712
  definition.setAttribute("fillDownLabelsDefault", pivot.repeatLabels ? "1" : "0");
20343
20713
  }
@@ -20363,6 +20733,8 @@ var init_table_xml = __esm({
20363
20733
  init_xml_out();
20364
20734
  init_aggregate();
20365
20735
  init_data();
20736
+ init_measures();
20737
+ init_values_axis();
20366
20738
  }
20367
20739
  });
20368
20740