本文介绍如何使用Spire.Presentation for Java设置幻灯片中的表格的对齐方式。
import com.spire.presentation.FileFormat;
import com.spire.presentation.ITable;
import com.spire.presentation.Presentation;
import com.spire.presentation.ShapeAlignmentEnum;
public class AlignTable {
public static void main(String[] args) throws Exception {
//创建Presentation对象
Presentation presentation = new Presentation();
//加载示例文档
presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");
//声明ITable变量
ITable table = null;
//遍历第一个幻灯片中的图形
for (Object shape: presentation.getSlides().get(0).getShapes()
) {
//判断图形是否为ITable对象
if (shape instanceof ITable)
{
//将图形转换为ITable对象
table =(ITable)shape;
}
}
//将表格水平居中
table.setShapeAlignment(ShapeAlignmentEnum.ShapeAlignment.AlignCenter);
//将表格垂直居中
table.setShapeAlignment(ShapeAlignmentEnum.ShapeAlignment.AlignMiddle);
//保存文档
presentation.saveToFile("AlignTable.pptx", FileFormat.PPTX_2013);
}
}