[英]XSLFGroupShape does not encompass its child shapes
我正在使用 Apache POI 3.16(撰寫本文時的最新版本)。 在下面的代碼片段中,我創建了一個 XSLFGroupShape,然后我用它來創建一堆子形狀:
XSLFGroupShape group = slide.createGroup();
XSLFAutoShape cardRect = group.createAutoShape();
cardRect.setShapeType(ShapeType.RECT);
cardRect.setAnchor(rect);
XSLFPictureShape avatarShape = group.createPicture(avatar);
// More shapes added to the group here...
問題如下:在生成的 PowerPoint 文件中,組位置和尺寸似乎未初始化(我選擇了內容像素化的矩形;整個矩形及其內容是單個 XSLFGroupShape;注意組的操縱器位於幻燈片的左上角):
我的代碼中是否缺少任何內容? 有沒有辦法規避或解決這個問題?
GroupShape
需要一個Anchor
和一個InteriorAnchor
。 並且分組的形狀必須適合GroupShape
。 當用戶與組一起工作時, PowerPoint
GUI 會自動進行管理。 但是apache poi
需要為此進行正確的設置,因為它只是將程序所說的內容寫入文件。
示例:寬度為 350,高度為 300,左側為 100,頂部為 50 的組形狀和每個角的簡單形狀。
import java.io.FileOutputStream;
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.sl.usermodel.*;
import java.awt.Rectangle;
import java.awt.Color;
public class CreatePPTXGroupShape {
public static void main(String[] args) throws Exception {
SlideShow slideShow = new XMLSlideShow();
Slide slide = slideShow.createSlide();
int groupLeft = 100;
int groupTop = 50;
int groupWidth = 350;
int groupHeight = 300;
int groupPadding= 10;
GroupShape group = slide.createGroup();
group.setInteriorAnchor(new Rectangle(groupLeft, groupTop, groupWidth, groupHeight));
group.setAnchor(new Rectangle(groupLeft+groupPadding, groupTop+groupPadding, groupWidth-groupPadding, groupHeight-groupPadding));
AutoShape shape = group.createAutoShape();
shape.setShapeType(ShapeType.RECT);
shape.setFillColor(Color.GREEN);
shape.setAnchor(new Rectangle(groupLeft, groupTop, 150, 100));
shape = group.createAutoShape();
shape.setShapeType(ShapeType.TRIANGLE);
shape.setFillColor(Color.RED);
shape.setAnchor(new Rectangle(groupLeft+groupWidth-120, groupTop, 120, 100));
shape = group.createAutoShape();
shape.setShapeType(ShapeType.DONUT);
shape.setFillColor(Color.YELLOW);
shape.setAnchor(new Rectangle(groupLeft, groupTop+groupHeight-90, 90, 90));
shape = group.createAutoShape();
shape.setShapeType(ShapeType.ELLIPSE);
shape.setFillColor(Color.BLUE);
shape.setAnchor(new Rectangle(groupLeft+groupWidth-100, groupTop+groupHeight-100, 100, 100));
FileOutputStream out = new FileOutputStream("CreatePPTXGroupShape.pptx");
slideShow.write(out);
out.close();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.