jxl导入数据到EXCEL
2012-06-29 09:19
513 查看
1.发送指令jsp页面
2.请求后台处理页面
3.后台处理页面
编辑完以上代码,修改一下后台的数据库连接就可以使用啦,很方便很强大的。
<html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>Alarm Report</title> <script type="text/javascript"> function ajaxSubmit(){ window.open("/rmcs/alarmOutputToExcel.jsp",'', 'menubar=yes, location=yes, toolbar=yes, status=no, titlebar=no, resizable=yes, height=430px, width=650px, top='+(screen.height-430)/2+'px, left='+(screen.width-650)/2+'px'); } </script> </head> <body> <input type="button" onclick="ajaxSubmit()" value="button" /> </body> </html>
2.请求后台处理页面
<%@ page contentType="text/html; charset=UTF-8" %> <%@ page import="servlet.CASAlertReport"%> <% try { CASAlertReport.outputExcel(request, response); } catch (Exception e) { e.printStackTrace(); } %>
3.后台处理页面
package servlet; /**数据库应用包*/ import com.db.Database; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; /**servlet应用包*/ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /**jxl应用包*/ import jxl.Workbook; import jxl.WorkbookSettings; import jxl.format.Alignment; import jxl.format.Colour; import jxl.format.UnderlineStyle; import jxl.write.Label; import jxl.write.WritableCellFormat; import jxl.write.WritableFont; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; public class CASAlertReport { public static void outputExcel(HttpServletRequest request, HttpServletResponse response) throws Exception { WritableWorkbook wwb = null; try{ response.reset(); response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("UTF-8"); /**设置导出报表的文件名称*/ response.setHeader("Content-disposition","attachment; filename=Alarm Report - By Device.xls"); WorkbookSettings workbookSettings = new WorkbookSettings(); workbookSettings.setEncoding("iso-8859-1"); wwb = Workbook.createWorkbook(response.getOutputStream(), workbookSettings); wwb.createSheet("Alarm Report", 10); WritableSheet wsSummary = wwb.getSheet("Alarm Report"); /**设置报表内容的字体样式*/ WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLUE); wsSummary.setRowView(1, 500); // Report Title WritableCellFormat wcf = new WritableCellFormat(wf); wcf.setAlignment(Alignment.LEFT); WritableCellFormat wcf_r = new WritableCellFormat(wf); wcf_r.setAlignment(Alignment.RIGHT); wsSummary.setColumnView(0, 30); wsSummary.setColumnView(1, 30); wsSummary.setColumnView(2, 30); wsSummary.setColumnView(3, 30); int rw = 7; wsSummary.addCell(new Label(0, rw - 1, "Severity", wcf)); wsSummary.addCell(new Label(1, rw - 1, "Platform", wcf)); wsSummary.addCell(new Label(2, rw - 1, "No. of Acked Alarms", wcf_r)); wsSummary.addCell(new Label(3, rw - 1, "No. of Unacked Alarms", wcf_r)); rw++; Database db = new Database(); String sql = "select * from vehicle"; ResultSet rs = db.getResultSet(sql); while (rs.next()) { wsSummary.addCell(new Label(0, rw - 1, rs.getString("license"), wcf)); wsSummary.addCell(new Label(1, rw - 1, rs.getString("IMEI"), wcf)); wsSummary.addCell(new Label(2, rw - 1, rs.getString("color"), wcf)); wsSummary.addCell(new Label(3, rw - 1, rs.getString("brand"), wcf)); rw ++; } wwb.write(); wwb.close(); } catch(Exception e){ e.printStackTrace(); return; } } }
编辑完以上代码,修改一下后台的数据库连接就可以使用啦,很方便很强大的。
相关文章推荐
- 基于JXL的Excel数据导入工具
- java中jxl将数据库中的数据导入到excel中
- jxl 从excel导入数据到数据库中;java中jdbc连接数据库
- Java 使用jxl.jar 导入导出Excel数据
- java中jxl将excel中的数据导入到数据库中
- 使用JXl实现excel数据的导入,读取数据
- 在jxl.jar包下把excel内容导入到数据库
- 用jxl导入报表Excel数据,如果excel是日期格式的话需要减去8小时
- jxl导入excel数据时的问题
- 用jxl将Excel中的数据导入功能的一个问题
- JXL将excel的数据导入到数据库
- jxl将数据导入,导出excel
- 利用JXLReadUtil工具将Excel数据导入到properties文件中
- 利用jxl向Excel中导入数据示例代码
- json文件 数据导入excel----->(jxl)
- Oracle导入excel数据方法汇总
- 使EXCEL中使用宏生成T-SQL实现数据导入
- Excel中强大的数据导入功能
- JAVA Excel数据批量导入到SQL数据库
- 将Excel中的数据导入到表中