posts - 0,  comments - 5,  trackbacks - 0
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

留言簿(1)

我参与的团队

文章分类

文章档案

相册

http://www.blogjava.net/beansoft

搜索

  •  

最新评论

要用到poi-2.5.1-final-20040804.jar包

 1 import  java.io.FileOutputStream;
 2 import  java.sql.Connection;
 3 import  java.sql.ResultSet;
 4 import  java.sql.ResultSetMetaData;
 5
 6 import  org.apache.poi.hssf.usermodel.HSSFCell;
 7 import  org.apache.poi.hssf.usermodel.HSSFRow;
 8 import  org.apache.poi.hssf.usermodel.HSSFSheet;
 9 import  org.apache.poi.hssf.usermodel.HSSFWorkbook;
10 import  org.dom4j.Document;
11 import  org.dom4j.Element;
12
13 import  wufalong.exportServer.ConnectBean;
14 import  wufalong.exportServer.CreateConnection;
15 import  wufalong.exportServer.GetResultSet;
16 import  wufalong.exportServer.LoadRootElementByConfigFile;
17 import  exportxls.JsUserBasicData;
18
19 public   class  Person20070517
20 {
21    public   static   void  main(String args[]) 
22    {
23       Person20070517 c = new  Person20070517();
24        int  allcount = 0 ;
25       allcount = allcount + c.createPersonMobile( " c:/人才.xls " );
26   }

27   
28    public   int  createPersonMobile(String filename)
29    {
30       Connection con  =   null ;
31       ResultSet rs  =   null ;
32       Document doc  =  LoadRootElementByConfigFile.getRootElement();
33       Element e  =  doc.getRootElement().element( " import " );
34        try
35        {
36             con  =  CreateConnection.getConnect(e);
37             rs  =  GetResultSet.getResule(con,ConnectBean.getSql(e));
38           FileOutputStream fOut  =   null ;
39           HSSFWorkbook workbook  =   new  HSSFWorkbook();
40           HSSFSheet sheet  =  workbook.createSheet();
41           HSSFRow row  =   null ;
42           HSSFCell cell  =   null ;
43            int  i  =   1 ;
44            int  writeadd  =   0 ;
45           String  cellvalue  =   "" ;
46           JsUserBasicData jub  =   new  JsUserBasicData();
47           row  =  sheet.createRow( 0 );
48           cell  =  row.createCell(( short 0 );
49           cell.setCellType(HSSFCell.CELL_TYPE_STRING);
50           cell.setEncoding(HSSFCell.ENCODING_UTF_16);
51           cell.setCellValue( " 姓名 " );
52           cell  =  row.createCell(( short 1 );
53           cell.setCellType(HSSFCell.CELL_TYPE_STRING);
54           cell.setEncoding(HSSFCell.ENCODING_UTF_16);
55           cell.setCellValue( " 手机 " );
56           
57            while  (rs.next())  {
58
59               System.out.println( " 正在生成第 "   +  i  +   " 条记录 " );
60               ResultSetMetaData rsmd  =  rs.getMetaData();
61               row  =  sheet.createRow(( short ) i);
62                int  colcount  =  rsmd.getColumnCount();
63                for  ( int  icc  =   0 ; icc  <  colcount; icc ++ {
64                   cellvalue  =  rs.getString(icc  +   1 ); 
65                   cell  =  row.createCell(( short ) icc);
66                   System.out.println( " md: "   +  cellvalue); 
67                   cell.setCellType(HSSFCell.CELL_TYPE_STRING);
68                   cell.setEncoding(HSSFCell.ENCODING_UTF_16);
69                   cell.setCellValue(cellvalue);
70               }

71               i ++ ;
72           }

73
74           fOut  =   new  FileOutputStream(filename);
75           workbook.write(fOut);
76           fOut.flush();
77           fOut.close();
78           System.out.println(filename  +   " 文件生成 "   +  i  +   " " );
79           rs.close();
80           rs  =   null ;
81           con.close();
82           con  =   null ;
83            return  i;
84       }
  catch  (Exception ee) 
85        {
86               System.out.println( " 發生了 "   +  ee.getMessage()  +   " 例外 " );
87       }
 
88        finally  
89        {
90               GetResultSet.closeResultSet(rs);
91               CreateConnection.closeConnect(con);
92       }

93       return   0 ;
94   }

95 }

96
posted on 2007-09-03 13:56 crazy 阅读(1785) 评论(0)  编辑  收藏 所属分类: java

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


网站导航: