...
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>
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.
...