当前位置: 技术问答>java相关
############## 在Jsp,JavaBean的信息管理系统中,如何实现数据库表中记录导出到Excel表中? ################
来源: 互联网 发布时间:2015-05-13
本文导语: 在Jsp,JavaBean的信息管理系统中如何实现数据库表中记录导出到Excel表中? | package com.tiptopone.game.turnbased.boardcast.bmp2wbmp; /** * Title: * Description: * Copyright: Copyright (c) 2002 * Company: ...
在Jsp,JavaBean的信息管理系统中如何实现数据库表中记录导出到Excel表中?
|
package com.tiptopone.game.turnbased.boardcast.bmp2wbmp;
/**
*
*
*
*
* @author unascribed
* @version 1.0
*/
import java.sql.*;
public class Wfb {
public Wfb() {
}
public static void m()
{
//load the driver
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//define the database source
String sourceurl=new String("jdbc:odbc:wfb");
//create connection
System.out.println("creat success!");
Connection dataconnection=DriverManager.getConnection(sourceurl);
//create stetement
System.out.println("connected success!");
Statement statement=dataconnection.createStatement();
//查询结果
ResultSet username=statement.executeQuery("SELECT a,b FROM wj");
while(username.next())
{
System.out.println(username.getString("a")+":read successful!"+username.getString("b"));
}
}
catch(ClassNotFoundException e)
{
System.out.println("错误:"+e);
}
catch(SQLException e)
{
System.out.println("错误:"+e);
}
}
}
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @author unascribed
* @version 1.0
*/
import java.sql.*;
public class Wfb {
public Wfb() {
}
public static void m()
{
//load the driver
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//define the database source
String sourceurl=new String("jdbc:odbc:wfb");
//create connection
System.out.println("creat success!");
Connection dataconnection=DriverManager.getConnection(sourceurl);
//create stetement
System.out.println("connected success!");
Statement statement=dataconnection.createStatement();
//查询结果
ResultSet username=statement.executeQuery("SELECT a,b FROM wj");
while(username.next())
{
System.out.println(username.getString("a")+":read successful!"+username.getString("b"));
}
}
catch(ClassNotFoundException e)
{
System.out.println("错误:"+e);
}
catch(SQLException e)
{
System.out.println("错误:"+e);
}
}
}
|
http://jakarta.apache.org/poi/hssf/how-to.html
short rownum;
// create a new file
FileOutputStream out = new FileOutputStream("workbook.xls");
// create a new workbook
HSSFWorkbook wb = new HSSFWorkbook();
// create a new sheet
HSSFSheet s = wb.createSheet();
// declare a row object reference
HSSFRow r = null;
// declare a cell object reference
HSSFCell c = null;
// create 3 cell styles
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
HSSFCellStyle cs3 = wb.createCellStyle();
// create 2 fonts objects
HSSFFont f = wb.createFont();
HSSFFont f2 = wb.createFont();
//set font 1 to 12 point type
f.setFontHeightInPoints((short) 12);
//make it red
f.setColor((short) HSSFCellStyle.RED);
// make it bold
//arial is the default font
f.setBoldweight(f.BOLDWEIGHT_BOLD);
//set font 2 to 10 point type
f2.setFontHeightInPoints((short) 10);
//make it the color at palette index 0xf (white)
f2.setColor((short) HSSFCellStyle.WHITE);
//make it bold
f2.setBoldweight(f2.BOLDWEIGHT_BOLD);
//set cell stlye
cs.setFont(f);
//set the cell format see HSSFDataFromat for a full list
cs.setDataFormat(HSSFDataFormat.getFormat("($#,##0_);[Red]($#,##0)"));
//set a thin border
cs2.setBorderBottom(cs2.BORDER_THIN);
//fill w fg fill color
cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
// set foreground fill to red
cs2.setFillForegroundColor((short) HSSFCellStyle.RED);
// set the font
cs2.setFont(f2);
// set the sheet name to HSSF Test
wb.setSheetName(0, "HSSF Test");
// create a sheet with 300 rows (0-299)
for (rownum = (short) 0; rownum
short rownum;
// create a new file
FileOutputStream out = new FileOutputStream("workbook.xls");
// create a new workbook
HSSFWorkbook wb = new HSSFWorkbook();
// create a new sheet
HSSFSheet s = wb.createSheet();
// declare a row object reference
HSSFRow r = null;
// declare a cell object reference
HSSFCell c = null;
// create 3 cell styles
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
HSSFCellStyle cs3 = wb.createCellStyle();
// create 2 fonts objects
HSSFFont f = wb.createFont();
HSSFFont f2 = wb.createFont();
//set font 1 to 12 point type
f.setFontHeightInPoints((short) 12);
//make it red
f.setColor((short) HSSFCellStyle.RED);
// make it bold
//arial is the default font
f.setBoldweight(f.BOLDWEIGHT_BOLD);
//set font 2 to 10 point type
f2.setFontHeightInPoints((short) 10);
//make it the color at palette index 0xf (white)
f2.setColor((short) HSSFCellStyle.WHITE);
//make it bold
f2.setBoldweight(f2.BOLDWEIGHT_BOLD);
//set cell stlye
cs.setFont(f);
//set the cell format see HSSFDataFromat for a full list
cs.setDataFormat(HSSFDataFormat.getFormat("($#,##0_);[Red]($#,##0)"));
//set a thin border
cs2.setBorderBottom(cs2.BORDER_THIN);
//fill w fg fill color
cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
// set foreground fill to red
cs2.setFillForegroundColor((short) HSSFCellStyle.RED);
// set the font
cs2.setFont(f2);
// set the sheet name to HSSF Test
wb.setSheetName(0, "HSSF Test");
// create a sheet with 300 rows (0-299)
for (rownum = (short) 0; rownum