在word文档中,段落缩进包括:左缩进,右缩进,首行缩进和悬挂缩进。该文将介绍如何使用Spire.Doc在Java应用程序中,设置word文档段落缩进样式。
import com.spire.doc.*;
import com.spire.doc.documents.*;
public class WordParaIndent{
public static void main(String[] args) {
//加载文档
Document document= new Document();
document.loadFromFile("Sample.docx");
//获取第一个section
Section section = document.getSections().get(0);
//获取第二段并将缩进格式设为左缩进
Paragraph para1 = section.getParagraphs().get(1);
para1.getFormat().setLeftIndent(30);
//获取第三段并将缩进格式设为右缩进
Paragraph para2 = section.getParagraphs().get(2);
para2.getFormat().setRightIndent(40);
//获取第四段并将缩进格式设为首行缩进
Paragraph para3 = section.getParagraphs().get(3);
para3.getFormat().setFirstLineIndent(40);
//获取第五段并将缩进格式设为悬挂缩进
Paragraph para4 = section.getParagraphs().get(4);
para4.getFormat().setFirstLineIndent(-40);
document.saveToFile("out/result.docx", FileFormat.Docx_2013);
}
}
效果图: