import lotus.domino.*;
import java.util.*;
import java.io.*;
import jxl.*;
import jxl.write.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db=agentContext.getCurrentDatabase();
Document doc =null;
Enumeration values=null;
View view=db.getView("view32");
Item item1 = null;
Item item2 = null;
String tmpStr1="";
String tmpStr2 = "";
String tmpStr = "";
String tmpStr3="";
lotus.domino.DateTime signdt = null;
lotus.domino.DateTime nowdt = session.createDateTime("Today");
nowdt.setNow();
int x=1;
// (您的程式碼移至此處)
//產生目前所需要的EXCEL物件
jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(new File("/tmp/upload_excel_map.xls"));
jxl.write.WritableSheet ws = wwb.createSheet("Report", 0);
jxl.write.Label label =null;
label = new jxl.write.Label(0, 0, "Part No.");
ws.addCell(label);
label = new jxl.write.Label(1, 0, "Lot No.");
ws.addCell(label);
label = new jxl.write.Label(2, 0, "Hold Code");
ws.addCell(label);
label = new jxl.write.Label(3, 0, "狀態碼");
ws.addCell(label);
//label = new jxl.write.Label(4, 0, "Initial report");
//ws.addCell(label);
//label = new jxl.write.Label(5, 0, "Comment");
//ws.addCell(label);
//label = new jxl.write.Label(6, 0, "Last Modify");
//ws.addCell(label);
//label = new jxl.write.Label(7, 0, "OP.");
//ws.addCell(label);
doc = view.getFirstDocument();
while (doc != null) {
//System.out.println(doc.getItemValueString("product"));
Vector times = doc.getItemValueDateTimeArray("SignDate");
signdt = (lotus.domino.DateTime)times.elementAt(times.size()-1);
tmpStr="";
tmpStr1="";
tmpStr2="";
tmpStr3="";
item1 = doc.getFirstItem("Tran_Hold_Code");
item2 = doc.getFirstItem("Tran_Hold_Code_1");
values = item1.getValues().elements();
if((nowdt.timeDifference(signdt) / 3600)<7){
while (values.hasMoreElements()) {
tmpStr = (String)values.nextElement();
if(tmpStr.equalsIgnoreCase("EXMAP")){
tmpStr1=tmpStr1+",請先上傳Excel Map";
tmpStr3="Y";
}else{
tmpStr1=tmpStr1+","+tmpStr;
}
}
if(! tmpStr3.equalsIgnoreCase("")){
label = new jxl.write.Label(0, x, doc.getItemValueString("product"));
ws.addCell(label);
label = new jxl.write.Label(1, x, doc.getItemValueString("Lot_Number"));
ws.addCell(label);
label = new jxl.write.Label(2, x, doc.getItemValueString("Hold_Code"));
ws.addCell(label);
//if(!doc.getItemValueString("Tran_Hold_Code_1").equalsIgnoreCase("")){
// values = item2.getValues().elements();
// while (values.hasMoreElements()) {
// tmpStr = (String)values.nextElement();
// tmpStr2=tmpStr2 +" ," +tmpStr;
// }
//}
label = new jxl.write.Label(3, x, tmpStr1);
ws.addCell(label);
//label = new jxl.write.Label(4, x, doc.getItemValueString("Report1"));
//ws.addCell(label);
//label = new jxl.write.Label(5, x, doc.getItemValueString("Comment"));
//ws.addCell(label);
//label = new jxl.write.Label(6, x, tmpStr2);
//ws.addCell(label);
}
x++;
}
doc = view.getNextDocument(doc);
}
//label = new jxl.write.Label(0, x, "若遇CM06轉碼,請協助子母批一起執行此動作,待後續處置,謝謝!");
//ws.addCell(label);
//寫入Exel工作表
wwb.write();
//關閉Excel工作物件
wwb.close();
if(x>1){
Vector v = new Vector();
v.addElement("3550");
v.addElement("3630");
Document maildoc = db.createDocument();
maildoc.replaceItemValue("Subject", "上傳Excel Map List");
maildoc.appendItemValue("Form", "Memo");
RichTextItem body = maildoc.createRichTextItem("Body");
body.appendText("上傳Excel Map List:");
body.addNewLine(2);
body.embedObject(EmbeddedObject.EMBED_ATTACHMENT,null, "/tmp/upload_excel_map.xls", "");
maildoc.send(true, v);
System.out.println("Send Excel Map File");
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
沒有留言:
張貼留言