- public class RepDocTemplate {
- // 默认没有license,会有水印文字
- private boolean isLicense = false;
- // 初始化日志
- private static final Logger log = LoggerFactory
- .getLogger(RepDocTemplate.class);
- /**
- * 私有构造,用户初始化License
- */
- public RepDocTemplate() {
- InputStream is = RepDocTemplate.class.getClassLoader()
- .getResourceAsStream("license.xml");
- License aposeLic = new License();
- try {
- aposeLic.setLicense(is);
- isLicense = true;
- } catch (Exception e) {
- log.error("word模板破解失败!", e);
- }
- }
- /**
- * 替换内容的主要操作
- *
- * @param input
- * @param output
- * @param datas
- */
- public void replaceDocTem(String input, String output,
- HashMap<String, Object> datas) {
- if (isLicense) {
- try {
- Document doc = new Document(input);
- // 遍历要替换的内容
- Iterator<String> keys = datas.keySet().iterator();
- while (keys.hasNext()) {
- String key = keys.next();
- String value = String.valueOf(datas.get(key));
- // 对显示值得修改
- if (Tool.isNull(value)) {
- value = "";
- }
- value = value.replace("\r\n", " ");
- // 要求替换的内容是完全匹配时的替换
- doc.getRange().replace("$" + key + "$", value, true, false);
- }
- // 替换保存后的内容
- doc.save(output);
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- }
- }
- }
- }
aspose
猜你喜欢
转载自blog.csdn.net/liu050604/article/details/78785496
今日推荐
周排行