Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pivot Table example

k3davis edited this pageMar 2, 2021 ·5 revisions

NOTE: Pivot table support is still very experimental.


In this example, we'll create a pivot table of monthly pastry sales. First, we'll need our Pastry class:

publicclassPastry{publicPastry(stringname,intamount,stringmonth){Month=month;Name=name;NumberOfOrders=amount;}publicstringName{get;set;}publicintNumberOfOrders{get;set;}publicstringMonth{get;set;}}

Next, we'll mock up some data:

varpastries=newList<Pastry>{newPastry("Croissant",150,"Apr"),newPastry("Croissant",250,"May"),newPastry("Croissant",134,"June"),newPastry("Doughnut",250,"Apr"),newPastry("Doughnut",225,"May"),newPastry("Doughnut",210,"June"),newPastry("Bearclaw",134,"Apr"),newPastry("Bearclaw",184,"May"),newPastry("Bearclaw",124,"June"),newPastry("Danish",394,"Apr"),newPastry("Danish",190,"May"),newPastry("Danish",221,"June"),newPastry("Scone",135,"Apr"),newPastry("Scone",122,"May"),newPastry("Scone",243,"June")};

And then we'll create a worksheet with this data in a table:

varworkbook=newXLWorkbook();varsheet=workbook.Worksheets.Add("PastrySalesData");// Insert our list of pastry data into the "PastrySalesData" sheet at cell 1,1vartable=sheet.Cell(1,1).InsertTable(pastries,"PastrySalesData",true);

Finally, we'll use that table as the source for our pivot table:

// Add a new sheet for our pivot tablevarptSheet=workbook.Worksheets.Add("PivotTable");// Create the pivot table, using the data from the "PastrySalesData" tablevarpt=ptSheet.PivotTables.Add("PivotTable",ptSheet.Cell(1,1),table.AsRange());// The rows in our pivot table will be the names of the pastriespt.RowLabels.Add("Name");// The columns will be the monthspt.ColumnLabels.Add("Month");// The values in our table will come from the "NumberOfOrders" field// The default calculation setting is a total of each row/columnpt.Values.Add("NumberOfOrders");

This will create a pivot table with a row for each pastry, a column for each month, and sales numbers in the cells. Each column and row will be totaled.

FAQ

Examples

Real world scenarios

Time Savers

Performance and Memory

Misc

Inserting Data/Tables

Styles

Ranges

Rows

Columns

Page Setup (Print Options)

AutoFilters

Comments

Dev docs

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp