gb2j  123456
package com.madhouse.sys.util;
import java.io.File;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.ResultSet;java连接sqlserver数据库
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import org.apachemons.logging.Log;
import org.apachemons.logging.LogFactory;
sql.jdbc.Connection;
sql.jdbc.Statement;
/**
* <li>°ÑÊý¾Ýµ¼Èëµ½Excel¹«ÓÃÀà</li>
* </br> This is about <code>ExcelUtil</code>
*
* @author hjy273
* @version 1.0
* @date Sep 6, 2008 9:52:52 PM
*/
public class ExcelUtil {
private static Log log = Log(ExcelUtil.class);
public ExcelUtil() {
}
public boolean DB2Excel(ResultSet rs) {
boolean flag = false;
WritableWorkbook workbook = null;
WritableSheet sheet = null;
Label label = null;
// ´´½¨Excel±í
try {
workbook = ateWorkbook(new File("e:/_report/output.csv"));
//workbook = ateWorkbook(os);
// ´´½¨Excel±íÖеÄsheet
sheet = ateSheet("First Sheet", 0);
// ÏòExcelÖÐÌí¼ÓÊý¾Ý
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = ColumnCount();
String colName = null;
int row = 0;
// Ìí¼Ó±êÌâ
for (int i = 0; i < columnCount; i++) {
colName = ColumnName(i + 1);
label = new Label(i, row, colName);
// log.debug("±êÌâ:"+i+"---"+row +"---"+ colName);
sheet.addCell(label);
}
row++;
log.debug("дÈë±êÌâ³É¹¦");
while (rs.next()) {
for (int i = 0; i < columnCount; i++) {
label = new Label(i, row, rs.getString(i + 1));
log.debug("ÐÐ:"+i+"---"+row +"---"+ rs.getString(i+1));
sheet.addCell(label);
}
row++;
}
log.debug("дÈëÄÚÈݳɹ¦");
// ¹Ø±ÕÎļþ
workbook.write();
workbook.close();
log.info("Êý¾Ý³É¹¦Ð´ÈëExcel");
flag = true;
} catch (SQLException e) {

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。