Free Support Forum - aspose.com

Subscript in a part of the cell

Hi,

In our application, we want to use Aspose Cells to produce reports... Some values have this format:
"34 H@@20" where "@@" indicate that the next character must be in subscript. How can I make that using Aspose Cells??

Thanks

Steeve
N.B.: I found a link on this page:
http://www.aspose.com/community/forums/46226/subscript-and-special-chatacter-manipulations-in-a-cell-and-checkbox-api/showthread.aspx#46226

But it redirect me on
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/index.html... So I cannot find the appropriate information...

Hi,

I think, you can simply use Cell.PutValue method. I have written a code example and also attached the output file. Please have a look at this and let me know if it fulfills your requirement and if it does not, then please provide me your source workbook which you can create manually using Ms-Excel and post here.

C#


Workbook workbook = new Workbook();


Worksheet worksheet = workbook.Worksheets[0];


worksheet.Cells[“A1”].PutValue(“34 H@@20”);


worksheet.AutoFitColumns();


workbook.Save(OUTDIR + “output.xlsx”, SaveFormat.Xlsx);

Hi Shakeel,

I let you an example of what I want. All the data come from a SQL database. In the example, I have 2 tabs: One with the result that I want and the other is my "actual result".

So, I want to obtain this result using Aspose Cells...

Thanks

Steeve

Hi,

Thanks for your further explanation. I now understand your requirement. I will post sample code after investigating it.

Hi Shakeel,

I try to find a solution, but I did not find. Do you any suggestion for me??

Thanks

Steeve

Hi,

Thanks for your patience. Please see the code below.

What I did, I inserted some text “ABC” inside the cell A1. Then I made B as a subscript.

Kindly see the output file and screenshot.

C#


Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];

Cell a1 = worksheet.Cells[“A1”];

a1.PutValue(“ABC”);

a1.Characters(1, 1).Font.IsSubscript = true; //Make B as subscript inside ABC

workbook.Save(@“F:\Shak-Data-RW\Downloads\Files\output.xlsx”, SaveFormat.Xlsx);

Screenshot:

Hi Shakeel,
I used what you suggested and I add a portion to remove "@@"... See below:

// Check for character in subscript (@@)
// Store all positions of the characters to change in subscript
// (le "j - (k * 2)" is use to calculate the position of the charecter after removing "@@")
int j = value.IndexOf("@@");
if (j >= 0)
{
int k = 0;
List<int> iListIndex = new List<int>();

while (j >= 0)
{
k++;
j = j + 2;
iListIndex.Add(j - (k * 2));

int jStart = j;
j = value.IndexOf("@@", jStart);
}

value = value.Replace("@@", "");
cell.Value = value;

foreach (int i in iListIndex)
cell.Characters(i, 1).Font.IsSubscript = true;
}
else
cell.Value = value;

Thanks for your help!!!

Steeve