Replace spreadsheet content Excel API : ReplaceSpreadsheetContent
Replace text in the local spreadsheet.
Interface Details
Endpoint
Copy PUT http://api.aspose.cloud/v4.0/cells/replace/content
Function Description
This method replaces specified text within a local spreadsheet file. It supports replacing occurrences of the target text across all sheets and cells of the workbook.The operation is performed cloudly, requiring no cloud storage.Ensure that you have the necessary permissions to read from and write to the source file.If the source file cannot be accessed, if writing to the file fails, or if 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 replaceSpreadsheetContent API are:
Parameter Name
Type
Path/Query String/HTTPBody
Description
Spreadsheet
File
FormData
Upload spreadsheet file.
searchText
String
Query
The searched text.
replaceText
String
Query
The replaced text.
worksheet
String
Query
Specify the worksheet for the replace.
cellArea
String
Query
Specify the cell area for the replace.
regoin
String
Query
The spreadsheet region setting.
password
String
Query
The password for opening spreadsheet file.
Response Description
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_ReplaceTextInLocalFile
{
public static void Run()
{
CellsApi cellsApi = new CellsApi("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
string bookTextXlsx = "BookText.xlsx";
var request = new ReplaceSpreadsheetContentRequest(
spreadsheet: "TestData/" + bookTextXlsx,
searchText: "Bike",
replaceText: "****"
);
cellsApi.ReplaceSpreadsheetContent(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 ExampleReplaceSpreadsheetContent {
private CellsApi api;
public ExampleReplaceSpreadsheetContent(){
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 bookTextXlsx = "BookText.xlsx";
ReplaceSpreadsheetContentRequest request = new ReplaceSpreadsheetContentRequest();
request.setSpreadsheet("TestData/" + bookTextXlsx);
request.setSearchText("Bike");
request.setReplaceText("****");
this.api.replaceSpreadsheetContent(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\ReplaceSpreadsheetContentRequest;
$cellsApi = new CellsApi(getenv("CellsCloudClientId"),getenv("CellsCloudClientSecret"),"v3.0",getenv("CellsCloudApiBaseUrl"));
$bookTextXlsx = "BookText.xlsx";
$request = new ReplaceSpreadsheetContentRequest();
$request->setSpreadsheet( "TestData/" . $bookTextXlsx);
$request->setSearchText( "Bike");
$request->setReplaceText( "****");
$$cellsApi->replaceSpreadsheetContent($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'])
book_text_xlsx = 'BookText.xlsx'
request = AsposeCellsCloud::ReplaceSpreadsheetContentRequest.new(:Spreadsheet=>'TestData/' + book_text_xlsx,:searchText=>'Bike',:replaceText=>'****');
@instance.replace_spreadsheet_content(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 bookTextXlsx = "BookText.xlsx"
var request = new model.ReplaceSpreadsheetContentRequest();
request.spreadsheet = "TestData/" + bookTextXlsx;
request.searchText = "Bike";
request.replaceText = "****";
return cellsApi.replaceSpreadsheetContent(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'))
book_text_xlsx = 'BookText.xlsx'
request = ReplaceSpreadsheetContentRequest( 'TestData/' + book_text_xlsx, 'Bike', '****')
api.replace_spreadsheet_content(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 $bookTextXlsx = 'BookText.xlsx';
my $request = AsposeCellsCloud::Request::ReplaceSpreadsheetContentRequest->new();
$request->{spreadsheet} = 'TestData/' . $bookTextXlsx;
$request->{search_text} = 'Bike';
$request->{replace_text} = '****';
$instance->replace_spreadsheet_content(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")
bookTextXlsx := "BookText.xlsx"
request := new (asposecellscloud.ReplaceSpreadsheetContentRequest)
request.Spreadsheet = "TestData/" + bookTextXlsx
request.SearchText = "Bike"
request.ReplaceText = "****"
_, httpResponse, err := instance.ReplaceSpreadsheetContent(request)
if err != nil {
t.Error(err)
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
t.Fail()
}
}