Write this thing is mainly in the previous period of time projects have similar needs, feel that the import of Excel is a relatively common function, so a simple encapsulation;
function Introduction:
1. A simple tool to use JXL to import Excel;
2. Data set access to support JDBC, internal use of the record to build two;
3. Only support the import of character type, numeric type, date type data;
The jar in the attachment can be used for direct use, the jar contains the source code, the zip includes a demo of the various import methods, and the zip contains the jars and Jxl.jar required by JDBC.
You can also click http://sites.google.com/site/gwikimo/to download
Example:
(i) using the JDBC approach
Java code
Package Org.wiki.excel.demo;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Java.sql.ResultSet;
Import java.sql.Statement;
Import Org.wiki.excel.core.ExcelUtil;
/***
*
* @de scription JDBC-based approach
* @author WIKI.M
* @date 2009-08-20
*
*/
public class Test4 {
public static void Main (string[] args) throws exception{
Class.forName ("Com.mysql.jdbc.Driver");
Connection conn = drivermanager.getconnection ("Jdbc:mysql://localhost:3306/test", "root", "wiki");
Statement st = Conn.createstatement ();
ResultSet rs = st.executequery ("SELECT * from user");
Excel Title Column
String[] FieldName = {"Serial number", "Name", "Age", "Telephone number", "Address", "date of Birth"};
Whether to display the corresponding Excel header columns
Boolean[] Isdisplay = {False,true,false,true,false,true};
Set column width
Int[] Columnview ={20,40,20,20,40,40};
Excelutil.exoprttoexcel ("F:/export4.xls", RS, Fieldname,isdisplay,columnview);
Rs.close ();
St.close ();
Conn.close ();
SYSTEM.OUT.PRINTLN ("Export Successful ...");
}
}