This article demonstrates how to replace text within a PowerPoint document or a particular PowerPoint slide in Java using the TextApi interface provided by Spire.Cloud.PowerPoint.
Replace text within a PowerPoint document
import spire.cloud.powerpoint.sdk.Configuration;
import spire.cloud.powerpoint.sdk.api.TextApi;
public class ReplaceTextWithinDocument {
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration instance based on your AppID and AppKey
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a TextApi instance
static TextApi textApi = new TextApi(configuration);
public static void main(String []args) throws Exception {
//Specify the input document
String name = "template.pptx";
//Specify the text that you want to replace
String oldValue = "Spire.Presentation";
//Specify the desired text
String newValue = "New String";
//Specify ignoreCase
boolean ignoreCase = true;
//Specify the password used to open the document, and it's "null" if nothing
String password = null;
//Specify the folder storing the input document, and it's "null" if nothing
String folder = "input";
//Use the 2G storage provided by E-iceblue, and it's "null" by default
String storage = null;
//Call ReplacePresentationText method to replace text within the document
textApi.replacePresentationText(name, oldValue, newValue, ignoreCase, password, folder, storage);
}
}
Replace text within a particular PowerPoint slide
import spire.cloud.powerpoint.sdk.Configuration;
import spire.cloud.powerpoint.sdk.api.TextApi;
public class ReplaceTextWithinSlide {
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration instance based on your AppID and AppKey
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a TextApi instance
static TextApi textApi = new TextApi(configuration);
public static void main(String []args) throws Exception {
//Specify the input document
String name = "template.pptx";
//Specify the slide index
int slideIndex = 0;
//Specify the text that you want to replace
String oldValue = "Spire.Presentation";
//Specify the desired text
String newValue = "New String";
//Specify ignoreCase
boolean ignoreCase = true;
//Specify the password used to open the document, and it's "null" if nothing
String password = null;
//Specify the folder storing the input document, and it's "null" if nothing
String folder = "input";
//Use the 2G storage provided by E-iceblue, and it's "null" by default
String storage = null;
//Call ReplaceSlideText method to replace text within the slide
textApi.replaceSlideText(name, slideIndex, oldValue, newValue, ignoreCase, password, folder, storage);
}
}