java实现查询Word是否包含批注和修订内容

java实现查询Word是否包含批注和修订内容

1.业务需求发送邮件前确认附件word内容是否包含批注和修订内容如果包含不可发送邮件
2.前端代码如下
/获取发送邮件的信用评价报告word是否包含批注修订内容/

function findEnterpriseReport(post_Param,callback){
	$.ajax({
		type: "post",
		url: baseURL + "sendmail/getEnterpriseReport",
		dataType: "json",
		contentType: "application/json",
		data: JSON.stringify(post_Param),
		success: function(r){
			if(r.code === 1){
				callback(true);
			}else if(r.code === 0){
				callback(false);
			}
		},error: function(m){
			callback(false);
		}
	});
}

3.后端java代码如下

/**
	 * 获取选定项目的发送评级信用报告进行校验
	 * qimeng.zhang
	 * 2020-12-03
	 */
	@RequestMapping("/getEnterpriseReport")
	//@RequiresPermissions("sendmail:ProjectListByuser")
	public R getEnterpriseReport(@RequestBody Map<String, Object> params) throws Exception{		
		Map<String,Object> projectFile = sendmailService.getFasongqiyebaogao(params);	
		if(projectFile==null){	
			return R.ok().put("code", 1);
		}else{
		//获取拼接word全路径
	    String urlPath = (String) projectFile.get("url_path"); //远程文件路径
	    //服务器word文件路径
		String remoteFilePath = "http://cn:8888/uploadFiles"+urlPath.substring(0,urlPath.lastIndexOf("/")+1)+URLEncoder.encode(urlPath.substring(urlPath.lastIndexOf("/")+1), "UTF-8");
		//本地存储下载的word文件路径
		String localFilePath = "/usr/local/tomcat/webapps/uploadFiles"+urlPath;
		//从服务器下载文件到本地
		FileUtil.downloadFile(remoteFilePath,localFilePath);
		//加载测试文档
	    Document doc = new Document();
	    doc.loadFromFile(localFilePath);
	    //判断是否有修订
	    if(doc.hasChanges()){
	    //校验之后删除word文件夹 
	    File  file = new File("/usr/local/tomcat/webapps/uploadFiles");
	    //调用删除方法
	    delFiles(file);
	    return R.ok().put("code", 1);
	     }
	    //遍历所有批注
	     for(int i = 0;i< doc.getComments().getCount();i++){
		    Comment comment = doc.getComments().get(i);
		    //遍历所有批注中的段落
		         for(int j= 0;j < comment.getBody().getParagraphs().getCount();j++) {
		             Paragraph paragraph = comment.getBody().getParagraphs().get(j);
		                //遍历段落中的对象
		                for (Object object : paragraph.getChildObjects()) {
		                    //读取文本
		                    if (object instanceof TextRange) {
		                	    //校验之后删除word文件夹 
		                	    File  file = new File("/usr/local/tomcat/webapps/uploadFiles");
		                	    //调用删除方法
		                	    delFiles(file);
		                        return R.ok().put("code", 1);
		                    }
		                }
		            }
		        }
	        //校验之后删除word文件夹 
 	        File  file = new File("/usr/local/tomcat/webapps/uploadFiles");
	    	//调用删除方法
	    	delFiles(file);
		   }
	  return R.ok();
	}
	/**
	 * 删除校验之后的信用评价报告
	 * qimeng.zhang
	 * 2020-12-03
     * 递归删除
     * 删除某个目录及目录下的所有子目录和文件
     * @param file 文件或目录
     * @return 删除结果
     */
    public static boolean delFiles(File file){
	    boolean result = false;
        //目录
        if(file.isDirectory()){
            File[] childrenFiles = file.listFiles();
            for (File childFile:childrenFiles){
                result = delFiles(childFile);
                if(!result){
                    return result;
                }
            }
        }
        //删除 文件、空目录
        result = file.delete();
        return result;
    }

4.java操作word参考地址
5.如果觉得对您有帮助请帮忙点点赞…谢谢

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值