Aspose allstyle

I am trying to copy one font style to new font text in aspose using
a= Rjb.import(‘cpm.aspose.words.Run’).new(doc,text)
Font=a.getFont
Font.setStyle(field.getStyle)

Like this it is adding the AllCaps style but not Bold style . is there any way to set all the style property to new node

@lucifer90

To copy all font styles from one text run to another in Aspose.Words for Java, you can set each font property individually. The Font class provides various properties that you can use to replicate the styles, such as bold, italic, underline, and more.

Here’s an example of how to copy all relevant font properties from one Run to another:

import com.aspose.words.Document;
import com.aspose.words.Run;

public class CopyFontStyle {
    public static void main(String[] args) throws Exception {
        // Create a new document
        Document doc = new Document();
        
        // Create the first run with some styles
        Run sourceRun = new Run(doc, "Source Text");
        sourceRun.getFont().setBold(true);
        sourceRun.getFont().setItalic(true);
        sourceRun.getFont().setSize(14.0);
        
        // Append the source run to the document
        doc.getFirstSection().getBody().getFirstParagraph().appendChild(sourceRun);
        
        // Create a new run to copy styles to
        Run targetRun = new Run(doc, "Target Text");
        
        // Copy font styles from sourceRun to targetRun
        targetRun.getFont().setBold(sourceRun.getFont().getBold());
        targetRun.getFont().setItalic(sourceRun.getFont().getItalic());
        targetRun.getFont().setSize(sourceRun.getFont().getSize());
        targetRun.getFont().setColor(sourceRun.getFont().getColor());
        targetRun.getFont().setUnderline(sourceRun.getFont().getUnderline());
        // Add more properties as needed...

        // Append the target run to the document
        doc.getFirstSection().getBody().getFirstParagraph().appendChild(targetRun);
        
        // Save the document
        doc.save("CopyFontStyle.docx");
    }
}

In this example, we create a source run with specific styles and then create a target run. We copy the desired font properties from the source run to the target run. You can add more properties as needed to ensure all styles are transferred correctly.

Make sure to adjust the properties you want to copy based on your requirements. This approach allows you to have full control over which styles are applied to the new text run.

@lucifer90 The easiest way to achieve this is cloning the original run. Please see the following code:

Run existingRun =(Run)doc.getChild(NodeType.RUN, 0, true);
Run newRun = (Run)existingRun.deepClone(true);
// Set new text
newRun.setText("This run will have exactly the same formatting as the original one.");

I don’t want to clone I want to get all styles to get copy to my new node that’s it. Is there any inbuilt method for this

@lucifer90 No, unfortunately, there is no built-in method to achieve this.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26633

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.