我创建了一个带有textString的形状。我已经能够居中放置文本框,但是似乎无法居中对齐中心。
使用Apache Poi 3.9版
EX:
我尝试了以下方法:
XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 25, 3, 32);
XSSFSimpleShape shape = drawing.createSimpleShape(anchor);
XSSFRichTextString textString = new XSSFRichTextString();
XSSFFont font = workbook.createFont();
font.setColor(HSSFColor.WHITE.index);
shape.setShapeType(ShapeTypes.ELLIPSE);
textString.setString(LeadSheetCoverPage.ADD_YOUR_LOGO.getText(dataStore.getLanguage()));
textString.applyFont(font);
shape.getCTShape().getTxBody().getBodyPr().setAnchor(STTextAnchoringType.CTR);
// This line below doesn't seem to align the Paragraph text to center
shape.getCTShape().getTxBody().getPList().get(0).getPPr().setAlgn(STTextAlignType.CTR);
shape.setFillColor(211, 211, 211);
shape.setLineStyleColor(0, 0, 0);
shape.setText(textString);
答案 0 :(得分:2)
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2
使用当前的apache poi 4.1.0
提供了XSSFSimpleShape.setVerticalAlignment。文本在提供XSSFTextParagraph.setTextAlign的XSSFSimpleShape
中。
示例:
XSSFTextParagraph
答案 1 :(得分:0)
对我有用的不是以上两种,我也不想升级。
CTTextParagraphProperties lv1PPr =
shape.getCTShape().getTxBody().getLstStyle().addNewLvl1PPr();
lv1PPr.setAlgn(STTextAlignType.CTR);
由于某种原因,上述方法不起作用,但对STTextAnchoringType起作用。