锘??xml version="1.0" encoding="utf-8" standalone="yes"?>蜜桃999成人看片在线观看,韩国精品一区,久久国产一二区http://www.aygfsteel.com/fl1429/category/38078.htmlJava,Ruby,Php,Flex,Ajax,UI,Google,Linux...................zh-cnTue, 02 Jun 2009 09:55:32 GMTTue, 02 Jun 2009 09:55:32 GMT60Java 鍒╃敤poi鎶婃暟鎹簱涓暟鎹鍏xcelhttp://www.aygfsteel.com/fl1429/archive/2009/05/26/278064.htmlfl1429fl1429Tue, 26 May 2009 10:12:00 GMThttp://www.aygfsteel.com/fl1429/archive/2009/05/26/278064.htmlhttp://www.aygfsteel.com/fl1429/comments/278064.htmlhttp://www.aygfsteel.com/fl1429/archive/2009/05/26/278064.html#Feedback0http://www.aygfsteel.com/fl1429/comments/commentRss/278064.htmlhttp://www.aygfsteel.com/fl1429/services/trackbacks/278064.html鏁堟灉:

image

浣跨敤鏃跺厛鎶妏oi鍖呭鍏ュ伐紼嬬殑path,娉ㄦ剰鍙渶瑕佸鍏oi鍖呭嵆鍙?涓嬭澆鍚庢湁涓変釜jar鍖?/p>

鏍稿績浠g爜:

榪炴帴鏁版嵁搴?DBConnection.java

package org.xg.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBConnection {
private final String DBUrl = "jdbc:mysql://localhost:3306/notebook" ;
private final String DBDriver = "com.mysql.jdbc.Driver" ;
private final String username = "root" ;
private final String password = "riskfitfeng" ;
private Connection con ;
public DBConnection()
{
try {
Class.forName(DBDriver) ;
con = DriverManager.getConnection(DBUrl,username,password) ;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Connection getDB()
{
return con ;
}
public void closeDb(ResultSet rs,PreparedStatement ps)
{
if(rs!=null)
{
try {
rs.close() ;
} catch (SQLException e) {
// TODO Auto-generated catch block

e.printStackTrace(); } }
if(ps!=null) { try { ps.close() ; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }

瀵煎叆excel綾?MySql2Excel.java

package org.xg.db;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class MySql2Excel {
public MySql2Excel() throws Exception
{
Connection con = null ;
DBConnection db = new DBConnection() ;
con = db.getDB() ;
String sql = "select * from students" ;
ResultSet rs = con.createStatement().executeQuery(sql) ;
// 鑾峰彇鎬誨垪鏁?
int CountColumnNum = rs.getMetaData().getColumnCount() ;
int i = 1 ;
// 鍒涘緩Excel鏂囨。
HSSFWorkbook wb = new HSSFWorkbook() ;
// sheet 瀵瑰簲涓涓伐浣滈〉
HSSFSheet sheet = wb.createSheet("student琛ㄤ腑鐨勬暟鎹?/span>") ;
HSSFRow firstrow = sheet.createRow(0); //涓嬫爣涓?鐨勮寮濮?
HSSFCell[] firstcell = new HSSFCell[CountColumnNum];
String[] names = new String[CountColumnNum];
names[0] = "ID";
names[1] = "瀛﹀彿";
names[2] = "濮撳悕";
names[3] = "鎬у埆";
names[4] = "鐝駭";
for(int j= 0 ;j<CountColumnNum; j++){
firstcell[j] = firstrow.createCell((short)j);
firstcell[j].setCellValue(new HSSFRichTextString(names[j]));
}
while(rs.next())
{
// 鍒涘緩鐢靛瓙琛ㄦ牸鐨勪竴琛?
HSSFRow row = sheet.createRow(i) ; // 涓嬫爣涓?鐨勮寮濮?
for(int j=0;j<CountColumnNum;j++)
{
// 鍦ㄤ竴琛屽唴寰幆
HSSFCell cell = row.createCell((short) j) ;
// 璁劇疆琛ㄦ牸鐨勭紪鐮侀泦錛屼嬌鏀寔涓枃
//
// 鍏堝垽鏂暟鎹簱涓殑鏁版嵁綾誨瀷
// 灝嗙粨鏋滈泦閲岀殑鍊兼斁鍏ョ數瀛愯〃鏍間腑
cell.setCellValue(new HSSFRichTextString(rs.getString(j+1))) ;
}
i++ ;
}
// 鍒涘緩鏂囦歡杈撳嚭嫻侊紝鍑嗗杈撳嚭鐢靛瓙琛ㄦ牸
OutputStream out = new FileOutputStream("E:\\person.xls") ;
wb.write(out) ;
out.close() ;
System.out.println("鏁版嵁搴撳鍑烘垚鍔?/span>") ;
rs.close() ;
con.close() ;
}
public static void main(String[] args)
{
try {
@SuppressWarnings("unused")
MySql2Excel excel = new MySql2Excel() ;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

渚嬪浣犲彲浠ュ湪鍓嶇jsp涓繖鏍瘋皟鐢?

<a href="ReportServlet" onclick="return confirm('紜鏁版嵁瀵煎嚭鍒癊:/涓?');">瀵煎嚭鏁版嵁鍒癊xcel</a>

鍚庡彴servlet鍐欎笂涓婇潰鐨勪唬鐮?娉ㄦ剰鏈鍚庨渶瑕乺esponse.sendRedirect("") 榪斿洖鍓嶇

 

婧愮爜涓嬭澆:

http://www.namipan.com/d/98cf9d03ab8f39ce3c107bb5b44b642dcb3ba581382a1400

poi鍖呬笅杞?

http://www.namipan.com/d/e0493749dd5e3a1f2e28a0a32493e5e026fae4aa1ac69c00



fl1429 2009-05-26 18:12 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 龙泉市| 石泉县| 吉林省| 启东市| 扎鲁特旗| 扎囊县| 淮南市| 安远县| 仁怀市| 鹿泉市| 临武县| 大邑县| 永宁县| 库尔勒市| 吉林省| 内丘县| 循化| 建德市| 象山县| 前郭尔| 仁怀市| 平顶山市| 穆棱市| 房产| 榕江县| 上栗县| 阿克陶县| 天等县| 乌海市| 昭苏县| 莱州市| 浙江省| 贡嘎县| 阿尔山市| 罗山县| 略阳县| 大埔区| 象山县| 庆元县| 蚌埠市| 奉新县|