java各字体大小表,如何使用docx4j在文档中设置字体大小和字体系列

FileReader fr=new FileReader("E://HtmlToDoc//LETTER.html" );

BufferedReader br=new BufferedReader(fr);

while( (s=br.readLine())!= null ){

html=html+s;}

html="

"+html.substring(html.indexOf(""));

/************************ Setting Page Size **********************************/

Docx4jProperties.getProperties().setProperty("docx4j.PageSize", "B4JIS");

String papersize= Docx4jProperties.getProperties().getProperty("docx4j.PageSize", "B4JIS");

String landscapeString = Docx4jProperties.getProperties().getProperty("docx4j.PageOrientationLandscape", "true");

boolean landscape= Boolean.parseBoolean(landscapeString);

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(PageSizePaper.valueOf(papersize), landscape);

AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/hw.html"));

afiPart.setBinaryData(html.getBytes());

//afiPart.setBinaryData(fileContent);

afiPart.setContentType(new ContentType("text/html"));

Relationship altChunkRel = wordMLPackage.getMainDocumentPart().addTargetPart(afiPart);

// .. the bit in document body

CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();

ac.setId(altChunkRel.getId() );

wordMLPackage.getMainDocumentPart().addObject(ac);

// .. content type

wordMLPackage.getContentTypeManager().addDefaultContentType("html", "text/html");

wordMLPackage.save(new java.io.File("E://HtmlToDoc//" + "test.docx"));

This is my code converts from HTML to Word document. How to set font size and font family for this word document.

解决方案

You're pulling HTML content in to a Word document as a collection of AltChunk instances, which means the HTML exists in the docx 'bundle' as separate file, and not as part of the flow of the actual Word document.

If you want to manipulate the imported content as native MS Word content, you need to import the source XHTML instead. This means that docx4j takes the mark-up and (some) related styles, converting them into the various constituent parts of a docx file (for example, table, text, run and paragraph elements). Once you have content imported in that way, you can style it as you would any other docx entities.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值