在word文档中,段落缩进包括:左缩进,右缩进,首行缩进和悬挂缩进。本文将详细描述如何使用spire.doc设置word文档段落缩进样式。
c#
//创建一个document实例并加载示例文档
document doc = new document();
doc.loadfromfile("sample.docx", fileformat.docx2010);
//获取第一个section
section section = doc.sections[0];
//获取第一段并将缩进格式设为首行缩进
paragraph para= section.paragraphs[0];
para.format.firstlineindent = 30f;
//将缩进格式设为左缩进
paragraph para2 = section.paragraphs[2];
para2.format.leftindent = 100f;
//将缩进格式设为右缩进
paragraph para3 = section.paragraphs[4];
para3.format.rightindent = 80f;
//将缩进格式设为悬挂缩进
paragraph para4 = section.paragraphs[6];
para4.format.firstlineindent= -30f;
//保存文档
doc.savetofile("indent.docx", fileformat.docx);
vb.net
'创建一个document实例并加载示例文档
dim doc as document = new document
doc.loadfromfile("sample.docx", fileformat.docx2010)
'获取第一个section
dim section as section = doc.sections(0)
'获取第一段并将缩进格式设为首行缩进
dim para as paragraph = section.paragraphs(0)
para.format.firstlineindent = 30!
'将缩进格式设为左缩进
dim para2 as paragraph = section.paragraphs(2)
para2.format.leftindent = 100!
'将缩进格式设为右缩进
dim para3 as paragraph = section.paragraphs(4)
para3.format.rightindent = 80!
'将缩进格式设为悬挂缩进
dim para4 as paragraph = section.paragraphs(6)
para4.format.firstlineindent = -30!
'保存文档
doc.savetofile("indent.docx", fileformat.docx)