Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This example takes an existing workbook that contains some data and creates a PivotTable. The workbook used in this example is available for download: Download ExampleBasicExample.xlsx.

Before writing any PivotTable code, make sure to open the workbook with ExcelApplication and get references to the data worksheet and a worksheet for the PivotTable. See Adding OfficeWriter to your .NET Application.

Code Block
ExcelApplication xla = new ExcelApplication();

//Example.xlsx has a worksheet 'Data' with 9 columns and 244 rows of data
Workbook wb = xla.Open("\\ExampleBasicExample.xlsx");

Worksheet data_ws = wb.Worksheets["Data"];
Worksheet pivot_ws = wb.Worksheets.CreateWorksheet("Pivot");

...

Here is a snapshot of the data for this tutorial, which can also be found in ExampleBasicExample.xlsx:

<IMAGE>

Image Added

There are 9 columns and 244 rows in the data set, including row with the header values.

In this case, the data source for the PivotTable will be a dynamically defined Area on the data worksheet. Note that the row of column names is included in the area.

...