import lotus.domino.*;
import java.io.*;
import java.util.Vector;
import jxl.*;
/*******************************************************************************
* @saveSQMessageToOracle
* @作者:徐华祥
* @2009年10月28日
* @说明:Execl文件的导入
******************************************************************************/
public class inputExecl_new extends AgentBase {
public void NotesMain() {
System.out.println("代理开始");
EmbeddedObject ebd = null;
String srcFile = "";
InputStream is = null;
Workbook wb = null;
Sheet st = null;
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document currentDoc = agentContext.getDocumentContext();
Database currentDB = agentContext.getCurrentDatabase();
Database wjkhDB = session.getDatabase(currentDB.getServer(),
"whcg/linkey_weijkh.nsf");
String path = currentDoc.getItemValueString("Path");
View wjkhView = wjkhDB.getView("showtousNo");
Vector vtr = session.evaluate("@AttachmentNames", currentDoc);
srcFile = new String("" + vtr.get(0).toString());
ebd = currentDoc.getAttachment(srcFile);
ebd.extractFile(srcFile);
is = new FileInputStream(srcFile);
wb = Workbook.getWorkbook(is);
if (ebd == null) {
wb.close();
wb = null;
return;
}
if (ebd.getType() != EmbeddedObject.EMBED_ATTACHMENT) {
wb.close();
wb = null;
return;
}
st = wb.getSheet(0);
int i = 0;
int m = 0;
int n = 0;
for (i = 1; i < st.getRows(); i++) {
Cell cellno = st.getCell(0, i);
Cell cellqu = st.getCell(7, i);
Document InViewDoc = wjkhView.getDocumentByKey(cellno
.getContents());
if (cellno.getContents().equals("")
|| cellqu.getContents().equals("") || InViewDoc != null) {
m++;
} else if (!cellno.getContents().equals("")
&& !cellqu.getContents().equals("")
&& InViewDoc == null) {
n++;
Document newDoc = wjkhDB.createDocument();
newDoc.appendItemValue("form", "NewDoc");
Cell cell1 = st.getCell(0, i);
if (!cell1.getContents().equals("")) {
newDoc.appendItemValue("tousNo", cell1.getContents());
} else {
newDoc.appendItemValue("tousNo", "");
}
Cell cell2 = st.getCell(1, i);
if (!cell2.getContents().equals("")) {
newDoc.appendItemValue("jiejType", cell2.getContents());
} else {
newDoc.appendItemValue("jiejType", "");
}
Cell cell3 = st.getCell(2, i);
if (!cell3.getContents().equals("")) {
newDoc.appendItemValue("tousTypeName", cell3
.getContents());
} else {
newDoc.appendItemValue("tousTypeName", "");
}
Cell cell4 = st.getCell(3, i);
if (!cell4.getContents().equals("")) {
newDoc.appendItemValue("tousUser", cell4.getContents());
} else {
newDoc.appendItemValue("tousUser", "");
}
Cell cell5 = st.getCell(4, i);
if (!cell5.getContents().equals("")) {
newDoc.appendItemValue("userSex", cell5.getContents());
} else {
newDoc.appendItemValue("userSex", "");
}
Cell cell6 = st.getCell(5, i);
if (!cell6.getContents().equals("")) {
newDoc.appendItemValue("fankTel", cell6.getContents());
} else {
newDoc.appendItemValue("fankTel", "");
}
Cell cell7 = st.getCell(6, i);
if (!cell7.getContents().equals("")) {
newDoc
.appendItemValue("youxjType", cell7
.getContents());
} else {
newDoc.appendItemValue("youxjType", "");
}
Cell cell8 = st.getCell(7, i);
if (!cell8.getContents().equals("")) {
newDoc.appendItemValue("chengqName", cell8
.getContents());
} else {
newDoc.appendItemValue("chengqName", "");
}
Cell cell9 = st.getCell(8, i);
if (!cell9.getContents().equals("")) {
newDoc.appendItemValue("luName", cell9.getContents());
} else {
newDoc.appendItemValue("luName", "");
}
Cell cell10 = st.getCell(9, i);
if (!cell10.getContents().equals("")) {
newDoc.appendItemValue("tousContent", cell10
.getContents());
} else {
newDoc.appendItemValue("tousContent", "");
}
Cell cell11 = st.getCell(10, i);
if (!cell11.getContents().equals("")) {
newDoc.appendItemValue("tousInTel", cell11
.getContents());
} else {
newDoc.appendItemValue("tousInTel", "");
}
Cell cell12 = st.getCell(11, i);
if (!cell12.getContents().equals("")) {
newDoc
.appendItemValue("comyName", cell12
.getContents());
} else {
newDoc.appendItemValue("comyName", "");
}
Cell cell13 = st.getCell(12, i);
if (!cell13.getContents().equals("")) {
newDoc
.appendItemValue("jiejUser", cell13
.getContents());
} else {
newDoc.appendItemValue("jiejUser", "");
}
Cell cell14 = st.getCell(13, i);
if (!cell14.getContents().equals("")) {
newDoc.appendItemValue("zhuanjUser", cell14
.getContents());
} else {
newDoc.appendItemValue("zhuanjUser", "");
}
Cell cell15 = st.getCell(14, i);
if (!cell15.getContents().equals("")) {
newDoc.appendItemValue("jilTime", cell15.getContents());
} else {
newDoc.appendItemValue("jilTime", "");
}
Cell cell16 = st.getCell(15, i);
if (!cell16.getContents().equals("")) {
newDoc.appendItemValue("chujzt", cell16.getContents());
} else {
newDoc.appendItemValue("chujzt", "");
}
newDoc.save(true, true);
}
}
wb.close();
is.close();
String tips = "您有" + m + "条信息导入失败,请检查投诉编号是否重复或为空,城区名称是否为空!";
PrintWriter out = getAgentOutput();
if (m == 0) {
out
.println("<meta http-equiv=/"Content-Type/" content=/"text/html; charset=GBK/">");
out
.println("<script language='javascript'>alert('文件导入完毕');</script>");
}
if (m != 0) {
out
.println("<meta http-equiv=/"Content-Type/" content=/"text/html; charset=GBK/">");
out.println("<script language='javascript'>alert('" + tips
+ "');</script>");
out
.println("<script language='javascript'>window.location.href='/"
+ path
+ "/showKhjlbother?openform&page=1'</script>");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}