翻譯|行業資訊|編輯:胡濤|2023-08-22 10:18:18.230|閱讀 180 次
概述:本文為您提供了在 Java 中鎖定 PowerPoint PPT 形狀的綜合指南,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Slides 是一款 PowerPoint管理API,用于讀取,編寫,操作和轉換PowerPoint幻燈片的獨立API,可將PowerPoint轉換為PDF,PDF/A,XPS,TIFF,HTML,ODP和其他PowerPoint格式。
Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
本文為您提供了在 Java 中鎖定 PowerPoint PPT 形狀的綜合指南。因此,您可以保護 PowerPoint 演示文稿的內容。出于多種原因,鎖定形狀可能很有用,包括防止意外更改、保護品牌標識、保持布局完整性等。那么,讓我們繼續看看如何在 Java 演示文稿中鎖定或解鎖形狀。
要鎖定和解鎖 PowerPoint 演示文稿,我們將使用Aspose.Slides for Java。它是一個功能豐富的 Java 庫,用于創建和操作演示文稿文檔。您可以下載該庫或使用pom.xml中的以下依賴項進行安裝。
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-slides</artifactId> <version>23.7</version> <classifier>jdk16</classifier> </dependency>
PowerPoint 演示文稿由多種元素組成,例如文本、圖像、音頻等。Aspose.Slides for Java 將每個元素視為 Shape 或從 Shape 派生的 abject。因此,如果鎖定演示文稿中的所有形狀,就可以防止 PPT 被修改。
Aspose.Slides for Java 將 PowerPoint 形狀分為以下類型:
現在讓我們看看如何用 Java 鎖定 PowerPoint PPT 中的形狀。
以下代碼示例演示如何使用 Java 鎖定 PowerPoint PPT 中的形狀。
try {
//Load presentation file
Presentation pTemplate = new Presentation("presentation.pptx");
//ISlide object for accessing the slides in the presentation
ISlide slide = pTemplate.getSlides().get_Item(0);
//IShape object for holding temporary shapes
IShape shape;
//Traverse through all the slides in the presentation
for (int slideCount = 0; slideCount < pTemplate.getSlides().size(); slideCount++) {
slide = pTemplate.getSlides().get_Item(slideCount);
//Traverse through all the shapes in the slides
for (int count = 0; count < slide.getShapes().size(); count++) {
shape = slide.getShapes().get_Item(count);
//if shape is auto shape
if (shape instanceof IAutoShape) {
//Type casting to Auto shape and getting auto shape lock
IAutoShape Ashp = (IAutoShape) shape;
IAutoShapeLock AutoShapeLock = (IAutoShapeLock) Ashp.getShapeLock();
//Apply shape locks
AutoShapeLock.setPositionLocked(true);
AutoShapeLock.setSelectLocked(true);
AutoShapeLock.setSizeLocked(true);
}
//if shape is group shape
else if (shape instanceof IGroupShape) {
//Type casting to group shape and getting group shape lock
IGroupShape Group = (IGroupShape) shape;
IGroupShapeLock groupShapeLock = (IGroupShapeLock) Group.getShapeLock();
//Apply shape locks
groupShapeLock.setGroupingLocked(true);
groupShapeLock.setPositionLocked(true);
groupShapeLock.setSelectLocked(true);
groupShapeLock.setSizeLocked(true);
}
//if shape is a connector
else if (shape instanceof IConnector) {
//Type casting to connector shape and getting connector shape lock
IConnector Conn = (IConnector) shape;
IConnectorLock ConnLock = Conn.getShapeLock();
//Apply shape locks
ConnLock.setPositionMove(true);
ConnLock.setSelectLocked(true);
ConnLock.setSizeLocked(true);
}
//if shape is picture frame
else if (shape instanceof IPictureFrame) {
//Type casting to pitcture frame shape and getting picture frame shape lock
IPictureFrame Pic = (IPictureFrame) shape;
IPictureFrameLock PicLock = (IPictureFrameLock) Pic.getShapeLock();
//Apply shape locks
PicLock.setPositionLocked(true);
PicLock.setSelectLocked(true);
PicLock.setSizeLocked(true);
}
}
}
//Save the presentation file
pTemplate.save("ProtectedSample.pptx", SaveFormat.Pptx);
} catch (Exception e) {
}
要解鎖 PowerPoint PPT 中鎖定的形狀,只需將其值設置為false來關閉鎖定。值得注意的是,使用 Aspose.Slides for Java 鎖定的形狀無法使用任何其他庫解鎖。
以下代碼示例演示如何使用 Java 解鎖 PPTX 文件中的形狀。
try {
//Load presentation file
Presentation pTemplate = new Presentation("presentation.pptx");
//ISlide object for accessing the slides in the presentation
ISlide slide = pTemplate.getSlides().get_Item(0);
//IShape object for holding temporary shapes
IShape shape;
//Traverse through all the slides in the presentation
for (int slideCount = 0; slideCount < pTemplate.getSlides().size(); slideCount++) {
slide = pTemplate.getSlides().get_Item(slideCount);
//Traverse through all the shapes in the slides
for (int count = 0; count < slide.getShapes().size(); count++) {
shape = slide.getShapes().get_Item(count);
//if shape is auto shape
if (shape instanceof IAutoShape) {
//Type casting to Auto shape and getting auto shape lock
IAutoShape Ashp = (IAutoShape) shape;
IAutoShapeLock AutoShapeLock = (IAutoShapeLock) Ashp.getShapeLock();
//Unlock shape
AutoShapeLock.setPositionLocked(false);
AutoShapeLock.setSelectLocked(false);
AutoShapeLock.setSizeLocked(false);
}
//if shape is group shape
else if (shape instanceof IGroupShape) {
//Type casting to group shape and getting group shape lock
IGroupShape Group = (IGroupShape) shape;
IGroupShapeLock groupShapeLock = (IGroupShapeLock) Group.getShapeLock();
//Unlock shape
groupShapeLock.setGroupingLocked(false);
groupShapeLock.setPositionLocked(false);
groupShapeLock.setSelectLocked(false);
groupShapeLock.setSizeLocked(false);
}
//if shape is a connector
else if (shape instanceof IConnector) {
//Type casting to connector shape and getting connector shape lock
IConnector Conn = (IConnector) shape;
IConnectorLock ConnLock = Conn.getShapeLock();
//Unlock shape
ConnLock.setPositionMove(false);
ConnLock.setSelectLocked(false);
ConnLock.setSizeLocked(false);
}
//if shape is picture frame
else if (shape instanceof IPictureFrame) {
//Type casting to pitcture frame shape and getting picture frame shape lock
IPictureFrame Pic = (IPictureFrame) shape;
IPictureFrameLock PicLock = (IPictureFrameLock) Pic.getShapeLock();
//Unlock shape
PicLock.setPositionLocked(false);
PicLock.setSelectLocked(false);
PicLock.setSizeLocked(false);
}
}
}
//Save the presentation file
pTemplate.save("ProtectedSample.pptx", SaveFormat.Pptx);
} catch (Exception e) {
}
以上便是如何在java中鎖定PPT形狀 ,如您還有關于產品相關方面的疑問,可以繼續瀏覽本系列其他內容,也歡迎您加入我們的交流群發表您遇到的問題。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn