您好,想问一下如何设置行距:
最小值 12磅;
单倍行距 1倍;
多倍行距 1.4倍 ;
间距:段前0.5行
这种样式??
Document document = new Document();
document.loadFromFile("Test.docx");
Paragraph paragraph1= document.getSections().get(0).getParagraphs().get(0);
//设置段前间距0.5
paragraph1.getFormat().setBeforeSpacing(0.5f);
paragraph1.getFormat().setAfterAutoSpacing(false);
//设置多倍行距1.4
Paragraph paragraph2=document.getSections().get(0).getParagraphs().get(1);
paragraph2.getFormat().setLineSpacing(16.8f);
//设置单倍行距
Paragraph paragraph3=document.getSections().get(0).getParagraphs().get(2);
paragraph3.getFormat().setLineSpacing(12f);
//设置最小值12
Paragraph paragraph4=document.getSections().get(0).getParagraphs().get(3);
paragraph4.getFormat().setLineSpacingRule(LineSpacingRule.At_Least);
paragraph4.getFormat().setLineSpacing(12);
//保存文档
document.saveToFile("setLineSpacing.docx", FileFormat.Docx_2013);
Document document = new Document();
document.loadFromFile("Test.docx");
Paragraph paragraph1= document.getSections().get(0).getParagraphs().get(0);
//将point换算为cm
PdfUnitConvertor unitConvertor = new PdfUnitConvertor();
float valueInPixel = unitConvertor.convertUnits(2, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
//设置段落悬挂2cm
paragraph1.getFormat().setFirstLineIndent(-valueInPixel);
paragraph1.getFormat().setLeftIndent(valueInPixel);
//保存文档
document.saveToFile("outPut.docx", FileFormat.Docx_2013);
Document document = new Document();
document.loadFromFile("data/fixText.docx");
Paragraph paragraph1= document.getSections().get(0).getParagraphs().get(1);
//设置段前间距、段后间距
paragraph1.getFormat().setBeforeSpacing(3f);
paragraph1.getFormat().setAfterSpacing(3f);
//保存文档
document.saveToFile("output/result.docx", FileFormat.Docx_2013);