How to check superscript characters in Excel worksheet cell in Java

Hi,
I am a java programmer.Suppose I have a cell value “abcde(12)” where (12) is superscript.How can i check whether cell value contains superscript font or not like contains(str) method of List and if so how can I get the superscripts string.Note that the superscript string cam be in any position of the cell value.

Thanks in advance.

Hi,

Thanks for your inquiry.

I have written a sample Java program using my simple template excel file (attached) which may help you to achieve your requirements. Please see the following code if it suits your need. The example demonstrates a simple test. If a cell has a superscript text in it, it will notify you and also gives you the superscripts characters.

Sample code:

import java.io.*;
import com.aspose.cells.*;
import java.util.*;

class GetSuperScriptText2
{


public static void main(String []args)
{

try
{

Workbook workbook = new Workbook();
workbook.open("e:\\files\\testsscripts.xls");
Worksheet worksheet = workbook.getWorksheets().getSheet(0);
Cells cells = worksheet.getCells();
Cell aCell = worksheet.getCells().getCell("A1");
String ftext= aCell.getStringValue();
Characters[] chars = aCell.getCharacters();
boolean check=false;

if(chars !=null)
{

int len = chars.length;
StringBuffer sb = new StringBuffer(ftext);
char ch[];

for(int cnt = 0;cnt<len;cnt++)
{
check = isSuperScript(chars[cnt]);

//if superscripts characters found.
if(check)
{
System.out.println("Superscript characters found!");
System.out.println("Startindex: " + chars[cnt].getStartIndex());
System.out.println("Length: " + chars[cnt].getLength());
ch = new char[chars[cnt].getLength()];
sb.getChars(chars[cnt].getStartIndex(),chars[cnt].getLength()+chars[cnt].getStartIndex(),ch,0);
for(int x = 0;x<ch.length;x++)
{
System.out.println("Superscript chars" +x+ " : " + ch[x]);
}
//break;


}

}
}



}

catch(Exception ee)
{

System.out.println(ee);
}


}

public static boolean isSuperScript(Characters chars)
{

if (chars.getFont().getEscapement()!=Font.ESCAPEMENT_SUPERSCRIPT)
{
return false;
}
else

{

return true;
}
}



}

Thank you.