
資料透視表是合併 Microsoft Excel 中包含的大量資料的工具。它們讓使用者從收集的數據中更快地得出結論。資料透視表由列、行、頁和資料欄位組成,它們有助於擴展、隔離、匯總和分組特定資料。此外,資料透視表可讓您取得大量資料並以僅需查看少量資料欄位的方式進行處理。資料透視表的其他一些好處包括
- 數據透視表使數據分析更容易
- 數據透視表可以建立即時數據
- 數據透視表易於使用
- 數據透視表輕鬆匯總數據
- 資料透視表有助於尋找資料模式
- 數據透視表可以更快地建立準確的報告
- 資料透視表可以幫助更快做出決策
將資料透視表新增至 Excel 文件
Aspose.Cells Cloud API 提供了一組類,可讓您將資料透視表新增至 Excel 工作表。 PutWorksheetPivotTable 方法可讓您在 Excel 工作表中新增新的資料透視表。為了添加表,我們需要提供以下參數
- name(字串) - 我們需要新增資料透視表的 Excel 檔案的名稱。
- sheetName(string) - 您想要新增資料透視表的工作表名稱。
- sourceData(字串) - 資料透視表的資料來源。
- destCellName(字串) - 資料透視表目標範圍左上角的儲存格。
- tableName(字串) - 新資料透視表的名稱。
- useSameSource(布林值) - 表示當另一個現有的資料透視表已使用此資料來源時是否使用相同的資料來源。
cURL 指令
curl -X PUT "https://api.aspose.cloud/v3.0/cells/Family%20Budget1.xlsx/worksheets/Sheet1/pivottables?sourceData='Current%20Month'!%24B%2427%3A%24E%2446&destCellName=B14&tableName=Pivot1&useSameSource=true" -H "accept: application/json" -H "authorization: Bearer <JWT Token>"
請求 URL
https://api.aspose.cloud/v3.0/cells/Family%20Budget1.xlsx/worksheets/Sheet1/pivottables?sourceData='Current%20Month'!%24B%2427%3A%24E%2446&destCellName=B14&tableName=Pivot1&useSameSource=true
C#.NET
string MyAppKey = "xxxxxxxx"; // Get AppKey from https://dashboard.aspose.cloud/
string MyAppSid = "xxxxxxxxx"; // Get AppSID from https://dashboard.aspose.cloud/
try
{
Aspose.Cells.Cloud.SDK.Api.CellsApi cellsApi = new Aspose.Cells.Cloud.SDK.Api.CellsApi(MyAppSid, MyAppKey);
String fileName = "Family Budget1.xlsx";
string sheetName = "Sheet1";
Aspose.Cells.Cloud.SDK.Model.CreatePivotTableRequest createPivotTableRequest =
new Aspose.Cells.Cloud.SDK.Model.CreatePivotTableRequest();
createPivotTableRequest.Name = "NewPivot";
createPivotTableRequest.SourceData = "'Current Month'!$B$21:$C$24";
createPivotTableRequest.DestCellName = "G22";
createPivotTableRequest.UseSameSource = true;
createPivotTableRequest.PivotFieldColumns = new System.Collections.Generic.List<int?> { 1 };
createPivotTableRequest.PivotFieldRows = new System.Collections.Generic.List<int?> { 1 };
createPivotTableRequest.PivotFieldData = new System.Collections.Generic.List<int?> { 1 };
Aspose.Cells.Cloud.SDK.Model.PivotTableResponse pivotTableResponse =
cellsApi.CellsPivotTablesPutWorksheetPivotTable(fileName, sheetName, createPivotTableRequest);
if (pivotTableResponse != null && pivotTableResponse.Status.Equals("OK"))
{
Console.WriteLine("Add a Pivot Table in a Worksheet, Done!");
Console.ReadKey();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}