我的课程WriteFile
的方法WriteToFile
将String
写入word文档。
WriteFile data=new WriteFile("C:/test3.doc",true);
data.writeToFile(user.saxeli+" "+user.gvari+" "+user.asaki+" "+user.swori);
如何用粗体和下划线样式将String
写入“test3.doc”?
这是WriteFile类:
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class WriteFile {
private String path;
private boolean append=true;
public WriteFile(String path,boolean append){
this.path=path; this.append=append;
}
public void writeToFile(String text) throws IOException{
FileWriter write=new FileWriter(path,append);
PrintWriter print_line= new PrintWriter(write);
print_line.printf("%s"+"%n", text);
print_line.close();
}
}
答案 0 :(得分:6)
看看Apache POI。该库可以写入Microsoft Word文件并使用粗体和下划线(字体)样式。
答案 1 :(得分:1)
你可以参考这个::
XWPFParagraph paragraphOne = document.createParagraph();
XWPFRun paragraphOneRunOne = paragraphOne.createRun();
paragraphOneRunOne.setItalic(true);
paragraphOneRunOne.setText(text);
点击此链接:: http://tkgospodinov.com/writing-microsoft-word-documents-in-java-with-apache-poi/