Skip to content

[F] Summarise with Pivot Table #5

@iuioiua

Description

@iuioiua

🚀 Feature Proposal

The "Summarise with Pivot Table" functionality for a table.

Motivation

Pivot tables are a great way of summarising data for tables.

Example

Inspired by exceljs/exceljs#2551. Notice the sourceTable property for Worksheet.addPivotTable().

import { Workbook } from "@cj-tech-master/excelts";

const workbook = new Workbook();
const worksheet = workbook.addWorksheet();

const table = worksheet.addTable({
  name: "table",
  ref: "A1",
  columns: [
    { name: "A" },
    { name: "B" },
    { name: "C" },
    { name: "D" },
    { name: "E" },
  ],
  rows: [
    ["a1", "b1", "c1", 4, 5],
    ["a1", "b2", "c1", 4, 5],
    ["a2", "b1", "c2", 14, 24],
    ["a2", "b2", "c2", 24, 35],
    ["a3", "b1", "c3", 34, 45],
    ["a3", "b2", "c3", 44, 45],
  ],
});

const worksheet2 = workbook.addWorksheet("Sheet2");
worksheet2.addPivotTable({
  sourceTable: table,
  rows: ["A", "B"],
  columns: ["C"],
  values: ["E"], // Exactly 1 field
  metric: "sum", // Metric: 'sum' only
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions