Free Support Forum - aspose.com

Special characters in cells

Hallo,

how can I put special characters, such as alpha, beta or gamma in cells? In HTML I use another font e.g. "Symbol" to do that:

Example:
- HTML: a1-Antitrypsin
- Aspose.Cells: cells("A1").PutValue("a1-Antitrypsin")

In Excel files normally you have to select the "a" and choose the font "Symbol" (see Screenshot). But what about the category axis?

How can I solve that problem in Aspose.Cells?

Many thanks.

Martin

Hi,

Thanks for considering Aspose.

It's very simple using Aspose.Cells APIs, Please check the following example code for your need:

[C#]

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
cells["A1"].PutValue("a1-Antitrypsin");
cells["A1"].Characters(0, 1).Font.Name = "Symbol";
cells["A1"].Characters(0, 1).Font.IsBold = true;
cells["A1"].Characters(0, 1).Font.Color = Color.Red;
workbook.Save("d:\\test\\symbolcharacters.xls");

[VB]

Dim workbook As Workbook = New Workbook()
Dim worksheet As Worksheet = workbook.Worksheets(0)
Dim cells As Cells = worksheet.Cells
cells("A1").PutValue("a1-Antitrypsin")
cells("A1").Characters(0, 1).Font.Name = "Symbol"
cells("A1").Characters(0, 1).Font.IsBold = True
cells("A1").Characters(0, 1).Font.Color = Color.Red
workbook.Save("d:\test\symbolcharacters.xls")

Thank you.

Thanks a lot.

This helps to get special characters in Excel cells, but not in charts, e.g. in category axis (see screenshot). Do you have any idea?

Martin

Hi Martin,

Please try the following codes:

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
cells["A1"].PutValue("α1-Antitrypsin");
cells["A2"].PutValue("α2-Antitrypsin");
cells["A3"].PutValue("α3-Antitrypsin");
cells["B1"].PutValue(1);
cells["B2"].PutValue(2);
cells["B3"].PutValue(3);
int index = worksheet.Charts.Add(ChartType.Column, 3, 3, 10, 8);
Chart chart = worksheet.Charts[index];
chart.NSeries.Add("B1:B3", true);
//chart.NSeries.CategoryData = "A1:A3";
chart.NSeries.CategoryData = "{α1,α2,α3}";