Spire.Cloud.Word provides the mergeApi interface for developers to merge Word documents, and this tutorial will demonstrate how to do it.
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.MergeApi;
import spire.cloud.word.sdk.client.model.MergingFile;
import java.util.*;
public class MergeWordDocuments {
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = " https://api.cloudxdocs.com ";
//Create a Configuration object based on your AppID and AppKey
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
//Create a mergeApi instance
static MergeApi mergeApi = new MergeApi(wordConfiguration);
public static void main(String[] args) throws ApiException{
//Load the first sample document
String name = "Sample1.docx";
//Load the second sample document and add it into List
List files = new ArrayList();
files.add(new MergingFile("input/Sample2.docx",null,null));
//Specify the folder storing the first sample. It’s null if nothing
String folder = "input";
//Specify password of the first sample. It’s null if nothing
String password = null;
//Use the 2G storage provided by E-iceblue. It's null by default
String storage = null;
//Save the resulting document to a specified path
String destFilePath = "output/mergeDocument.docx";
//Call the mergeDocument method to merge Word documents
mergeApi.mergeDocument(name, files, destFilePath, folder, storage, password);
}
}