目前有个富文本导出Word的需求,图文表格为富文本主要内容,有没有什么好的工具,开发语音Java
Free Spire.Doc for Java库有一个Paragraph.appendRTF方法可以导出富文本到Word,jar包可以在这里下载或者通过下面的Maven依赖安装
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId> e-iceblue </groupId>
<artifactId>Spire.doc.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>
导出富文本:
import com.spire.doc.*;
import com.spire.doc.documents.*;
public class insertRtfStringToDoc {
public static void main(String[] args) {
//Create Word document.
Document document = new Document();
//Add a new section.
Section section = document.addSection();
//Add a paragraph to the section.
Paragraph para = section.addParagraph();
//Declare a String variable to store the Rtf string.
String rtfString = "{\\rtf1\\ansi\\deff0 {\\fonttbl {\\f0 hakuyoxingshu7000;}}\\f0\\fs28 Hello, World}";
// Append Rtf string to paragraph.
para.appendRTF(rtfString);
String result = "output/insertRtfStringToDoc.docx";
// Save to file.
document.saveToFile(result, FileFormat.Docx);
}
}