Add Superscript from HTML Span | Find & Replace Text in Word DOC File using Java | Calendar Date Format Zone

Hi,
I am replacing a word in the doc file with some date in different format. In all the format day of month will come along with its superscript(for eg: 19th th has superscript ), and for some reason i have to add the superscript in html.So i am adding the superscript as <span style=“vertical-align: super;”>. For date format, month and year coming after date also coming as superscript. Attaching sample code with input,output and expected output SuperscriptIssue.zip (57.7 KB). Please help me to solve this issue.

Thank you

@Gptrnt,

The “output.docx” you shared was generated by Aspose.Words for Java 20.6; but, we have managed to produce a similar output when using Aspose.Words for Java 20.11 on our end. We are checking this scenario further on our end and will get back to you soon.

@Gptrnt,

Please change your “dateHandler” method in Main.java and replace <span/> with </span>.

public String dateHandler(long dateInMillisec,String dateFormat ) throws Exception {

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
    DateFormat df = new SimpleDateFormat(dateFormat);
    df.setTimeZone(TimeZone.getTimeZone("IST"));
    calendar.setTimeInMillis(dateInMillisec);
    String supScript = calculateSuperScript(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
    supScript = "<span style=\"vertical-align: super;\">" + supScript + "</span>";
    String date = df.format(calendar.getTime());
    date = addSuperScript(date, dateFormat, supScript);
    return date;
}