1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| package com.hxkj.server.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hxkj.server.common.core.result.Result; import com.hxkj.server.common.core.utils.TddRedisUtil; import com.hxkj.server.entity.GeneraterWordData; import com.hxkj.server.service.GeneraterWordService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;
/** * 要尊重编程 * * @Author: 庞欢腾 * @Date: 2022/5/13 * @Description: data-server */ @Api(tags = "生成word文档接口") @RestController @RequestMapping("/generater-word") public class GeneraterWordController {
GeneraterWordService generaterWordService;
@Autowired public void setGeneraterWordService(GeneraterWordService generaterWordService) { this.generaterWordService = generaterWordService; }
@ApiOperation(value = "生成word文档接口", notes = "生成word文档接口", response = Result.class, httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "txt_data", value = "文本数据", paramType = "query", dataType = "Map", required = true), @ApiImplicitParam(name = "image_data", value = "图像数据", paramType = "query", dataType = "Map", required = true), @ApiImplicitParam(name = "inTemplatePathName", value = "输入模板地址名称", paramType = "query", dataType = "String", required = true), @ApiImplicitParam(name = "outputPathName", value = "输出word文件地址名称", paramType = "query", dataType = "String", required = true) }) @ApiOperationSupport(author = "庞欢腾") @PostMapping("/generaterWord") public Result<String> generaterWord(@RequestBody GeneraterWordData generaterWordData) { return generaterWordService.baseGeneraterWord(generaterWordData); }
@ApiOperation(value = "一个非常灵活随意的生成word文档接口", notes = "生成word文档接口,当使用的模板不是一个的时候,使用这个接口。" + "模板名称参数是一个用逗号分割的任意个模板名称", response = Result.class, httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "txt_data", value = "文本数据", paramType = "query", dataType = "Map", required = true), @ApiImplicitParam(name = "image_data", value = "图像数据", paramType = "query", dataType = "Map", required = true), @ApiImplicitParam(name = "inTemplatePathName", value = "输入模板地址名称,参数是一个用逗号分割的任意个模板名称", paramType = "query", dataType = "String", required = true), @ApiImplicitParam(name = "outputPathName", value = "输出word文件地址名称", paramType = "query", dataType = "String", required = true) }) @ApiOperationSupport(author = "庞欢腾") @PostMapping("/generaterWordNimble") public Result<String> generaterWordNimble(@RequestBody GeneraterWordData generaterWordData) { return generaterWordService.baseGeneraterWordNimble(generaterWordData); }
@ApiOperation(value = "通用文档生成接口", notes = "2022年08月04日 生成word文档接口,当使用的模板不是一个的时候,使用这个接口。" + "模板名称参数是一个用逗号分割的任意个模板名称", response = Result.class, httpMethod = "POST") @ApiOperationSupport(author = "庞欢腾") @PostMapping("/makeWordNimble") public Result<String> makeWordNimble(@RequestBody GeneraterWordData generaterWordData) { return generaterWordService.baseMakeWordNimble(generaterWordData); }
@ApiOperation(value = "通用文档生成接口", notes = "2022-08-17 生成word文档接口,当使用的模板不是一个的时候,使用这个接口。" + "模板名称参数是一个用逗号分割的任意个模板名称,(第二代接口,当图片数据不在同一个目录的时候,图片名称参数前面要指定子目录,例如:tdd配置的路径+子目录/图片名称.png)", response = Result.class, httpMethod = "POST") @ApiOperationSupport(author = "庞欢腾") @PostMapping("/makeWordNimblePng") public Result<String> makeWordNimblePng(@RequestBody GeneraterWordData generaterWordData) { return generaterWordService.baseMakeWordNimblePng(generaterWordData); }
/** * 测试用例 */ /*public static void main(String[] args) { GeneraterWord generaterWord = new GeneraterWordImpl(); String inTemplatePathName = "E:\\a工作文件\\郑州\\2022\u200E年\u200E\\精细化平台开发工作\\预警信息制作模板\\开发模板\\郑州市气象台预警模板.doc"; Map<String, String> data = new HashMap<>(); // data.put("name", "郑州"); data.put("td0table0", "31日09时t_31日10时t_31日11时t_31日12时t_31日13时t_31日14时t_31日15时t_31日16时t_31日17时t_31日18时t_31日19时t_31日20时"); data.put("td1table0", "31日09时t_31日10时t_31日11时t_31日12时t_31日13时t_31日14时t_31日15时t_31日16时t_31日17时t_31日18时t_31日19时t_31日20时"); data.put("td2table0", "31日09时t_31日10时t_31日11时t_31日12时t_31日13时t_31日14时t_31日15时t_31日16时t_31日17时t_31日18时t_31日19时t_31日20时");
//加载示例文档 Document document = new Document(); // "C:\\Users\\Administrator\\Desktop\\input.docx" document.loadFromFile(inTemplatePathName); // 文本 // generaterWord.replaceText(data, document);
//表格 generaterWord.replaceTable(data, document);
//保存文档 document.saveToFile("E:\\a工作文件\\郑州\\2022\u200E年\u200E\\精细化平台开发工作\\预警信息制作模板\\开发模板\\ReplaceAllMatchedText.docx", FileFormat.Docx_2013);
}*/
/** * 测试循环生成文档功能 * @param args */ /*public static void main(String[] args) { String root = "D:\\data\\word\\制作文档\\"; String out = root + "生成后的文件.docx"; Map<String, String>[] txt_data = new Map[2]; txt_data[0] = new HashMap<>(); txt_data[0].put("name", "这是第一个文本"); txt_data[1] = new HashMap<>(); txt_data[1].put("name", "这是第二个文本");
Map<String, String>[] image_data = new Map[2]; image_data[0] = new HashMap<>(); image_data[0].put("img2", root + "img1.png"); image_data[1] = new HashMap<>(); image_data[1].put("img2", root + "img3.png");
GeneraterWord generaterWord = new GeneraterWordImpl(); Document document = generaterWord.generaterWord(root + "气象信息快报_近小时降水量2.doc"); generaterWord.loopReplaceWord(txt_data, image_data, document, out);
}*/
}
|