参考下面
Ncc 怎么获取wps设置的模板生成文件 RtfDownloadFactory
这个类里 找到下面那一串方法downLoad
bytes=createContFile(pk_conmodel,pk_psndoc,context,tablename,primaryKey);
我们可以在查询的时候查询出模板主键 用户主键 表名 4个参数传进去
public String generateFile(String pk) {
Properties configuration = getConfiguration();
String filepath = configuration.getProperty("FILEPATH");// 文件路径 本地的文件保存的地址
String vmodelname = "";// 合同名称
LoginContext context = new LoginContext();
RtfDownloadFactory rtfdownloadfactory = new RtfDownloadFactory();
String sql = "select c.pk_psndoc,c.pk_conttext FROM 你需要生成文件的表名 c where c.主键 = '" + pk
+ "' AND c.dr=0 ;";
Map<String, String> executeQuery;
try {
executeQuery = (Map<String, String>) getBaseDAO().executeQuery(sql, new MapProcessor());
// CtrtMngVO queryCtrtMngVOBypk = ictrtmngservice.queryCtrtMngVOBypk(pk);
String pk_psndoc = executeQuery.get("pk_psndoc");// 人员主键
String pk_conttext = executeQuery.get("pk_conttext");// 合同模板
String plsql = "select h.vmodelname from 模板的表名 h where h.模板主键= '" + pk_conttext + "' ; ";
Map<String, String> execute = (Map<String, String>) getBaseDAO().executeQuery(plsql, new MapProcessor());
vmodelname = execute.get("vmodelname");// 模板名字
// 合同模板 人员主键 日志文件 数据库表面 合同主键
byte[] createContFile = rtfdownloadfactory.createContFile(pk_conttext, pk_psndoc, context, "hi_psndoc_ctrt",
pk);
Logger.info("合同模板:" + pk_conttext + ",人员主键:" + pk_psndoc);
FileOutputStream fileOutputStream = new FileOutputStream(new File(filepath + vmodelname + ".rtf"));
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
bos.write(createContFile);
bos.close();//
Logger.info("合同文件路径:" + filepath + vmodelname + ".rtf");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return vmodelname;
}
如果在生成了文件需要删除的话可以调用file.dele();方法就可以删除了返回的是一个boolean 类型
如果你不想把保存文件的路径写死的话可以把文件的路径写在配置文件里面然后使用下面的方法
Properties porp = new Properties();
InputStreamReader stream = new InputStreamReader(
CreateContractServiceImpl.class.getResourceAsStream("当前你需要的配置文件的权限路径"), "UTF-8");
porp.load(stream);
porp这个里面就是配置文件的获取值 用一个getProperty()的方法获取配置文件里面要是键值对的方式来写
例如:
FILEPATH=C:\\