blog.Toby

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  130 随笔 :: 2 文章 :: 150 评论 :: 0 Trackbacks
调用:
//写入EXCEL表格
            String fileName = "";
            fileName=dtPart+".xls";
            File fs = new File("E:\\ITFI_SELSTK\\app\\webapp\\excel\\");
            String[] fns=fs.list();
            boolean exist = false;
            if(fns!=null&&fns.length>0)
            {
                for(int i=0;i<fns.length;i++)
                {
                    if(fns[i].equals(fileName))
                        exist = true;
                }
            }
            if(exist==false||fns.length<=0)
            {
                //取出股票策略
                String sql = "select a.sec_cd,b.sel_snm from (select distinct sec_cd,ind_id from cd_10_ind.dbo.ind_s_model_sel where pub_dt=convert(char(10),getdate(),120)) as a,AUTO_SEL_CLS b where a.ind_id=b.sel_cd ";
                DatabaseOperate opcl = new DatabaseOperate("jdbc_sel_stk", DatabaseOperate.OP_QUERY, sql, request);
       String[][] indnms = opcl.execute();
                for(int m=0;m<totalb1Stks.length;m++)
                {
                    for(int n=0;n<indnms.length;n++)
                    {
                          if(totalb1Stks[m][0].trim().equals(indnms[n][0].trim()))
                          {
                                totalb1Stks[m][28]+=indnms[n][1]+",";
                          }
                    }
                 
                }
                File f = new File("E:\\ITFI_SELSTK\\app\\webapp\\excel\\"+fileName);
                f.createNewFile();
                writeExcel(new FileOutputStream(f),totalb1Stks);
            }
     //end write excel ===========
----------------------------------------------------------------------------------------
public static void writeExcel(OutputStream os,String[][] smsInfo) throws Exception {
  jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os);
  jxl.write.WritableSheet ws = wwb.createSheet("Sheet1", 0);
  //控制显示格式
  jxl.write.WritableFont wfc =
   new jxl.write.WritableFont(
    WritableFont.ARIAL,
    10,
    WritableFont.BOLD,
    false,
    UnderlineStyle.NO_UNDERLINE,
    jxl.format.Colour.GREEN);
  //jxl.write.WritableCellFormat wcfFC = //格式控制
  // new jxl.write.WritableCellFormat(wfc);
        String[] title = new String[16];
        title[0] = "股票代码";
        title[1] = "股票简称";
        title[2] = "昨收盘";
        title[3] = "EPS05";
        title[4] = "EPS06e";
        title[5] = "评级人数";
        title[6] = "评级系数";
        title[7] = "PE";
        title[8] = "PB";
        title[9] = "PS";
        title[10] = "PE/G";
        title[11] = "ROE";
        title[12] = "毛利率";
        title[13] = "行业";
        title[14] = "策略";
        title[15] = "录入人员";
  if(smsInfo!=null)
  {
   int len = smsInfo.length;
             //先写入excel表格标题
            jxl.write.Label labelC = new jxl.write.Label(0, 0, title[0]);
            ws.addCell(labelC);
            String pjxs="N/A";
            for(int j=1;j<title.length;j++)
            {
                labelC = new jxl.write.Label(j, 0, title[j]);
                ws.addCell(labelC);
            }
   for(int i=0;i<len;i++)
   {
    labelC = new jxl.write.Label(0, i+1, smsInfo[i][0]);
          ws.addCell(labelC);
                labelC = new jxl.write.Label(1, i+1, smsInfo[i][1]);
          ws.addCell(labelC);
                labelC = new jxl.write.Label(2, i+1, StringUtil.getDouble(smsInfo[i][9],2));
          ws.addCell(labelC);
                labelC = new jxl.write.Label(3, i+1, smsInfo[i][7]);
          ws.addCell(labelC);
                labelC = new jxl.write.Label(4, i+1, StringUtil.getDouble(smsInfo[i][8],2));
          ws.addCell(labelC);
                labelC = new jxl.write.Label(5, i+1, smsInfo[i][11]);
          ws.addCell(labelC);
                if(!StringUtil.getDouble(smsInfo[i][10],2).equals("9.00"))
                  {
                    pjxs = StringUtil.getDouble(smsInfo[i][10],2);
                  }
                labelC = new jxl.write.Label(6, i+1, pjxs);
          ws.addCell(labelC);
                labelC = new jxl.write.Label(7, i+1, StringUtil.getDouble(smsInfo[i][23],2));
          ws.addCell(labelC);
                labelC = new jxl.write.Label(8, i+1, StringUtil.getDouble(smsInfo[i][21],2));
          ws.addCell(labelC);
                labelC = new jxl.write.Label(9, i+1, smsInfo[i][22]);
          ws.addCell(labelC);
                labelC = new jxl.write.Label(10, i+1, StringUtil.getDouble(smsInfo[i][25],2));
          ws.addCell(labelC);
                labelC = new jxl.write.Label(11, i+1, StringUtil.getDouble(smsInfo[i][26],2));
          ws.addCell(labelC);
                labelC = new jxl.write.Label(12, i+1, StringUtil.getDouble(smsInfo[i][27],2));
          ws.addCell(labelC);
                labelC = new jxl.write.Label(13, i+1, smsInfo[i][24]);
          ws.addCell(labelC);
                labelC = new jxl.write.Label(14, i+1, smsInfo[i][28]);
          ws.addCell(labelC);
                labelC = new jxl.write.Label(15, i+1, smsInfo[i][18]);
          ws.addCell(labelC);
   }
  }
  //写入Exel工作表
  wwb.write();
  //关闭Excel工作薄对象
  wwb.close();
 }


参考资料:
http://www-128.ibm.com/developerworks/cn/java/l-javaExcel/index.html
posted on 2005-12-29 15:40 渠上月 阅读(375) 评论(0)  编辑  收藏 所属分类: java tips

只有注册用户登录后才能发表评论。


网站导航: