Development environment: Windows2000, Tomcat5.0, SQL2000
Ready to work:
Add a database driver package and a jxl.jar package into a virtual directory / web-inf / lib directory
Configure a database connection pool in a server.xml file (omitted other articles)
BEAN Writing a BEAN for the Database (all the operations of the package to DB.) Here you focus on how to use the JXL package to operate.
This example is to take personal information from the database and write an Excel file. My write Excel file code is as follows:
Public void WriteExcel (OutputStream OS) throws exception {
// Create a writable Excel work
JXL.WRITE.WRITABLEWORK WWB = Workbook.createworkbook (OS);
// Create a page of work, named IndividualInfo,
JXL.WRITE.WRITABLESHEET WS = WWB.CREATESHEET ("IndividualInfo", 0);
/ / Determine the title string title [] = {"ID", "Name", "Phone" and "Account"};
// Cycle write title, defined as 14 characters, bold
for (int i = 0; i
// This will use an internal method to take the information of the database, and the information obtained is placed in a Vector object.
Vector vector = this.GetIndividualInfo (); // getindividualInfo () Everyone is done
// Individual includes user ID, name, phone, account, all Individual objects exists in a vector // Traversing this vector, here is a value object called Individual, package all personal information for (INT i = 0, j = 0; i This bean calls in JSP, the code is as follows: <% @ page import = "com.bank.textexcel"%> <% response.reset (); respternse.setContentType ("Application / VND.MS-Excel"); TextExcel obj = new textexcel (); obj.writeExcel Response.getOutputStream ());%> Here you should set the content type to: Application / VND.MS-Excel After the above steps, you can successfully write the database data to the Excel file. When you open the JSP file, you can save this Excel file directly, or you can open them directly in your browser.