Using java to explain how to export data to an excel file:
Download the latest JExcelApi and place jxl. jar in your classpath.
Write a javaBean file and use JExcelApi to dynamically generate an excel file. Here I will write a simple and schematic file. Complex, you may need to query the database or something.
// Test. java
Package com. jarie. test;
Import java. io .*;
Import jxl .*;
Import jxl. write .*;
Import jxl. format .*;
Import java. util .*;
Import java. awt. Color;
Public class Test {
Public static void writeExcel (OutputStream OS) throws Exception {
Jxl. write. WritableWorkbook wwb = Workbook. createWorkbook (OS );
Jxl. write. WritableSheet ws = wwb. createSheet ("TestSheet1", 0 );
Jxl. write. Label labelC = new jxl. write. Label (0, 0, "I love China ");
Ws. addCell (labelC );
Jxl. write. WritableFont wfc = new jxl. write. WritableFont (WritableFont. ARIAL, 20, WritableFont. BOLD, false,
UnderlineStyle. NO_UNDERLINE, jxl. format. Colour. GREEN );
Jxl. write. WritableCellFormat wcfFC = new jxl. write. WritableCellFormat (wfc );
WcfFC. setBackground (jxl. format. Colour. RED );
LabelC = new jxl. write. Label (6, 0, "", wcfFC );
Ws. addCell (labelC );
// Write the Exel Worksheet
Wwb. write ();
// Close the Excel worksheet object
Wwb. close ();
}
// It is best to write such a main method to test whether your class has been written.
Public static void main (String [] args) throws Exception {
File f = new File ("kk.xls ");
F. createNewFile ();
WriteExcel (new FileOutputStream (f ));
}
}
Write a jsp file to use the Test javabean to output the excel file.
// Test_excel.jsp
<Href = "mailto: % @ page"> % @ page import = "com. jarie. test. Test" %>
<%
Response. reset ();
Response. setContentType ("application/vnd. ms-excel ");
Test. writeExcel (response. getOutputStream ());
%>
Then, you can access test_excel.jsp with ie to open the dynamically generated excel file in ie.