Hi support team,
Thanks for your awesome product, really love it!
Currently I am using NodeJS SDK to handle API Call with Aspose.Word. I have a small question:
I have a document like that:
{{ Text1 }} {{ Text2 }} {{ Text3 }} {{ Text4 }} ... {{ Text100 }}
Currently, I need to call Search & Replace API 100 times, and it not good for performance.
According to Replace multiple text items in a single API call using replaceText API of Aspose.Words Cloud, there is no way to do multiple Search & Replace in one API call.
But can you guys please tell me if there is another way to improve it?
Thanks,
Duc.
@ducbuiquangxd
Thank you for contacting Aspose Support.
I have logged a request WORDSCLOUD-409 for our Development team to extend
POST /words/{name}/replaceText API that will let you replace multiple text items in a single API call. Please spare us some time for implementation. Your patience would be appreciated.
Thanks for your help!
Please ping me whenever. multiple search & replace text feature is integrated.
@ducbuiquangxd
Sure, we will update you here as soon as the feature is implemented.
@ducbuiquangxd
We would suggest you use our Mail Merge features that are appropriate for the use case of mass text replacement.
The issues you have found earlier (filed as WORDSCLOUD-409) have been fixed in this update. This message was posted using Bugs notification tool by Ivanov_John
@ducbuiquangxd
About, your above request, we have implemented the batch requests feature in the latest versions of Aspose.Words Cloud SDKs. Now, it allows you to run a bunch of requests as one. Please check the following sample code to search and replace multiple strings. Hopefully, it will help you to accomplish the task.
string sourceFile = @"....source.docx";
string remoteName = "source.docx";
string resultFile = @"....result.docx";
// old and new texts
string[] oldTexts = { "Old", "2020" };
string[] newTexts = { "New", "2021" };
// add all replacements as batch part requests
var requests = new BatchPartRequest[oldTexts.Length + 2];
int i = 0;
// create requests
using (var source = File.OpenRead(sourceFile))
{
requests[i++] = new BatchPartRequest(new UploadFileRequest
{
FileContent = source,
Path = remoteName
});
for (; i <= oldTexts.Length; i++)
{
requests[i] = new BatchPartRequest(new ReplaceTextRequest
{
Name = remoteName,
ReplaceText = new ReplaceTextParameters
{
OldValue = oldTexts[i - 1],
NewValue = newTexts[i - 1],
IsMatchCase = false,
}
});
// set dependecy tree to run request one by one.
requests[i].DependsOn(requests[i-1]);
}
requests[i] = new BatchPartRequest(new DownloadFileRequest
{
Path = remoteName,
});
requests[i].DependsOn(requests[i - 1]);
// run uploading, all replacements, and downloading as one batch request
var results = this.WordsApi.Batch(requests);
using (var fs = new FileStream(resultFile, FileMode.OpenOrCreate))
{
// save the result to resultFile
(results.Last() as Stream).CopyTo(fs);
}
}