急java中用XWPFParagraph来写内容到word怎么设置行间距啊?比如设置为1.5倍行间距

急java中用XWPFParagraph来写内容到word怎么设置行间距啊?比如设置为1.5倍行间距,第1张

paragraphsetSpacingBetween(18, LineSpacingRuleEXACT);
这里面的18指的是磅值,必须是正整数,LineSpacingRuleEXACT指的是指定值
LineSpacingRule这个枚举类还有两个枚举值,AUTO和AT_LEAST 其中AUTO表示自动(就是单倍行距)AT_LEAST就是最小值,可以通过自定义添加其他规则(我不会)
如果想省事儿,就直接使用paragraphsetSpacingLineRule(LineSpacingRuleAUTO);
不使用第一行提供的方法即可,我也是刚接触不久,希望能帮到你

NPOI 20就可以了。
引用using NPOIXWPFUserModel;
XWPFDocument doc = new XWPFDocument();
docCreateParagraph();
FileStream sw = FileOpenWrite("blankdocx");
docWrite(sw);
swClose();
追加一句,刚才是生成了一个文件,再用流的方式,提示客户端下载,即可
/// <summary>
/// d出提示框,提示用户是否下载保存到本地\
/// </summary>
/// <param name="strFileName">文件路径</param>
public static string openWindowExport(string strFileName)
{
string strReutrn = "";
try
{
FileInfo DownloadFile = new FileInfo(strFileName);
SystemWeb>写
public static void main(String args[])
throws Exception
{
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p1 = doccreateParagraph();
p1setAlignment(ParagraphAlignmentCENTER);
p1setBorderBottom(BordersDOUBLE);
p1setBorderTop(BordersDOUBLE);
p1setBorderRight(BordersDOUBLE);
p1setBorderLeft(BordersDOUBLE);
p1setBorderBetween(BordersSINGLE);
p1setVerticalAlignment(TextAlignmentTOP);
XWPFRun r1 = p1createRun();
r1setBold(true);
r1setText("The quick brown fox");
r1setBold(true);
r1setFontFamily("Courier");
r1setUnderline(UnderlinePatternsDOT_DOT_DASH);
r1setTextPosition(100);
XWPFParagraph p2 = doccreateParagraph();
p2setAlignment(ParagraphAlignmentRIGHT);
p2setBorderBottom(BordersDOUBLE);
p2setBorderTop(BordersDOUBLE);
p2setBorderRight(BordersDOUBLE);
p2setBorderLeft(BordersDOUBLE);
p2setBorderBetween(BordersSINGLE);
XWPFRun r2 = p2createRun();
r2setText("jumped over the lazy dog");
r2setStrike(true);
r2setFontSize(20);
XWPFRun r3 = p2createRun();
r3setText("and went away");
r3setStrike(true);
r3setFontSize(20);
r3setSubscript(VerticalAlignSUPERSCRIPT);
XWPFParagraph p3 = doccreateParagraph();
p3setWordWrap(true);
p3setPageBreak(true);
p3setAlignment(ParagraphAlignmentBOTH);
p3setSpacingLineRule(LineSpacingRuleEXACT);
p3setIndentationFirstLine(600);
XWPFRun r4 = p3createRun();
r4setTextPosition(20);
r4setText("To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them To die: to sleep; ");
r4addBreak(BreakTypePAGE);
r4setText("No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd To die, to sleep; To sleep: perchance to dream: ay, there's the rub; ");
r4setItalic(true);
XWPFRun r5 = p3createRun();
r5setTextPosition(-10);
r5setText("For in that sleep of death what dreams may come");
r5addCarriageReturn();
r5setText("When we have shuffled off this mortal coil,Must give us pause: there's the respectThat makes calamity of so long life;");
r5addBreak();
r5setText("For who would bear the whips and scorns of time,The oppressor's wrong, the proud man's contumely,");
r5addBreak(BreakClearALL);
r5setText("The pangs of despised love, the law's delay,The insolence of office and the spurns");
FileOutputStream out = new FileOutputStream("simpledocx");
docwrite(out);
outclose();
}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/13453278.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-09
下一篇 2023-08-09

发表评论

登录后才能评论

评论列表(0条)

保存