| |
 |
Adding Pivot Table with Muiltiple Data Source - Aspose.Cells
|
 |
This online demo
exhibits how to set multiple datasource of a Pivot Table in a worksheet
using
Aspose.Cells
for .NET.
PivotTables can be added to the spreadsheets
using Aspose.Cells. Aspose.Cells provides some special set of classes that are used
to create and set the PivotTables. These classes are used to create and set PivotTable
Objects, which act as the building blocks of a PivotTable.
Click Process
to see how demo can set the multiple datasource of a pivot table.
You can either open the resulting excel file into MS Excel
or save directly to your disk.
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<%@ Page Language="C#" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true"
CodeBehind="pivot-table-with-multiple-datasource.aspx.cs" Inherits="Aspose.Cells.Demos.Pivot_Table_MultiSource"
Title="Adding Pivot Table with Muiltiple Data Source - Aspose.Cells Demos" %>
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="Server">
<p class="componentDescriptionTxt">
<span style="font-size: 10pt"></span> </p>
<p class="componentDescriptionTxt">
<span style="font-size: 10pt; font-family: Arial"></span>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
<tr>
<td valign="top" width="19">
<img alt="" height="41" src="/Common/images/heading_lft.jpg" width="19" /></td>
<td class="demos-heading-bg" width="100%">
<h2 class="demos-heading-bg">
<font face="Arial" size="4">Adding Pivot Table with Muiltiple Data Source - Aspose.Cells</font></h2>
</td>
<td valign="top" width="19">
<img alt="" height="41" src="/Common/images/heading_rt.jpg" width="19" /></td>
</tr>
</table>
</p>
<font face="Arial" size="2">
<p align="left">
<font color="black" face="Arial" style="background-color: whitesmoke"><span style="color: black;
background-color: white; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US;
mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><font size="2">This online demo
exhibits how to set multiple datasource of a Pivot Table in a worksheet</font></span></font>
<font size="2"><span style="font-family: Arial">using</span> <font face="Arial"><a
href="http://www.aspose.com/categories/file-format-components/aspose.cells-for-.net-and-java/default.aspx">
<span style="color: #0000ff; text-decoration: underline">Aspose.Cells</span></a>
for .NET</font></font><span style="font-family: Arial"><font size="2">.</font></span></p>
<p align="left">
<span style="font-family: Arial"><font size="2">PivotTables can be added to the spreadsheets
using Aspose.Cells. Aspose.Cells provides some special set of classes that are used
to create and set the PivotTables. These classes are used to create and set PivotTable
Objects, which act as the building blocks of a PivotTable.</font></span></p>
<p align="left">
</p>
<span style="font-family: Arial"><font size="2"></font></span>
Click <b>Process </b>
to see how demo can set the multiple datasource of a pivot table. </font>
<span style="font-size: 10pt; font-family: Arial"> You can either open the resulting excel file into MS Excel
or save directly to your disk. </span><p align="left">
<span style="font-size: 10pt; font-family: Arial"></span>
<asp:Button ID="btnExecute" runat="server" Text="Process" OnClick="btnExecute_Click" /> </p>
</asp:Content>
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Aspose.Cells;
using System.Drawing;
using Aspose.Cells.Pivot;
namespace Aspose.Cells.Demos
{
public partial class Pivot_Table_MultiSource : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlFileVersion;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnExecute_Click(object sender, EventArgs e)
{
CreateStaticReport();
}
public void CreateStaticReport()
{
//Open template
string path = System.Web.HttpContext.Current.Server.MapPath("~");
path = path.Substring(0, path.LastIndexOf("\\"));
path += @"\designer\Workbooks\PivotSource.xls";
//Instantiating an Workbook object
Workbook workbook = new Workbook(path);
Worksheet sheet = workbook.Worksheets[0];
PivotTableCollection pivotTables = sheet.PivotTables;
String[] sourceData = new String[] { "=Sheet1!A1:C8", "=Sheet2!A1:C8" };
PivotPageFields pageField = new PivotPageFields();
String[] pageItems = new String[2];
pageItems[0] = "Item1";
pageItems[1] = "Item2";
pageField.AddPageField(pageItems);
pageItems = new String[2];
pageItems[0] = "Item3";
pageItems[1] = "Item4";
pageField.AddPageField(pageItems);
int[] TBPG = new int[2];
TBPG[0] = 0;
TBPG[1] = 1;
//Sets which item label in each page field to use to identify the data range.
pageField.AddIdentify(0, TBPG);
TBPG = new int[2];
TBPG[0] = 1;
TBPG[1] = -1;
pageField.AddIdentify(1, TBPG);
int index = pivotTables.Add(sourceData, false, pageField, "E3", "PivotTable1");
if (ddlFileVersion.SelectedItem.Value == "XLS")
{
////Save file and send to client browser using selected format
workbook.Save(HttpContext.Current.Response, "PivotTableMultipleSource.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
}
else
{
workbook.Save(HttpContext.Current.Response, "PivotTableMultipleSource.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
}
//end response to avoid unneeded html
HttpContext.Current.Response.End();
}
}
}
|
|
|
|