Add a pivot table in an Excel worksheet This REST API indicates to add
a pivot table into worksheet.
RSET API
Copy
PUT http://api.aspose.cloud/v3.0/cells/{ name} /worksheets/{ sheetName} /pivottables
The request parameters are:
Parameter Name
Type
Path/Query String/HTTPBody
Description
name
string
path
Document name.
sheetName
string
path
The worksheet name.
request
body
CreatePivotTableRequest dto in request body.
folder
string
query
Document’s folder.
storageName
string
query
storage name.
sourceData
string
query
The data for the new PivotTable cache.
destCellName
string
query
The cell in the upper-left corner of the PivotTable report’s destination range.
tableName
string
query
The name of the new PivotTable report.
useSameSource
boolean
query
Indicates whether using same data source when another existing pivot table has used this data source. If the property is true, it will save memory.
The OpenAPI Specification defines a publicly accessible programming interface and lets you carry out REST interactions directly from a web browser.
You can use cURL command-line tool to access Aspose.Cells web services easily. The following example shows how to make calls to Cloud API with cURL.
Cloud SDK Family
Using an SDK is the best way to speed up the development. An SDK takes care of low-level details and lets you focus on your project tasks. Please check out the GitHub repository for a complete list of Aspose.Cells Cloud SDKs.
The following code examples demonstrate how to make calls to Aspose.Cells web services using various SDKs:
C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells-cloud/aspose-cells-cloud-dotnet/
namespace Aspose.Cells.Cloud.SDK.Example
{
using Aspose.Cells.Cloud.SDK.Api;
using Aspose.Cells.Cloud.SDK.Model;
using Aspose.Cells.Cloud.SDK.Request;
using System;
using System.Collections.Generic;
public partial class CellsApiExample
{
public void PutWorksheetPivotTableExample()
{
CellsApi cellsApi = new CellsApi(Environment.GetEnvironmentVariable("CellsCloudTestClientId"), Environment.GetEnvironmentVariable("CellsCloudTestClientSecret"));
PutWorksheetPivotTableRequest request = new PutWorksheetPivotTableRequest
{
name = "Book1.xlsx",
sheetName = "Sheet4",
destCellName = "C1",
sourceData = "Sheet1!C6:E13",
tableName = "TestPivot",
useSameSource = true,
folder = "TestData/In"
};
cellsApi.PutWorksheetPivotTable(request);
}
}
}
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aspose.cloud.cells.api;
import com.aspose.cloud.cells.client.*;
import com.aspose.cloud.cells.model.*;
import com.aspose.cloud.cells.request.*;
import java.io.IOException;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.util.HashMap;
public class Example {
private CellsApi api;
public Example(){
try {
api = new CellsApi(
System.getenv("CellsCloudClientId"),
System.getenv("CellsCloudClientSecret"),
"v3.0",
System.getenv("CellsCloudApiBaseUrl")
);
} catch (ApiException e) {
e.printStackTrace();
}
}
public void Run(){
try{
String remoteFolder = "TestData/In";
String localName = "Book1.xlsx";
String remoteName = "Book1.xlsx";
UploadFileRequest uploadFileRequest = new UploadFileRequest();
uploadFileRequest.setPath( remoteFolder + "/" + remoteName );
uploadFileRequest.setStorageName( "");
HashMap<String,File> files = new HashMap<String,File>();
files.put( localName , new File(localName ));
uploadFileRequest.setUploadFiles(files);
api.uploadFile(uploadFileRequest);
PivotTableFieldRequest pivottable = new PivotTableFieldRequest();
List<Integer> data = new ArrayList<Integer>();
data.add(1);
pivottable.setData(data);
PutPivotTableFieldRequest request = new PutPivotTableFieldRequest();
request.setName(remoteName);
request.setSheetName("Sheet4");
request.setPivotTableIndex(0);
request.setPivotFieldType("row");
request.setPivotTableFieldRequest(pivottable);
request.setNeedReCalculate(true);
request.setFolder(remoteFolder);
request.setStorageName("");
CellsCloudResponse response = api.putPivotTableField(request);
} catch (ApiException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}
PHP
Ruby
Python
Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { CellsApi, UploadFileRequest, CellsPivotTables_PutWorksheetPivotTableRequest } = require("asposecellscloud");
const clientId = process.env.CellsCloudClientId;
const clientSecret = process.env.CellsCloudClientSecret;
const ApiURL = process.env.CellsCloudApiBaseUrl;
const fs = require('fs');
const path = require('path');
const cellsApi = new CellsApi(clientId, clientSecret,"v3.0",ApiURL);
const localPath = "D:/aspose-cells-cloud-node/TestData/"
const filename = "Book1.xlsx";
const data =fs.createReadStream(path.join(localPath, filename));
const req = new UploadFileRequest({
path: "Temp/" + filename,
file: data
});
cellsApi.uploadFile(req)
.then((result) => {
const req = new CellsPivotTables_PutWorksheetPivotTableRequest();
req.name = filename;
req.sheetName = "Sheet4";
req.request = null;
req.folder = "Temp";
req.sourceData = "Sheet1!C6:E13";
req.destCellName = "C1";
req.tableName = "TestPivot";
req.useSameSource = true;
cellsApi.cellsPivotTablesPutWorksheetPivotTable(req)
.then((result) => {
console.log("successful")
}).catch((error) => {
console.error('Unhandled Promise Rejection:', error);
})
})
Android
Swift
Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For complete examples and data files, please go to https://github.com/aspose-cells-cloud/aspose-cells-cloud-perl/
use strict;
use warnings;
use utf8;
use File::Slurp;
use MIME::Base64;
use AsposeCellsCloud::CellsApi;
my $config = AsposeCellsCloud::Configuration->new( client_id => $ENV{'ProductClientId'}, client_secret => $ENV{'ProductClientSecret'});
my $instance = AsposeCellsCloud::CellsApi->new(AsposeCellsCloud::ApiClient->new( $config));
my $remoteFolder = 'TestData/In';
my $remoteName = 'TestCase.xlsx';
my $request = AsposeCellsCloud::Request::PutWorksheetPivotTableRequest->new();
$request->{name} = $remoteName;
$request->{sheet_name} = 'Sheet3';
$request->{folder} = $remoteFolder;
$request->{source_data} = '=Sheet1!C6:E13';
$request->{dest_cell_name} = 'C1';
$request->{table_name} = 'TestPivot';
$request->{use_same_source} = 'true';
$request->{storage_name} = '';
my $result = $api->put_worksheet_pivot_table(request=> $request);
Go