文档生成html文件,把domino 的文档生成 doc 或者 html 文件的实现

import lotus.domino.*;

import java.util.*;

import java.io.PrintWriter;

import com.gdcn.admin.*;

import com.gdcn.rmi.*;

import java.rmi.Naming;

import com.gdcn.domino.util.Log;

import java.io.*;

import com.gdcn.domino.*;

import com.gdcn.*;

import java.lang.*;

import org.jdom.Element;

public class JavaAgent extends AgentBase {

HashMap paramsMap;

private PrintWriter pw;

private PubliceFunction pFunc = new PubliceFunction();

private static DominoInt dominoInt = null;

private Session session = null;

private String tmpPath_forWord = null; //临时目录

private AgentContext agentContext;

private Database   gz_dict_config = null;

private Vector youxiang= new Vector(); //律师邮箱

private Document tmpDoc=null;

public void NotesMain() {

try {

session = getSession();

agentContext = session.getAgentContext();

pw = getAgentOutput();

dominoInt = pFunc.getRmi(session);

Document doc = agentContext.getDocumentContext();

Database db = agentContext.getCurrentDatabase();

//取业务配置库

String lstrPath = db.getFilePath().toString()

.substring(

0,

(db.getFilePath().length() - db

.getFileName().length()));

gz_dict_config= session.getDatabase(db.getServer(), lstrPath

+ "gz_dict_config.nsf");

View law=null;

Document ywDoc = null;

if(doc.getItemValueString("lxr")!=null && !doc.getItemValueString("lxr").equals("")){

law=gz_dict_config.getView("vw_ShowLSConfigformail");

ywDoc= law.getDocumentByKey(doc.getItemValueString("lxr"));

youxiang=ywDoc.getItemValue("youxiang");

}

for(int i=0;iString platform. = session.getPlatform();

String tempRtfDir=getDbPathWithSepChar(db); //临时文档路径

String tmpAttName = "test1.doc";

tmpPath_forWord = session.getEnvironmentString("Directory", true);

if (platform.equals("UNIX") || platform.equals("LINUX")) {

tmpPath_forWord += "/domino/html/download/";

} else {

tmpPath_forWord += "";

}

String tempRtfFile = tmpPath_forWord+tmpAttName;

tmpDoc = db.createDocument();

Document RcfvTable =db.createDocument();

RcfvTable.replaceItemValue("form","RcfvTable");

RcfvTable.replaceItemValue("user",agentContext.getEffectiveUserName());

RcfvTable.replaceItemValue("zcdh",doc.getFirstItem("bhText").getText());

RcfvTable.replaceItemValue("fadanren",doc.getItemValueString("InitalAuthor_SYS_1"));

RcfvTable.replaceItemValue("jbtime_1", doc.getFirstItem("jbtime").getText());

RcfvTable.replaceItemValue("riqi",doc.getItemValueString("InitalCreated").substring(0,10));

RcfvTable.replaceItemValue("projectname_1", doc.getFirstItem("projectname").getText());

RcfvTable.replaceItemValue("name_1", doc.getFirstItem("name").getText());

RcfvTable.replaceItemValue("lxr_1", doc.getFirstItem("lxr").getText());

//         RcfvTable.replaceItemValue("zcdnr_1", doc.getFirstItem("zcdnr").getText());

Vector xinxi=doc.getItemValue("zcdnr");

String neir="";

for(int k=0;kneir+=xinxi.get(k)+"

";

}

RcfvTable.replaceItemValue("zcdnr_1", neir);

RcfvTable.replaceItemValue("yqfksj_1", doc.getFirstItem("yqfksj").getText()+"  "+doc.getItemValueString("qjtime1"));

RcfvTable.replaceItemValue("hdnr_1", "");

RcfvTable.replaceItemValue("cljg", "");

RichTextItem tmpItem;

if(tmpDoc.hasItem("rtf_DocAtt")) tmpDoc.removeItem("rtf_DocAtt");

tmpItem=tmpDoc.createRichTextItem("rtf_DocAtt");

RcfvTable.renderToRTItem(tmpItem);

//文档正文内容

String tmp = tmpItem.getText();

FileOutputStream fOut=new FileOutputStream(tempRtfFile);

fOut.write(tmp.getBytes());

if(tmpDoc.hasItem("rtf_DocAtt")) tmpDoc.removeItem("rtf_DocAtt");

tmpItem=tmpDoc.createRichTextItem("rtf_DocAtt");

tmpItem.××Object(××dedObject.××_ATTACHMENT,"",tempRtfFile,"test1.doc");

File tmpFile = new File(tempRtfFile);

tmpFile.delete();

RcfvTable.remove(true);

String direct = session.getEnvironmentString("Directory", true);

String tmpPath = "";

if (platform.toLowerCase().indexOf("windows") > -1) {

tmpPath = direct + "";

} else {

tmpPath = direct + "/domino/html/temp/";

}

File fileTemp = new File(tmpPath);

if(!fileTemp.isDirectory()){

fileTemp.mkdir();

}

//      for(int i=0;itmpDoc.replaceItemValue("form", "Memo");

//设置当前登陆用户为发件人

tmpDoc.replaceItemValue("Principal",doc.getItemValueString("currentUserNameCommon"));

//邮件标题

tmpDoc.replaceItemValue("Subject", "test1--"+doc.getItemValueString("bhText"));

//邮件内容

RichTextItem wbody = tmpDoc.createRichTextItem("wBody");

//         wbody.appendText("");

MIMEEntity body = tmpDoc.createMIMEEntity();

Stream stream = session.createStream();

stream.writeText(wbody.getText());

body.setContentFromText(stream, "text/html;charset=UTF-8",MIMEEntity.ENC_NONE);

wbody.remove();

//========== 把附件加到邮件上 ======

//1、取附件名

String attformular = "@AttachmentNames";

Vector ret = session.evaluate(attformular,doc);

if(!ret.get(0).toString().equals("")){ //如果存在附件

//2、拆除附件

for (int j = 0; j < ret.size(); j++) {

String attName_down = ret.get(j).toString();

try {

××dedObject obj_down = doc.getAttachment(attName_down);

if (obj_down != null) {

obj_down.extractFile(tmpPath + attName_down);

obj_down.recycle();

obj_down = null;

}

} catch (Exception e) {

e.printStackTrace();

}

}

//3、上传附件

RichTextItem attFile =tmpDoc.createRichTextItem("Body");

for (int k = 0; k < ret.size(); k++) {

String attName_up = ret.get(k).toString();

File upAttFile = new File(tmpPath + attName_up);

if (upAttFile.exists()) {

attFile.××Object(××dedObject.××_ATTACHMENT, null,

tmpPath + attName_up, attName_up);

try {

upAttFile.delete(); // 删除临时文档

} catch (Exception delErr) {

delErr.printStackTrace();

}

} else {

throw new RuntimeException("NotesMain()出错:服务器文件["+tmpPath + attName_up+"]不存在");

}

}

attFile.recycle();

attFile = null;

}

tmpDoc.send(false,youxiang.get(i).toString());

}

//      tmpDoc.send(false,youxiang);

doc.save(true,true);

pw.println("");

ywDoc.recycle();

law.recycle();

} catch(Exception e) {

e.printStackTrace();

}finally{

if(dominoInt != null && (dominoInt instanceof com.gdcn.domino.pool.DominoIntProxy))

((com.gdcn.domino.pool.DominoIntProxy)dominoInt).release();

try {

session.recycle();

} catch (Exception e) {

e.printStackTrace();

}

}

}

/**

* 功能:取当前数据库目录(包括分隔符号),与平台不相关

*/

public String getDbPathWithSepChar(Database db) throws Exception {

String path = "";

String dbPath = db.getFilePath();

String filename = db.getFileName();

path = dbPath.substring(0, dbPath.length() - filename.length());

return path;

}

}

有时生成的doc文档格式不对,需要在表单设置里,把所有内容内嵌为HTML,然后用和把它们包起来

同理可以生成 html 文件

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值