Need help…
could you please tell us how we can identify the number of characters in word and the character index of current cursor location and move left or right from the current to a specific count.
Need help…
Regarding WORDSNET-10148, you may use the following code as a workaround. Please see these sample input/output Word documents (Docs.zip (17.6 KB)). Hope, this helps:
int paragraphIndex = 0;
int characterIndex = 4;
string text = "demo";
Document doc = new Document(@"E:\\Temp\\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
Paragraph targetPara = (Paragraph)builder.CurrentStory.GetChildNodes(NodeType.Paragraph, true)[paragraphIndex];
Node[] runs = targetPara.GetChildNodes(NodeType.Run, true).ToArray();
for (int i = 0; i < runs.Length; i++)
{
Run run = (Run)runs[i];
int length = run.Text.Length;
Run currentNode = run;
for (int x = 1; x < length; x++)
{
currentNode = SplitRun(currentNode, 1);
}
}
if (characterIndex >= 0 && characterIndex < targetPara.Runs.Count)
{
builder.MoveTo(targetPara.Runs[characterIndex]);
builder.Font.Name = "Verdana";
builder.Font.Size = 16;
builder.Font.Color = Color.Red;
builder.Write(text);
}
else
{
Console.WriteLine("Incorrect character index specified");
}
doc.JoinRunsWithSameFormatting();
doc.Save(@"E:\\Temp\\20.3.docx");
private static Run SplitRun(Run run, int position)
{
Run afterRun = (Run)run.Clone(true);
afterRun.Text = run.Text.Substring(position);
run.Text = run.Text.Substring((0), (0) + (position));
run.ParentNode.InsertAfter(afterRun, run);
return afterRun;
}
We will also inform you via this thread as soon as WORDSNET-10148 will be resolved in future.
The issues you have found earlier (filed as WORDSNET-10148) have been fixed in this Aspose.Words for .NET 21.2 update and this Aspose.Words for Java 21.2 update.