Cell value

Suppose I have a List.Now I want to set all string of the list in one cell where last character of each string will be a superscript. E.g

List<1> = abc1

List<2> = def2

The cell value will be : abc1def2 where 1,2 will be superscipt

Hi,
Thanks for your inquiry.

May the following sample code help you for your need, kindly refer to it.

Sample code:

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
Cell aCell = worksheet.Cells["A1"];
aCell.PutValue("abc1def2");
//Set 1 as superscript.
aCell.Characters(3, 1).Font.IsSuperscript = true;
aCell.Characters(7, 1).Font.IsSuperscript = true;
workbook.Save("f:\\test\\tcharTest.xls");

Also, kindly refer to the documentation link: http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/formatting-selected-characters-in-a-cell.html

Thank you.

Thanks for the reply.
Actually the whole process that I want is dynamic.
Suppose I have a class named CellEntry.The class is as follows.
class CellEntry{
private String text;
private String supScriptText;
public CellEntry(String text,String supScriptText){
this.text = text;
this.supScriptText = supScriptText;
}
public String getText(){
return text;
}
public String getSupScriptText(){

return text;

}
public String setText(String text){

this.text = text;

}
public String setsupScriptText(String text){

  this.supScriptText= text;<br>

}


}
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
Cell aCell = worksheet.Cells[“A1”];

CellEntry ce1 = new CellEntry (“abc”,“10”);
CellEntry ce2 = new CellEntry (“def”,“20”);
List list = new Arraylist();
list.add(ce1);
list.add(ce2);
for(int i = 0; i < list.size(); i++){
CellEntry tempCe1 = list.get(i);
/* Now I want to make the following Output in One cell(aCell )
abc10def20 where 10 and 20 will be superscript
*/
}

Hi,

Well, I think you are using Java version of Aspose.Cells.

May the following sample code help you for your requirement, kindly consult it.

Sample codes:

[Java]

(The code actually does make 10 and 20 numbers as superscript text in the cell's string value.)

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

class RichText
{


public static void main(String []args)
{

try
{

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().getSheet(0);
Cells cells = worksheet.getCells();
Cell aCell = worksheet.getCells().getCell("A1");

CellEntry ce1 = new CellEntry("abc", "10");
CellEntry ce2 = new CellEntry("def", "20");

List list = new ArrayList();
list.add(ce1);
list.add(ce2);

String ftext= new String();

for(int i = 0; i < list.size(); i++)
{

CellEntry tempCe1 = list.get(i);
ftext = ftext + tempCe1.getText() + tempCe1.getSupScriptText();

}
Font font;
aCell.setValue(ftext);
int startIndex = 0;
for(int i = 0; i < list.size(); i++)
{
CellEntry tempCe1 = list.get(i);
startIndex += tempCe1.getText().length();
font = new Font();
font.setEscapement(Font.ESCAPEMENT_SUPERSCRIPT);

aCell.setCharacters(startIndex, tempCe1.getSupScriptText().length(),font);
startIndex += tempCe1.getSupScriptText().length();
}

workbook.save ("e:\\files\\RichChartsTest.xls");

}

catch(Exception ee)
{

System.out.println(ee);
}

}

}


class CellEntry
{
private String text;
private String supScriptText;
public CellEntry(String text, String supScriptText)
{
this.text = text;
this.supScriptText = supScriptText;
}
public String getText()
{
return text;
}
public String getSupScriptText()
{
return supScriptText;
}
public void setText(String text)
{
this.text = text;
}
public void setsupScriptText(String text)
{
this.supScriptText = text;
}

}

I also write parallel [C#] code here if you would require this one too.

[C#]

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
Cell aCell = worksheet.Cells["A1"];

CellEntry ce1 = new CellEntry("abc", "10");
CellEntry ce2 = new CellEntry("def", "20");
ArrayList list = new ArrayList();
list.Add(ce1);
list.Add(ce2);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < list.Count; i++)
{
CellEntry tempCe1 = (CellEntry)list[i];
stringBuilder.Append(tempCe1.getText());
stringBuilder.Append(tempCe1.getSupScriptText());
}
aCell.PutValue(stringBuilder.ToString());
MessageBox.Show(stringBuilder.ToString());
int startIndex = 0;
for (int i = 0; i < list.Count; i++)
{
CellEntry tempCe1 = (CellEntry)list[i];
startIndex += tempCe1.getText().Length;
Characters characters = aCell.Characters(startIndex, tempCe1.getSupScriptText().Length);
characters.Font.IsSuperscript = true;
startIndex += tempCe1.getSupScriptText().Length;
}
workbook.Save (@"e:\files\RichChartsTest.xls");

Note: Obviously the CellEntry class remains the same even in .NET.

Thank you.

Thanks for the reply.It’s working as i wanted.