JAVA代码把字符串输入到docx文件中
时间: 2023-04-10 11:00:54 浏览: 233
可以使用Apache POI库来实现将字符串输入到docx文件中。具体实现可以参考以下代码:
```
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
public class JavaToDocx {
public static void main(String[] args) {
String text = "这是要输入到docx文件中的字符串";
try {
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
paragraph.createRun().setText(text);
FileOutputStream out = new FileOutputStream("output.docx");
document.write(out);
out.close();
System.out.println("文件已成功生成!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
阅读全文