CellsDrawing Font

Hi,


Attached .xlsx file contains more different Shapes. Class Shape provide the method getFont and when you execute the following code you can see is not as Excel font name and size(output:font name: Arial, font size: 10). Class RectangleShape provide the method getCharacters and if you get the Font from FontSetting, like in code, it have Font name and size as Excel(output: font name: MS Pゴシック font size: 20). But class CellsDrawing doesn’t provide the method getCharacters and I don’t know how to get the real Font? Can you help me please?

Code:
String path = “/home/emisia/Downloads/TextInShape/TextInShape.xlsx”;
Workbook workbook = new Workbook(path);
Worksheet worksheet = workbook.getWorksheets().get(0);
ShapeCollection shapes = worksheet.getShapes();
for (int i = 0; i < shapes.getCount(); i++) {
Shape shape = shapes.get(i);
if (shape instanceof RectangleShape) {
RectangleShape rectangle = (RectangleShape) shape;
Font font = rectangle.getFont();
System.out.println(“Rectangle:”);
System.out.println("font name: " + font.getName()
+ "\nfont size: " + font.getSize());
List characters = rectangle.getCharacters();
font = characters.get(0).getFont();
System.out.println(“font name: " + font.getName()
+ “\nfont size: " + font.getSize());
} else if (shape instanceof CellsDrawing) {
CellsDrawing drawing = (CellsDrawing) shape;
Font font = drawing.getFont();
System.out.println(”\nCellsDrawing:”);
System.out.println("font name: " + font.getName()
+ "\nfont size: " + font.getSize());
break;
}
}

Output:

Rectangle:
font name: Arial
font size: 10
font name: MS Pゴシック
font size: 20

CellsDrawing:
font name: Arial
font size: 10

Thanks,
Bojan

Hi,


Thanks for the sample file and code.

I can find the issue as you have mentioned by using your code with your template file. I think the feature is not supported yet as we still have some shape types and wordarts that are not supported for manipulation or rendering. We have logged a separate ticket with an id: CELLSJAVA-40371 for your issue. We will look into it soon.

Thank you.

Hi,

Thanks for your posting and using Aspose.Cells for Java

All Shape objects including CellsDrawing have the getCharacters() method. It is not needed for you to detect the concrete type of a shape to get font details.

Following code can work for all shapes in your given template file:

Java


for (int i = 0; i < shapes.getCount(); i++) {

Shape shape = shapes.get(i);

Font font = shape.getFont();

List characters = shape.getCharacters();



}