JXL-based Excel data import Tool

Source: Internet
Author: User
Tags mysql zip

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 ...");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.