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