Replace content in remote range Excel API : ReplaceContentInRemoteRange
Replace text in the range of remoted spreadsheet.
Interface Details
Endpoint
Copy PUT http://api.aspose.cloud/v4.0/cells/ {name}/worksheets/ {worksheet}/ranges/ {cellArea}/replace/content
Function Description
This method replaces specified text within a range of spreadsheet file stored in remote cloud storage.It supports replacing occurrences of the target text across all sheets and cells of the workbook directly within the cloud environment.The operation is performed remotely, eliminating the need to download the file to the local machine.Ensure that you have valid cloud storage credentials and accessible file paths or identifiers for the target spreadsheet.If the source file cannot be accessed, permissions are insufficient, writing to the file fails, or an error occurs during the replacement process (such as an unsupported file format), an appropriate exception will be thrown.Depending on the implementation, the method may return the number of replacements made or the locations of the replaced texts (e.g., sheet name, cell coordinates).Users should specify the exact text to replace and its replacement to ensure accurate modifications.
The request parameters of replaceContentInRemoteRange API are:
Parameter Name
Type
Path/Query String/HTTPBody
Description
name
String
Path
The name of the workbook file to be replace.
searchText
String
Query
The searched text.
replaceText
String
Query
The replaced text.
worksheet
String
Path
The worksheet name.
cellArea
String
Path
The cell area for the replace.
folder
String
Query
The folder path where the workbook is stored.
storageName
String
Query
(Optional) The name of the storage if using custom cloud storage. Use default storage if omitted.
regoin
String
Query
The spreadsheet region setting.
password
String
Query
The password for opening spreadsheet file.
Response Description
Copy {
"Name" : "CellsCloudResponse" ,
"Type" : "Class" ,
"IsAbstract" : false ,
"Properties" : [
{
"Name" : "Code" ,
"Nullable" : true ,
"ReadOnly" : false ,
"IsInherit" : false ,
"DataType" : {
"Identifier" : "Integer" ,
"Name" : "integer"
}
},
{
"Name" : "Status" ,
"Nullable" : true ,
"ReadOnly" : false ,
"IsInherit" : false ,
"DataType" : {
"Identifier" : "String" ,
"Name" : "string"
}
}
]
}
OpenAPI Specification
The OpenAPI Specification defines a publicly accessible programming interface and lets you carry out REST interactions directly from a web browser.
Excel API SDK
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 hidden or 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
using Aspose.Cells.Cloud.SDK.Api;
using Aspose.Cells.Cloud.SDK.Model;
using Aspose.Cells.Cloud.SDK.Request;
using System;
using System.IO;
using System.Collections.Generic;
using Range = Aspose.Cells.Cloud.SDK.Model.Range;
public static class Example40_ReplaceTextInRemoteRange
{
public static void Run()
{
CellsApi cellsApi = new CellsApi("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
string remoteFolder = "TestData/In";
string bookTextXlsx = "BookText.xlsx";
var request = new ReplaceContentInRemoteRangeRequest(
name: bookTextXlsx,
searchText: "Bike",
replaceText: "****",
worksheet: "Sales",
cellArea: "A1:A10",
folder: remoteFolder
);
cellsApi.ReplaceContentInRemoteRange(request);
}
}
Java
This file contains hidden or 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 org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.util.HashMap;
public class ExampleReplaceContentInRemoteRange {
private CellsApi api;
public ExampleReplaceContentInRemoteRange(){
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 bookTextXlsx = "BookText.xlsx";
UploadFileRequest uploadFileRequest = new UploadFileRequest();
uploadFileRequest.setPath( remoteFolder + "/" + bookTextXlsx );
uploadFileRequest.setStorageName( "");
HashMap<String,File> files = new HashMap<String,File>();
files.put( bookTextXlsx , new File(bookTextXlsx ));
uploadFileRequest.setUploadFiles(files);
cellsApi.uploadFile(uploadFileRequest);
ReplaceContentInRemoteRangeRequest request = new ReplaceContentInRemoteRangeRequest();
request.setName(bookTextXlsx);
request.setSearchText("Bike");
request.setReplaceText("****");
request.setWorksheet("Sales");
request.setCellArea("A1:A10");
request.setFolder(remoteFolder);
this.api.replaceContentInRemoteRange(request);
} catch (ApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
PHP
This file contains hidden or 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
<?php
require_once('vendor\autoload.php');
use \Aspose\Cells\Cloud\Api\CellsApi;
use \Aspose\Cells\Cloud\Request\ReplaceContentInRemoteRangeRequest;
$cellsApi = new CellsApi(getenv("CellsCloudClientId"),getenv("CellsCloudClientSecret"),"v3.0",getenv("CellsCloudApiBaseUrl"));
$remoteFolder = "TestData/In";
$bookTextXlsx = "BookText.xlsx";
CellsApiTestBase::ready( $this->instance,$bookTextXlsx ,$remoteFolder . "/" . $bookTextXlsx , "");
$request = new ReplaceContentInRemoteRangeRequest();
$request->setName( $bookTextXlsx);
$request->setSearchText( "Bike");
$request->setReplaceText( "****");
$request->setWorksheet( "Sales");
$request->setCellArea( "A1:A10");
$request->setFolder( $remoteFolder);
$$cellsApi->replaceContentInRemoteRange($request);
Ruby
This file contains hidden or 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
require 'openssl'
require 'bundler'
require 'aspose_cells_cloud'
@instance = AsposeCellsCloud::CellsApi.new(ENV['CellsCloudClientId'], ENV['CellsCloudClientSecret'],'v3.0',ENV['CellsCloudApiBaseUrl'])
remote_folder = 'TestData/In'
book_text_xlsx = 'BookText.xlsx'
mapFiles = { }
mapFiles[book_text_xlsx] = ::File.open(File.expand_path("TestData/"+book_text_xlsx),"r")
uploadrequest = AsposeCellsCloud::UploadFileRequest.new( { :UploadFiles=>mapFiles,:path=>remote_folder })
@instance.upload_file(uploadrequest)
request = AsposeCellsCloud::ReplaceContentInRemoteRangeRequest.new(:name=>book_text_xlsx,:searchText=>'Bike',:replaceText=>'****',:worksheet=>'Sales',:cellArea=>'A1:A10',:folder=>remote_folder);
@instance.replace_content_in_remote_range(request);
Node.js
This file contains hidden or 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
var fs = require('fs');
var path = require('path');
const _ = require('asposecellscloud');
const cellsApi = new CellsApi(process.env.CellsCloudClientId, process.env.CellsCloudClientSecret,"v3.0",process.env.CellsCloudApiBaseUrl);
var remoteFolder = "TestData/In"
var bookTextXlsx = "BookText.xlsx"
var bookTextXlsxRequest = new model.UploadFileRequest();
bookTextXlsxRequest.uploadFiles ={bookTextXlsx:fs.createReadStream(localPath + bookTextXlsx)};
bookTextXlsxRequest.path = remoteFolder + "/" + bookTextXlsx ;
bookTextXlsxRequest.storageName ="";
cellsApi.uploadFile(bookTextXlsxRequest );
var request = new model.ReplaceContentInRemoteRangeRequest();
request.name = bookTextXlsx;
request.searchText = "Bike";
request.replaceText = "****";
request.worksheet = "Sales";
request.cellArea = "A1:A10";
request.folder = remoteFolder;
return cellsApi.replaceContentInRemoteRange(request).then((result) => {
expect(result.response.statusCode).to.equal(200);
});
Python
This file contains hidden or 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
import os
import sys
from asposecellscloud.apis.cells_api import CellsApi
from asposecellscloud.models import *
from asposecellscloud.requests import *
api = CellsApi(os.getenv('CellsCloudClientId'),os.getenv('CellsCloudClientSecret'),"v3.0",os.getenv('CellsCloudApiBaseUrl'))
remote_folder = 'TestData/In'
book_text_xlsx = 'BookText.xlsx'
mapFiles = {
local_name: local_name
}
request = UploadFileRequest( mapFiles, remote_folder + '/' + remote_name,storage_name= '')
api.upload_file(request)
request = ReplaceContentInRemoteRangeRequest( book_text_xlsx, 'Bike', '****', 'Sales', 'A1:A10',folder= remote_folder)
api.replace_content_in_remote_range(request)
Perl
This file contains hidden or 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
use lib 'lib';
use strict;
use warnings;
use File::Slurp;
use MIME::Base64;
use AsposeCellsCloud::CellsApi;
my $config = AsposeCellsCloud::Configuration->new( client_id => $ENV{'CellsCloudClientId'}, client_secret => $ENV{'CellsCloudClientSecret'});
my $instance = AsposeCellsCloud::CellsApi->new(AsposeCellsCloud::ApiClient->new( $config));
my $remoteFolder = 'TestData/In';
my $bookTextXlsx = 'BookText.xlsx';
my $upload_file_request = AsposeCellsCloud::Request::UploadFileRequest->new( 'UploadFiles'=>{ $bookTextXlsx => $bookTextXlsx } ,'path'=>$remoteFolder . '/' . $bookTextXlsx );
my $request = AsposeCellsCloud::Request::ReplaceContentInRemoteRangeRequest->new();
$request->{name} = $bookTextXlsx;
$request->{search_text} = 'Bike';
$request->{replace_text} = '****';
$request->{worksheet} = 'Sales';
$request->{cell_area} = 'A1:A10';
$request->{folder} = $remoteFolder;
$instance->replace_content_in_remote_range(request=> $request);
Go
This file contains hidden or 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 main
import (
"os"
asposecellscloud "github.com/aspose-cells-cloud/aspose-cells-cloud-go"
)
func main() {
instance := asposecellscloud.NewCellsApiService(os.Getenv("ProductClientId"), os.Getenv("ProductClientSecret"), "https://api.aspose.cloud", "v3.0")
remoteFolder := "TestData/In"
bookTextXlsx := "BookText.xlsx"
bookTextXlsxRequest := new(asposecellscloud.UploadFileRequest)
bookTextXlsxRequest.UploadFiles = make(map[string]string)
bookTextXlsxRequest.UploadFiles[bookTextXlsx] = bookTextXlsx
bookTextXlsxRequest.Path = remoteFolder + "/" + bookTextXlsx
bookTextXlsxRequest.StorageName =""
instance.UploadFile(bookTextXlsxRequest )
request := new (asposecellscloud.ReplaceContentInRemoteRangeRequest)
request.Name = bookTextXlsx
request.SearchText = "Bike"
request.ReplaceText = "****"
request.Worksheet = "Sales"
request.CellArea = "A1:A10"
request.Folder = remoteFolder
_, httpResponse, err := instance.ReplaceContentInRemoteRange(request)
if err != nil {
t.Error(err)
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
t.Fail()
}
}