import java.io.PRintWriter;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.text.DecimalFormat;import java.util.Date;import java.util.Vector;import lotus.domino.AgentBase;import lotus.domino.AgentContext;import lotus.domino.Database;import lotus.domino.Document;import lotus.domino.NotesException;import lotus.domino.session;import com.sap.mw.jco.JCO;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.io.FileOutputStream; import java.io.OutputStream; import jxl.Sheet;import jxl.Workbook;import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.Label; public class JavaAgent extends AgentBase {
public void NotesMain() {
Session session = null; AgentContext agentContext = null; Database db = null; Document doc = null; SQLServer_BasicFunction sqlbf = null; String dbname = "oerp"; //ResultSet rs = null; //JCO.Function function = null; WritableWorkbook wwb; System.out.println("----------------------kkk"); try { session = getSession(); agentContext = session.getAgentContext(); db = agentContext.getCurrentDatabase(); doc = agentContext.getDocumentContext(); sqlbf = new SQLServer_BasicFunction(session, db, dbname); java.text.SimpleDateFormat format1 = new java.text.SimpleDateFormat("yyyyMMddHHmmss"); Date now = new Date(); String dateStr1 = format1.format(now); String filename=dateStr1 + ".xls"; File directory = new File("");//參數為空 String courseFile = null; courseFile = directory.getCanonicalPath() ; String filePath = null; filePath = courseFile+"//data//domino//html//outputExcel//"+filename; System.out.println(filePath); directory=null;
// 創建Excel工作薄 // 新建立一個jxl文件,即在e盤下生成testJXL.xls OutputStream os = new FileOutputStream(filePath); wwb=Workbook.createWorkbook(os); // 添加第一個工作表并設置第一個Sheet的名字 WritableSheet sheet = wwb.createSheet("sheet1", 0); PrintWriter pw = getAgentOutput(); DecimalFormat df2 = new DecimalFormat("####"); StringBuilder sb= new StringBuilder(); // Label(x,y,z) 代表單元格的第x+1列,第y+1行, 內容z // 在Label對象的子對象中指明單元格的位置和內容 Label label = new Label(0,0,"是否錄入到SAP系統"); sheet.addCell(label); label = new Label(1,0,"物料編號"); sheet.addCell(label); label = new Label(2,0,"物料描述"); sheet.addCell(label); label = new Label(3,0,"供應商"); sheet.addCell(label); label = new Label(4,0,"價格(含稅)"); sheet.addCell(label); label = new Label(5,0,"舊價格(含稅)"); sheet.addCell(label); label = new Label(6,0,"新舊價格差異率"); sheet.addCell(label); label = new Label(7,0,"交貨期"); sheet.addCell(label); label = new Label(8,0,"稅率"); sheet.addCell(label); label = new Label(9,0,"材料費"); sheet.addCell(label); label = new Label(10,0,"加工費"); sheet.addCell(label); label = new Label(11,0,"是否含運"); sheet.addCell(label); label = new Label(12,0,"跟最低價的差異率"); sheet.addCell(label); label = new Label(13,0,"有效期從"); sheet.addCell(label); label = new Label(14,0,"有效期到"); sheet.addCell(label); label = new Label(15,0,"條件采購單位"); sheet.addCell(label); int row =0; ResultSet rs = null; System.out.println(doc.getItemValueString("KEYUNID")); //try //{ rs=sqlbf.Select("SELECT * FROM WH_SRM_Vendorratio_Sub where parentid ='"+ doc.getItemValueString("KEYUNID")+"'"); while(rs.next()) { System.out.println(row); row =row+1; label = new Label(0,row,rs.getString("ZConfirm")); sheet.addCell(label); label = new Label(1,row,rs.getString("MATNR")); sheet.addCell(label); label = new Label(2,row, rs.getString("MAKTX")); sheet.addCell(label); label = new Label(3,row, rs.getString("VERDOR")); sheet.addCell(label); label = new Label(4,row, rs.getString("PRICE")); sheet.addCell(label); label = new Label(5,row, rs.getString("OLDPRICE")); sheet.addCell(label); label = new Label(6,row, rs.getString("DIFFPRICE")); sheet.addCell(label); label = new Label(7,row, rs.getString("DELIVERYTIME")); sheet.addCell(label); label = new Label(8,row, rs.getString("TAXRATE")); sheet.addCell(label); label = new Label(9,row, rs.getString("materialcost")); sheet.addCell(label); label = new Label(10,row, rs.getString("processcost")); sheet.addCell(label); label = new Label(11,row, rs.getString("FREIGHT")); sheet.addCell(label); label = new Label(12,row, rs.getString("LowPriceDiff")); sheet.addCell(label); label = new Label(13,row, rs.getString("B_VERDERTIME")); sheet.addCell(label); label = new Label(14,row, rs.getString("E_VERDERTIME")); sheet.addCell(label); label = new Label(15,row, rs.getString("MEINS")); sheet.addCell(label); }
新聞熱點
疑難解答