'//Run: client, Java
import lotus.domino.*;
import java.util.*;
import java.text.*;
import java.io.*;
import jxl.*;
import jxl.write.*;
import java.util.*;
import java.util.Date;
import java.util.Vector;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
System.out.println ("A6.1 Document Revise History -Start");
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db = agentContext.getCurrentDatabase();
Document docQuery = db.createDocument();
// Database db = session.getDatabase("CN=CMOS01/O=CHIPMOS","ap\\dcc2\\dcc18.nsf");
View viewEff = db.getView("vwEff_1DByFab");
ViewNavigator nav = viewEff.createViewNav();
ViewEntry entryEff;
Document doc;
SimpleDateFormat formatter_1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat formatter_2 = new SimpleDateFormat("yyMMdd");
lotus.domino.DateTime dt;
lotus.domino.DateTime dtToday;
Item item;
String strFab;
String strFabCode;
String strPL;
String strFilePath;
String strFileName;
String strPreSpecNo;
int intR;
jxl.write.WritableWorkbook wwb = null;
jxl.write.WritableSheet ws = null;
jxl.write.Label label =null;
strFab = "";
strPL = "";
intR = 1;
strPreSpecNo = "";
strFilePath = "";
strFabCode = "";
dtToday = docQuery.getCreated();
strFileName = "document_" + formatter_2.format(dtToday.toJavaDate()) + ".xls";
if (session.getPlatform().equals("Windows 32-bit") | session.getPlatform().equals("Windows/32")) {
strFilePath= "c:/temp/" + strFileName;
}
else {
strFilePath= "/tmp/" + strFileName;
}
wwb = Workbook.createWorkbook(new File(strFilePath));
ws = wwb.createSheet(formatter_2.format(dtToday.toJavaDate()) , 0);
label = new jxl.write.Label(0, 0, "產線");
ws.addCell(label);
label = new jxl.write.Label(1, 0, "類別");
ws.addCell(label);
label = new jxl.write.Label(2, 0, "Step/Function");
ws.addCell(label);
label = new jxl.write.Label(3, 0, "文件編碼");
ws.addCell(label);
label = new jxl.write.Label(4, 0, "版本");
ws.addCell(label);
label = new jxl.write.Label(5, 0, "生效日期");
ws.addCell(label);
label = new jxl.write.Label(6, 0, "撰寫者");
ws.addCell(label);
label = new jxl.write.Label(7, 0, "部門名稱");
ws.addCell(label);
label = new jxl.write.Label(8, 0, "文件名稱");
ws.addCell(label);
label = new jxl.write.Label(9, 0, "變更理由及特殊說明事由");
ws.addCell(label);
label = new jxl.write.Label(10, 0, "變更後內容");
ws.addCell(label);
entryEff = nav.getFirst();
while (entryEff != null) {
Vector vCol = entryEff.getColumnValues();
strFab = vCol.elementAt(0).toString();
strPL = vCol.elementAt(1).toString();
doc = entryEff.getDocument();
strFabCode = doc.getItemValueString("Kind");
label = new jxl.write.Label(0, intR, strFab);
ws.addCell(label);
label = new jxl.write.Label(1, intR, strPL);
ws.addCell(label);
label = new jxl.write.Label(2, intR, doc.getItemValueString("Step"));
ws.addCell(label);
label = new jxl.write.Label(3, intR,doc.getItemValueString("DocNo"));
ws.addCell(label);
label = new jxl.write.Label(4, intR, doc.getItemValueString("Ver"));
ws.addCell(label);
item = doc.getFirstItem("ISS_DT");
dt = item.getDateTimeValue();
label = new jxl.write.Label(5, intR, formatter_1.format(dt.toJavaDate()));
ws.addCell(label);
label = new jxl.write.Label(6, intR, doc.getItemValueString("ORIGINATOR"));
ws.addCell(label);
label = new jxl.write.Label(7, intR, doc.getItemValueString("DeptName"));
ws.addCell(label);
label = new jxl.write.Label(8, intR,doc.getItemValueString("TITLE"));
ws.addCell(label);
label = new jxl.write.Label(9, intR, doc.getItemValueString("Notices"));
ws.addCell(label);
label = new jxl.write.Label(10, intR, doc.getItemValueString("Text4"));
ws.addCell(label);
intR = intR + 1;
entryEff = nav.getNext(entryEff);
}
//寫入Exel工作表
wwb.write();
//關閉Excel工作物件
wwb.close();
docQuery.replaceItemValue("Form","QueryForm");
docQuery.replaceItemValue("FilePath",strFilePath);
docQuery.replaceItemValue("FileName",strFileName);
docQuery.save();
Agent agFTP = db.getAgent("A11_FTP2FileServer");
agFTP.runOnServer(docQuery.getNoteID());
} catch(Exception e) {
e.printStackTrace();
}
}
}
沒有留言:
張貼留言