POI列子:替换文本框值

适用于2007版本的word,最开始是因为项目需要就去找找POI打印的列子,结果文本框替换值有点不知所措,试了一些方法。通过POI的api源码找到点头绪。

直接切代码,不擅长描述:

有些是重复,没有写成公用方法,因为是以前写的

============================================查询值替换并生成zip包下载=========================================

package com.buss.system.print;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
import org.apache.xmlbeans.FilterXmlObject;
import org.jeecgframework.core.util.DateUtils;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.web.system.util.DictUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.buss.approve.common.entity.TBusAttachmentEntity;
import com.buss.approve.common.entity.TCommonFormEntity;
import com.buss.approve.form.entity.TSubFormMfEntity;
import com.buss.approve.form.entity.TSubFormSocialEntity;
import com.buss.org.maintain.entity.main.TBussOrgEntity;
import com.buss.org.maintain.entity.mf.TBussOrgMfEntity;
import com.buss.org.maintain.entity.st.TBussOrgStEntity;
import com.buss.org.maintain.entity.yl.TBussOrgYlEntity;
import com.buss.system.print.hengyunsoft.poi.PremitPrintTemplate;
import com.buss.util.TemplateUtil;

@SuppressWarnings("all")
@Scope("prototype")
@Controller
@RequestMapping("/permitPrint")
public class PermitPrint {

@Autowired
private SystemService systemService;

@RequestMapping(params = "permit", method = RequestMethod.GET)
public void permit(TBussOrgEntity tBussOrg, TBussOrgYlEntity tBussYl,TBussOrgMfEntity tBussMf,
TBussOrgStEntity tBussSt, HttpServletRequest req, HttpServletResponse res, String id)
throws Exception {

System.out.println(id);
if (StringUtil.isNotEmpty(id)) {
List<TBussOrgEntity> tBussOrgList = systemService.findByProperty(
TBussOrgEntity.class, "id", id);
tBussOrg = tBussOrgList.get(0);
String name = tBussOrg.getName();// 机构名称
String legalPer = tBussOrg.getLegalPerson();// 机构法人
String detailAdd = tBussOrg.getDetailAddress();// 详细地址
String perCode = tBussOrg.getOrglicense();// 许可证编码
Date obDate = tBussOrg.getObtainDate();// 有效开始日期
Date exDate = tBussOrg.getExpiringDate(); // 无效日期
Date regDate= tBussOrg.getRegistrationDate();//机构登记日期
String addCode = tBussOrg.getProvinceId();// 地址编码
String phone = tBussOrg.getPhone();// 电话号码
if (obDate == null) {
obDate = new Date();
}
if (exDate == null) {
exDate = new Date();
}
if (regDate == null) {
regDate = new Date();
}

SimpleDateFormat sdf = new SimpleDateFormat("yyyy MM dd");
String obDateString = sdf.format(obDate);//证件开始日期
String exDateString = sdf.format(exDate);//证件无效日期
String reDateString = sdf.format(regDate);

String service = tBussOrg.getBusinessRange();// 业务范围
/**
* 养老
*/
List<TBussOrgYlEntity> tBussYList = systemService.findByProperty(
TBussOrgYlEntity.class, "bussOrgId", id);
/**
* 民非
*/
List<TBussOrgMfEntity> tBussMfist= systemService.findByProperty(
TBussOrgMfEntity.class, "bussOrgId", id);
/**
* 社团
*/
List<TBussOrgStEntity> tBussStList=systemService.findByProperty(
TBussOrgStEntity.class, "bussOrgId", id);

/**
* 民非模板打印
*/
if (tBussOrgList.size() > 0&&tBussMfist.size()>0) {
tBussMf = tBussMfist.get(0);
String total= tBussMf.getTotalFunding().toString();
String manager= tBussMf.getBusinessSupervisor();//业务管理单位
Date obDatest = tBussOrg.getObtainDate();// 有效开始日期
Date exDatest = tBussOrg.getExpiringDate(); // 无效日期
String regUnit = tBussOrg.getRegistrationDepart();
String orgCode = perCode;
String orgName = name;
String businessRange = service;
String address = detailAdd;
String leader = legalPer;
String totalFunding = total;
String businessSupervisor = manager;
if (obDatest == null) {
obDatest = new Date();
}
if (exDatest == null) {
exDatest = new Date();
}

SimpleDateFormat sdfst = new SimpleDateFormat("yyyy MM dd");
String obDateS = sdfst.format(obDatest);//证件开始日期
String exDates = sdfst.format(exDatest);//证件无效日期
Map<String, Object> tags =new HashMap<String, Object>();
if(StringUtil.isEmpty(regUnit)){
regUnit = "无登记主管单位";
}else{
regUnit = DictUtil.getOneDictDesc("MG_ORG_REG", regUnit);
}

if(StringUtil.isEmpty(orgCode)){
orgCode = "无统一社会信用代码";
}

tags.put("orgCode", orgCode);//许可证号
//tags.put("Area", activityArea);//活动区域
tags.put("orgName",orgName);//机构名称
tags.put("businessRange", businessRange);//业务范围
tags.put("address", address);//详细地址
tags.put("leader", leader);//法人
tags.put("totalFunding",totalFunding );//注册资金
tags.put("businessSuper", businessSupervisor);//业务主管单位
tags.put("Date", obDateS);//证件开始日期
tags.put("registrationUnit", regUnit); //登记主管单位
tags.put("validDate", obDateS +" "+exDates );

String outFile = orgName+"证书打印.zip";
String strPath=req.getRealPath("upload/print/mf");
String [] files={"新证书模本(正本).docx","新证副本.docx"};
TemplateUtil.genericHttpFile(res, outFile, strPath, files, tags);
}
/**
* 社团模板打印
*/
if (tBussOrgList.size()>0&& tBussStList.size()>0) {
List<TBussOrgEntity> tBussOrgListst = systemService.findByProperty(
TBussOrgEntity.class, "id", id);
tBussOrg = tBussOrgListst.get(0);
tBussSt=tBussStList.get(0);
Date obDatest = tBussOrg.getObtainDate();// 有效开始日期
Date exDatest = tBussOrg.getExpiringDate(); // 无效日期
if (obDatest == null) {
obDatest = new Date();
}
if (exDatest == null) {
exDatest = new Date();
}
SimpleDateFormat sdfst = new SimpleDateFormat("yyyy MM dd");
String obDateS = sdfst.format(obDatest);//证件开始日期
String exDates = sdfst.format(exDatest);//证件无效日期
String area= tBussSt.getActivityArea();
String manager =tBussSt.getBusinessSupervisor();
String regUnit = tBussOrg.getRegistrationDepart();
String money =tBussSt.getTotalFunding().toString();
Map<String, Object> tags =new HashMap<String, Object>();
res.setContentType("application/x-download");
/**
* 文件声明头
*/
res.setHeader( "Content-Disposition", "attachment;filename=" + new String( (name+"证书打印.zip").getBytes("gbk"), "ISO8859-1" ));
ZipOutputStream zos = new ZipOutputStream(res.getOutputStream());
zos.setEncoding("GBK");
if(StringUtil.isEmpty(regUnit)){
regUnit = "无登记主管单位";
}else{
regUnit = DictUtil.getOneDictDesc("MG_ORG_REG", regUnit);
}
if(StringUtil.isEmpty(perCode)){
perCode = "无统一社会信用代码";
}
tags.put("activityArea", area);//活动区域
tags.put("businessSuper", manager);//业务主管单位
tags.put("orgName",name);//机构名称
tags.put("leader", legalPer);//法人
tags.put("address", detailAdd);//详细地址
tags.put("Date", obDateS);//证件开始日期
tags.put("printDate", obDateS);//证件开始日期
tags.put("orgCode", perCode);//许可证号
tags.put("totalFunding",money );//注册资金
tags.put("validDate", obDateS +" "+exDates );
tags.put("exDate", obDateS);//证件结束日期
tags.put("businessRange", service);//业务范围
tags.put("registrationUnit", regUnit); //登记主管单位

String outFile = name+"许可证打印.zip";
String strPath = req.getRealPath("upload/print/st");
String [] files= {"新证书模本(正本).docx","新证副本.docx"};
TemplateUtil.genericHttpFile(res, outFile, strPath, files, tags);

}

/**
* 养老模板打印
*/
if (tBussOrgList.size() > 0&&tBussYList.size()>0) {
tBussOrg = tBussOrgList.get(0);
tBussYl = tBussYList.get(0);
Map<String, Object> tags = new HashMap<String, Object>();
tags.put("Org", name);
tags.put("Name", legalPer);
tags.put("Addr", detailAdd);
tags.put("Crt", perCode);
tags.put("Num", obDateString + " " + exDateString);
tags.put("Service", service);
tags.put("exDate", exDateString);
tags.put("addCode", addCode);
tags.put("Date", obDateString);
tags.put("phone", phone);
if (tBussYl.getBedNum()==null) {
String bedNum=" ";
tags.put("bedNu", bedNum);
}else if(tBussYl.getBedNum()!=null){
String bedNum = tBussYl.getBedNum().toString();// 机构床数
tags.put("bedNu", bedNum);
}
String outFile = name+"许可证打印.zip";
String strPath = req.getRealPath("upload/print/yl");
String [] files= {"许可证模板.docx","许可证书第一页副本.docx","许可证书第二页副本.docx"};
TemplateUtil.genericHttpFile(res, outFile, strPath, files, tags);
}
}
}
@RequestMapping(params = "printSt", method = RequestMethod.GET)
public void printSt(String instanceID,HttpServletRequest req, HttpServletResponse res) throws IOException{
List<TSubFormSocialEntity> subFormSocialEntityList = systemService.findByProperty(TSubFormSocialEntity.class, "instanceId", instanceID);
List<TCommonFormEntity> commonFormEntityList = systemService.findByProperty(TCommonFormEntity.class, "instanceId", instanceID);

if(commonFormEntityList.size()>0 && subFormSocialEntityList.size()>0){
TSubFormSocialEntity subFormSocialEntity = subFormSocialEntityList.get(0);
TCommonFormEntity commonFormEntity = commonFormEntityList.get(0);

String orgName = commonFormEntity.getOrgName(); //名称
String orgCode = commonFormEntity.getOrgCode(); //统一社会信用代码
String address = subFormSocialEntity.getAddress() ; //住所
String actuvityArea = subFormSocialEntity.getActivityArea(); //活动区域
String businessRange = subFormSocialEntity.getBusinessRange(); //业务范围
String leader = subFormSocialEntity.getLeader();// 法人代表
Integer totalFunding = subFormSocialEntity.getTotalFunding(); //注册资金
String businessSupervisor = subFormSocialEntity.getBusinessSupervisor() ;//业务主管单位
String regDepart = commonFormEntity.getRegistrationDepart() ; //发证机关
String regUnit = commonFormEntity.getRegistrationDepart();
if(StringUtil.isEmpty(regUnit)){
regUnit = "无登记主管单位";
}else{
regUnit = DictUtil.getOneDictDesc("MG_ORG_REG", regUnit);
}
if(StringUtil.isEmpty(orgCode)){
orgCode = "无统一社会信用代码";
}
Date obDatest = null;// 有效开始日期
Date exDatest = null; // 无效日期
if (obDatest == null) {
obDatest = new Date();
}
if (exDatest == null) {
exDatest = new Date();
}
SimpleDateFormat sdfst = new SimpleDateFormat("yyyy MM dd");
String obDateS = sdfst.format(obDatest);//证件开始日期
String exDates = sdfst.format(exDatest);//证件无效日期
Map<String, Object> tags =new HashMap<String, Object>();
tags.put("activityArea", actuvityArea);//活动区域
tags.put("businessSuper", businessSupervisor);//业务主管单位
tags.put("orgName",orgName);//机构名称
tags.put("leader", leader);//法人
tags.put("address", address);//详细地址
tags.put("Date", obDateS);//证件开始日期
tags.put("printDate", obDateS);//证件开始日期
tags.put("orgCode", orgCode);//许可证号
tags.put("totalFunding",totalFunding );//注册资金
tags.put("validDate", obDateS +" "+exDates );
tags.put("exDate", obDateS);//证件结束日期
tags.put("businessRange", businessRange);//业务范围
tags.put("registrationUnit", regUnit); //登记主管单位

//生成下载文件
String outFile =orgName+"证书打印.zip";
String strPath=req.getRealPath("upload/print/mf");
String [] files={"新证书模本(正本).docx","新证副本.docx"};
TemplateUtil.genericHttpFile(res, outFile, strPath, files, tags);

}
}
@RequestMapping(params = "printStBztz", method = RequestMethod.GET)
public void printStBztz(String instanceID,HttpServletRequest req, HttpServletResponse res) throws IOException{
List<TCommonFormEntity> commonFormList = systemService.findByProperty(
TCommonFormEntity.class, "instanceId", instanceID);
if(commonFormList.size() > 0){
TCommonFormEntity tCommonFormEntity = commonFormList.get(0);
Map<String, Object> tags =new HashMap<String, Object>();
String orgName = tCommonFormEntity.getOrgName(); //机构名称
String applicant = tCommonFormEntity.getApplicant(); //申请人
String applyDate = tCommonFormEntity.getApplyDate(); //申请人电话
String applyYear = ""; //年
String applyMon = ""; //月
String applyDay = ""; //日
String otherDay = "";
String nowdate = DateUtils.getTimestamp().toString();
if(StringUtil.isNotEmpty(applyDate)){
applyYear = applyDate.substring(0, 4); //年
applyMon = applyDate.substring(5, 7); //月
applyDay = applyDate.substring(8, 10); //日
int other = Integer.parseInt(applyDay);
otherDay = "" + (other+5);
}

tags.put("orgName", orgName);
tags.put("applicant", applicant);
tags.put("applyYear", applyYear);
tags.put("applyMon", applyMon);
tags.put("applyDay", applyDay);
tags.put("otherDay", otherDay);

tags.put("nowYear", nowdate.substring(0, 4));
tags.put("nowMon", nowdate.substring(5, 7));
tags.put("nowDay", nowdate.substring(8, 10));

String outfile = orgName+"补正通知书.docx";
String strPath=req.getRealPath("upload/print/st");
String file = "补正通知书.docx";
TemplateUtil.genericHttpFile(res, outfile,strPath, file, tags);

}

}

@RequestMapping(params = "printStSltz", method = RequestMethod.GET)
public void printStSltz(String instanceID,HttpServletRequest req, HttpServletResponse res) throws IOException{
//List<TBusAttachmentEntity> fileList = new ArrayList<TBusAttachmentEntity>();
List<TCommonFormEntity> commonFormList = systemService.findByProperty(
TCommonFormEntity.class, "instanceId", instanceID);
if(commonFormList.size() > 0){
TCommonFormEntity tCommonFormEntity = commonFormList.get(0);
Map<String, Object> tags =new HashMap<String, Object>();
String orgName = tCommonFormEntity.getOrgName(); //机构名称
String applicant = tCommonFormEntity.getApplicant(); //申请人
String nowdate = DateUtils.getTimestamp().toString();

tags.put("orgName", orgName);
tags.put("applicant", applicant);
tags.put("nowYear", nowdate.substring(0, 4));
tags.put("nowMon", nowdate.substring(5, 7));
tags.put("nowDay", nowdate.substring(8, 10));

String outfile = orgName+"受理通知书.docx";
String strPath=req.getRealPath("upload/print/st");
String file = "受理通知书.docx";
TemplateUtil.genericHttpFile(res, outfile,strPath, file, tags);
}

}
/**
* st受理回执
* @param instanceID
* @param req
* @param res
* @throws IOException
*/
@RequestMapping(params = "printStSlhz", method = RequestMethod.GET)
public void printStSlhz(String instanceID,HttpServletRequest req, HttpServletResponse res) throws IOException{
// List<TSubFormMfEntity> subFormSocialEntityList = systemService.findByProperty(TSubFormMfEntity.class, "instanceId", instanceID);
List<TCommonFormEntity> commonFormEntityList = systemService.findByProperty(TCommonFormEntity.class, "instanceId", instanceID);
if(commonFormEntityList.size()>0 ){
TCommonFormEntity commonFormEntity = commonFormEntityList.get(0);
String bussNo = commonFormEntity.getAcceptNo(); //业务编号
String backBussNo = " "; // 备用业务编号
String applicant = commonFormEntity.getOrgName(); //申请人
String acceptPersonal ="邹星";
String acceptDate = commonFormEntity.getApplyDate(); //受理日期
String contact = commonFormEntity.getApplicantMobile(); //联系电话
String handlePerson = commonFormEntity.getApplicant(); //受理人 //commonFormEntity.getApplicant();//办理人
String phone = " ";//办事人电话
String tel = "15285117979";//办事人手机
String queryAddr = "http://www.gyasc.gov.cn/"; //查询地址
String temp = commonFormEntity.getTitle();
int l = temp.indexOf("】");
temp = temp.substring(2, l);
String appliMatter = temp; //申请事项
String acceptOption ="经初步检查,申请人提交材料齐全,具备申请条件,特给予办理,并递交上级审批,请申请人等候审批结果"; //受理意见
String payStandard= " "; //缴费标准
String alreadyCharge = "0人民币";//现已收费
String promiseDate = " ";//承诺日期
String explain = "按收费标准无需说明"; //说明
String remarks = " ";//备注

String senderSign = " ";//送件人签字
String personalSign = " ";//受理人签字
String printDate = " ";//打印日期
SimpleDateFormat sdfst = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分");
printDate = sdfst.format(new Date());

Map<String, Object> tags =new HashMap<String, Object>();
tags.put("bussNo", bussNo);
tags.put("backBussNo",backBussNo );
tags.put("applican",applicant );
tags.put("acceptPersonal", acceptPersonal);
tags.put("acceptDate", acceptDate);
tags.put("contact",contact );
tags.put("handlePerson", handlePerson);
tags.put("phone", phone);
tags.put("handerTel", tel);
tags.put("queryAddr",queryAddr );
tags.put("appliMatter",appliMatter );
tags.put("acceptOption",acceptOption );
tags.put("payStandard", payStandard);
tags.put("alreadyCharge", alreadyCharge);
tags.put("promiseDate",promiseDate );
tags.put("explain", explain);
tags.put("remarks",remarks);
tags.put("senderSign",senderSign );
tags.put("personalSign",personalSign );
tags.put("printDate",printDate );
String orgName = commonFormEntity.getOrgName();
String outfile = orgName+"受理回执.docx";

String strPath=req.getRealPath("upload/print/st");
String file = "受理模板.docx";
TemplateUtil.genericHttpFile(res, outfile,strPath, file, tags);

}
}
@RequestMapping(params = "printMf", method = RequestMethod.GET)
public void printMf(String instanceID,HttpServletRequest req, HttpServletResponse res) throws IOException{
List<TSubFormMfEntity> subFormSocialEntityList = systemService.findByProperty(TSubFormMfEntity.class, "instanceId", instanceID);
List<TCommonFormEntity> commonFormEntityList = systemService.findByProperty(TCommonFormEntity.class, "instanceId", instanceID);

if(commonFormEntityList.size()>0 && subFormSocialEntityList.size()>0){
TSubFormMfEntity subFormSocialEntity = subFormSocialEntityList.get(0);
TCommonFormEntity commonFormEntity = commonFormEntityList.get(0);

String orgName = commonFormEntity.getOrgName(); //名称
String orgCode =commonFormEntity.getOrgCode(); //统一社会信用代码
String address = subFormSocialEntity.getAddress() ; //住所
String activityArea = subFormSocialEntity.getActivityArea(); //活动区域
String businessRange = subFormSocialEntity.getBusinessRange(); //业务范围
String leader = subFormSocialEntity.getLeader();// 法人代表
Integer totalFunding = subFormSocialEntity.getTotalFunding(); //注册资金
String businessSupervisor = subFormSocialEntity.getBusinessSupervisor() ;//业务主管单位
String regUnit = commonFormEntity.getRegistrationDepart(); //登记主管单位
if(StringUtil.isEmpty(regUnit)){
regUnit = "无登记主管单位";
}else{
regUnit = DictUtil.getOneDictDesc("MG_ORG_REG", regUnit);
}

if(StringUtil.isEmpty(orgCode)){
orgCode = "无统一社会信用代码";
}
Date obDatest = null;// 有效开始日期
Date exDatest = null; // 无效日期
if (obDatest == null) {
obDatest = new Date();
}
if (exDatest == null) {
exDatest = new Date();
}
SimpleDateFormat sdfst = new SimpleDateFormat("yyyy MM dd");
String obDateS = sdfst.format(obDatest);//证件开始日期
String exDates = sdfst.format(exDatest);//证件无效日期
Map<String, Object> tags =new HashMap<String, Object>();
tags.put("orgCode", orgCode);//许可证号
//tags.put("Area", activityArea);//活动区域
tags.put("orgName",orgName);//机构名称
tags.put("businessRange", businessRange);//业务范围
tags.put("address", address);//详细地址
tags.put("leader", leader);//法人
tags.put("totalFunding",totalFunding );//注册资金
tags.put("businessSuper", businessSupervisor);//业务主管单位
tags.put("Date", obDateS);//证件开始日期
tags.put("registrationUnit", regUnit); //登记主管单位
tags.put("validDate", obDateS +" "+exDates );
String outFile = orgName+"证书打印.zip";
String strPath=req.getRealPath("upload/print/mf");
String [] files={"新证书模本(正本).docx","新证副本.docx"};
TemplateUtil.genericHttpFile(res, outFile, strPath, files, tags);
}
}
}

======================================读取方式========================================================

package com.buss.system.print.hengyunsoft.poi;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.jinglin.application.file.DefaultWordTemplate;

public class PremitPrintTemplate extends DefaultWordTemplate {

private Map<String, Object> tags = new HashMap<String, Object>();

public PremitPrintTemplate(InputStream inputStream, Map<String, Object> tags) {
super(inputStream, tags);
this.tags = tags;
}

private void buildWordDoc() {

XWPFDocument document = this.getDocument();

List<XWPFParagraph> paragraphs = document.getParagraphs();
// 遍历得到doc中的段落
for (XWPFParagraph paragraph : paragraphs) {
String text = paragraph.getText();
if (StringUtils.isBlank(text)) {
continue;
}

List<CTR> rList = paragraph.getCTP().getRList();

for (CTR ctr : rList) {
// xml文件对象读取
XmlObject xmlObject = ctr.copy();
// 拿到xml文件节点
Node domNode = xmlObject.getDomNode();
// 拿到子节点List列表对象
NodeList nodeList = domNode.getChildNodes();
// 获取List对象第一条数据
//Node item = nodeList.item(1);
int len = nodeList.getLength();
for (int idx = 0 ; idx < len ; idx++) {
Node item = nodeList.item(idx);
if ("w:pict".equals(item.getNodeName())) {

NodeList pictChildNodes = item.getChildNodes();

for (int i = 0; i < pictChildNodes.getLength(); i++) {

Node vShapeNode = pictChildNodes.item(i);

if (!"v:shape".equals(vShapeNode.getNodeName())) {
continue;
}

NodeList vShapeChildNodes = vShapeNode.getChildNodes();
Node textboxNode = vShapeChildNodes.item(0);

NodeList textboxChildNodes = textboxNode
.getChildNodes();
Node textContentNode = textboxChildNodes.item(0);

NodeList txbxContentChildNodes = textContentNode
.getChildNodes();
Node wpNode = txbxContentChildNodes.item(0);

NodeList wpNodeChildNodes = wpNode.getChildNodes();

for (int j = 0; j < wpNodeChildNodes.getLength(); j++) {

Node wrNode = wpNodeChildNodes.item(j);
if (!"w:r".startsWith(wrNode.getNodeName())) {
continue;
}

NodeList wrNodeChildNodes = wrNode.getChildNodes();
Node wtNode = wrNodeChildNodes.item(1);

Node targetNode = wtNode.getChildNodes().item(0);

if (targetNode == null) {
continue;
}

String targetNodeValue = targetNode.getNodeValue();

Object value = tags.get(targetNodeValue);

if (value != null) {
targetNode.setNodeValue(value.toString());
}

ctr.set(xmlObject);
}

}

}
}
}
}
}

@Override
public void write(OutputStream out) {
buildWordDoc();
super.write(out);
}

public void write(OutputStream out, boolean isCloseStream) {
buildWordDoc();
try {
this.document.write(out);
out.flush();
if (isCloseStream) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}

}

@Override
public void write(String outputPath) {
//buildWordDoc();重复调用了
super.write(outputPath);
}

}

时间: 2024-10-31 01:31:48

POI列子:替换文本框值的相关文章

JS动态生成Input文本框 并获取文本框值

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns= "http://www.w3.org/1999/xhtml" > <head> <meta http-equiv= "Conte

JS获取文本框值

一.获取文本框/编辑框/隐藏域框 <script type="text/javascript">function Mycheck(){  var checkstr="获取内容如下:\n";  if (document.form1.文章作者.value != ""){     checkstr+="作者名称:"+document.form1.文章作者.value+"\n";  }  if (doc

jquery设置文本框值 与获取文本框的值

<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="../js/jquery-1.12.4.js"></script> </head> <body> <input type="tex

在JSP页面中获取本页的文本框值(亲测可用)

对我很有用,就记在这了,方便再学习. 项目中用到一个查询条件,点击查询后,需要将结果显示在本页中.但是需要能在本页面中取值,如何不通过别的页面或action/servlet第三方来获得该文本框的值呢.百思不得其解...... 还是我们老大见多识广,在高人指点下不费吹灰之力就解决了(但是需要在JSP页面中写JAVA代码) 首先是一个form表单,里面有一个文本框或其它的表单项 <form name="thisform"method="post"><i

word 替换文本框

创建以下宏 Dim mShape As Shape Dim tmpString As String For Each mShape In ActiveDocument.Shapes If mShape.Type = msoTextBox Then tmpString = mShape.TextFrame.TextRange.Text mShape.TextFrame.TextRange.Text = Replace(tmpString, "查找内容", "替换内容"

js 文本框值变化触发事件

jo.find(".price").bind('input onpropertychange', function () { me.calculate(jo); });

js/jquery获取文本框的值与改变文本框的值

我们就用它来学习获取文本框的值及改变文本框的值. 代码如下 复制代码 <script>function get1(){ document.getElementById("txtbox2").value=document.getElementById("txtbox").value; //获取文本框1的值,并赋值给文本框2}</script> <table width="500" border="0"

jQuery实现点击文本框清除内容代码实例

jQuery实现点击文本框清除内容代码实例:本章节介绍一下文本框最简单的一个人性化措施,就是点击文本框的时候能够删除里面的提示文本.代码实例如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title&g

文本框的onchange事件,如何兼容各大浏览器

在项目中经常会遇到对用户输入的数据进行实时校验,而不是等文本框失去焦点或用户手动点击校验. 首先分析下在哪些情况下文本框会产生change事件. 1.用户通过键盘入正常字符时: 2.用户通过键盘输入非正常字符时 ctrl+v ctrl+x ctrl+z delete Backspace 等操作时: 3.用户通过鼠标进行粘贴.剪切.撤消等操作时: <body> <input id="text1" type="text"/> <div id