import com.spire.doc.*;
import com.spire.doc.documents.HorizontalAlignment;
public class ParagraphIndents {
public static void main(String[]args){
//加载测试文档
Document doc = new Document();
doc.loadFromFile("test.docx");
//获取段落并设置段落缩进方式及缩进值
Section sec = doc.getSections().get(0);
sec.getParagraphs().get(0).getFormat().setLeftIndent(30f);//左缩进
sec.getParagraphs().get(1).getFormat().setRightIndent(30f);//右缩进
sec.getParagraphs().get(2).getFormat().setFirstLineIndent(30f);//首行缩进
sec.getParagraphs().get(3).getFormat().setFirstLineIndent(-30f);//悬挂缩进
//获取段落,并设置段落对齐方式
sec.getParagraphs().get(5).getFormat().setHorizontalAlignment(HorizontalAlignment.Left);//左对齐
sec.getParagraphs().get(6).getFormat().setHorizontalAlignment(HorizontalAlignment.Right);//右对齐
sec.getParagraphs().get(7).getFormat().setHorizontalAlignment(HorizontalAlignment.Center);//居中对齐
sec.getParagraphs().get(8).getFormat().setHorizontalAlignment(HorizontalAlignment.Justify);//两端对齐
sec.getParagraphs().get(9).getFormat().setHorizontalAlignment(HorizontalAlignment.Distribute);//分散对齐
//保存文档
doc.saveToFile("result.docx");
doc.dispose();
}
}