java 填写word_java向word写入数据

该段代码展示了如何使用Java的XWPFDocument类来创建并填充Word文档。方法`writerErrorFileContent`接受文件路径、内容列表和文件类型作为参数,根据文件类型在文档中写入相应的错误详细信息。它首先创建文档,然后定义段落样式,如居中、加粗和字体大小,并根据文件类型写入不同段落标题。接着,遍历内容列表并逐条插入,最后保存并关闭文件流。
摘要由CSDN通过智能技术生成

private static String fileDir = "/home/xdja/conf/edums_js/";private static String errorWordFilePath = "importWordErrorDetails.doc";private static String errorExcelFilePath = "importExcelErrorDetails.doc";/*** 写导入题库错误文件类容

*@paramfileDir 文件路径

*@paramfilePath 文件路径

*@paramcontent 内容

*@paramtype 文件类型 1---excel 2 word;

*@authorniugang*/

private void writerErrorFileContent(String fileDir, String filePath, Listcontent, String type) {

XWPFDocument document= newXWPFDocument();

OutputStream stream= null;

BufferedOutputStream bufferStream= null;try{

File dir= newFile(fileDir);if (!dir.exists()) {

dir.mkdirs();

}

stream= new FileOutputStream(new File(fileDir+filePath));

bufferStream= new BufferedOutputStream(stream, 1024);//创建一个段落

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值