首页 > 学院 > 开发设计 > 正文

lotus domino EXCEL导出功能开发

2019-11-08 03:17:59
字体:
来源:转载
供稿:网友

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);        }

         //String PrintPath = "<script>window.parent.hiddenLayer();window.open('/outputexcel/" + filename+"');</script>";            //System.out.println(PrintPath);      wwb.write(); 

         // 关闭文件     

         wwb.close();          //pw.println(PrintPath);         pw.println("<script>window.location.href=window.location.href;window.open('/outputexcel/" + filename+"');</script>");   pw.close();        } catch (Exception e) {   e.printStackTrace();  } finally {   try {    //if (rs != null)    // rs.close();    if (doc != null)     doc.recycle();    if (db != null)     db.recycle();    if (agentContext != null)     agentContext.recycle();    if (session != null)     session.recycle();    System.gc();   } catch (NotesException ne) {    ne.printStackTrace();   } catch (Exception e) {    // TODO 自动生成 catch 块    e.printStackTrace();   }  } }

 }

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表