本文展示如何使用Spire.Presentation for Java对PowerPoint表格的文字设置水平或垂直对齐方式。
import com.spire.presentation.*;
public class AlignTextInTableCell {
    public static void main(String[] args) throws Exception {
        //创建PowerPoint文档
        Presentation presentation = new Presentation();
        //添加表格
        Double[] widths = new Double[]{100d, 200d, 100d, 100d};
        Double[] heights = new Double[]{30d, 70d, 70d};
        ITable table = presentation.getSlides().get(0).getShapes().appendTable(30,80, widths, heights);
        table.setStylePreset(TableStylePreset.NONE);
        //在第一行的单元格设置水平对齐方式
        table.get(0, 0).getTextFrame().setText("靠左");
        table.get(0, 0).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.LEFT);
        table.get(1, 0).getTextFrame().setText("水平居中");
        table.get(1, 0).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.CENTER);
        table.get(2, 0).getTextFrame().setText("靠右");
        table.get(2, 0).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.RIGHT);
        table.get(3, 0).getTextFrame().setText("两端对齐");
        table.get(3, 0).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.JUSTIFY);
        //在第二行的单元格设置垂直对齐方式
        table.get(0, 1).getTextFrame().setText("居上");
        table.get(0, 1).setTextAnchorType(TextAnchorType.TOP);
        table.get(1, 1).getTextFrame().setText("垂直居中");
        table.get(1, 1).setTextAnchorType(TextAnchorType.CENTER);
        table.get(2, 1).getTextFrame().setText("居下");
        table.get(2, 1).setTextAnchorType(TextAnchorType.BOTTOM);
        //在第三行同时设置水平和垂直对齐方式
        table.get(0, 2).getTextFrame().setText("左上");
        table.get(0, 2).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.LEFT);
        table.get(0, 2).setTextAnchorType(TextAnchorType.TOP);
        table.get(1, 2).getTextFrame().setText("居中");
        table.get(1, 2).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.CENTER);
        table.get(1, 2).setTextAnchorType(TextAnchorType.CENTER);
        table.get(2, 2).getTextFrame().setText("右下");
        table.get(2, 2).getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.RIGHT);
        table.get(2, 2).setTextAnchorType(TextAnchorType.BOTTOM);
        //保存文档
        presentation.saveToFile("TableAlignment.pptx", FileFormat.PPTX_2013);
        presentation.dispose();
    }
}
 



 
					



