本文介绍如何使用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);
}
}