是这样的,我在网页里加了的查询button,并在动态产生了一个table,这个表放在一个Iframe里,怎么才能把这个frame里的table导出为一个excel?
最好有代码。谢谢
14 个解决方案
#1
告诉你个最简单的方法
1.新建个JSP页
2.复制你要导出页的所有代码到新页
3.在<head>前添加<html xmlns="http://www.w3.org/1999/xhtml">
4.在你要导出页通过<a href="test2.jsp">导出到Excel</a>
1.新建个JSP页
2.复制你要导出页的所有代码到新页
3.在<head>前添加<html xmlns="http://www.w3.org/1999/xhtml">
4.在你要导出页通过<a href="test2.jsp">导出到Excel</a>
#2
试过了,好像不行呀,急呀
#3
在数据库里导算了。。。
#4
不会呀,我都是这么做的,绝对好用的
#5
求助呀,高手们,高抬贵手,救一下。急呀
#6
你把从库里查询出来的信息先保存在List里面,然后自己写一个action,把信息的输出格式设置成Excel的形式,把List做为context的一部分加到里面就ok了!
#7
我是菜鸟,我还是不太明白,你 这样是不是要用到BEAN
#8
有个包可以搞定:jxl.jar Apache.org出品
#9
不好意思,这个东西不是apache.org出的。特纠正
给你个下载地址:
A Java library for reading/writing Excel
http://sourceforge.net/project/showfiles.php?group_id=79926
给你个下载地址:
A Java library for reading/writing Excel
http://sourceforge.net/project/showfiles.php?group_id=79926
#10
祝你成功 :
你如果需要详细帮助,可以这里找:
http://jexcelapi.sourceforge.net/
你如果需要详细帮助,可以这里找:
http://jexcelapi.sourceforge.net/
#11
告诉你两个方法,一个是在action里面写方法用poi包,这和一种要自己手动设置excel的显示格式,很麻烦,这里先不说了,如果你想知道,我再发
另一种是用javascript脚本,这一种很简单,但不适合分页
<table width="1165" border="1" id="excelTable" >注意,id不能少
<input name="print" value="导出excel" type="button" onclick="myPrint('excelTable')" />
function myPrint(tableId) {
try {
//alert('a');
var elTable = document.getElementById(tableId);
//alert('b');
var oRangeRef = document.body.createTextRange();
oRangeRef.moveToElementText(elTable);
//alert('c');
oRangeRef.execCommand("Copy");
//alert('d');
var oXL = new ActiveXObject("Excel.Application");
//alert("e");
var oWB = oXL.Workbooks.Add;
var oSheet = oWB.ActiveSheet;
oSheet.Paste();
oXL.Selection.ColumnWidth = 5;
oXL.Selection.RowHeight = 35;// 行高
//oXL.Selection.Rows("<%=rows%>:<%=rows%>").RowHeight = 35; //动态设定单行高度
oXL.Selection.Columns(3).ColumnWidth = 7; //单列设定宽度
oXL.Selection.Columns(5).ColumnWidth = 8; //单列设定宽度
oXL.Visible = true;
oSheet = null;
oWB = null;
appExcel = null;
}
catch (e) {
alert(e.description);
}
另一种是用javascript脚本,这一种很简单,但不适合分页
<table width="1165" border="1" id="excelTable" >注意,id不能少
<input name="print" value="导出excel" type="button" onclick="myPrint('excelTable')" />
function myPrint(tableId) {
try {
//alert('a');
var elTable = document.getElementById(tableId);
//alert('b');
var oRangeRef = document.body.createTextRange();
oRangeRef.moveToElementText(elTable);
//alert('c');
oRangeRef.execCommand("Copy");
//alert('d');
var oXL = new ActiveXObject("Excel.Application");
//alert("e");
var oWB = oXL.Workbooks.Add;
var oSheet = oWB.ActiveSheet;
oSheet.Paste();
oXL.Selection.ColumnWidth = 5;
oXL.Selection.RowHeight = 35;// 行高
//oXL.Selection.Rows("<%=rows%>:<%=rows%>").RowHeight = 35; //动态设定单行高度
oXL.Selection.Columns(3).ColumnWidth = 7; //单列设定宽度
oXL.Selection.Columns(5).ColumnWidth = 8; //单列设定宽度
oXL.Visible = true;
oSheet = null;
oWB = null;
appExcel = null;
}
catch (e) {
alert(e.description);
}
#12
在导出得jsp页面加上
<% response.setContentType("application/vnd.ms-excel;charset=看你是什么环境而定"); %>
<% response.setContentType("application/vnd.ms-excel;charset=看你是什么环境而定"); %>
#13
我在bean里写一个个Static函数,导出的时候,excel能出来,并且没个字段的标题也能出来,但是没有数据库查出的数据,不知是什么原因,麻烦指点一下。
-------------------------------------------------------------------------------------public static void writeExcel(HttpServletRequest request,HttpServletResponse response,String sql,
String main_shop,String branch_shop,String options) throws Exception {
Connection conn=CDataSource.mainDS.getConnection();
Statement stm=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stm.executeQuery(sql);
try{
OutputStream os = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment; filename="+ main_shop+branch_shop+options+ ".xls");
// 开始写入excel
// 加标题
// 标题字体
jxl.write.WritableFont wfc = new jxl.write.WritableFont(
jxl.write.WritableFont.COURIER, 18, jxl.write.WritableFont.NO_BOLD, true);
jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(
wfc);
wcfFC.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
// 字段字体
jxl.write.WritableFont wfc1 = new jxl.write.WritableFont(
jxl.write.WritableFont.COURIER, 10, jxl.write.WritableFont.NO_BOLD, true);
jxl.write.WritableCellFormat wcfFC1 = new jxl.write.WritableCellFormat(
wfc1);
wcfFC1.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
// 结果字体
jxl.write.WritableCellFormat wcfFC2 = new jxl.write.WritableCellFormat();
wcfFC2.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
jxl.write.WritableWorkbook wbook = Workbook.createWorkbook(os);
// 写sheet名称
jxl.write.WritableSheet wsheet= wbook.createSheet("全球通积分查询", 0);
int i = 3;
wsheet.setColumnView(0, 20);
wsheet.setColumnView(1, 30);
wsheet.setColumnView(2, 30);
// 加入字段名
wsheet.addCell(new jxl.write.Label(0, 3, "编号", wcfFC1));
wsheet.addCell(new jxl.write.Label(1, 3, "用户号码", wcfFC1));
wsheet.addCell(new jxl.write.Label(2, 3, "兑换时间", wcfFC1));
wsheet.addCell(new jxl.write.Label(3, 3, "兑换地点", wcfFC1));
wsheet.addCell(new jxl.write.Label(4, 3, "金额", wcfFC1));
wsheet.addCell(new jxl.write.Label(5, 3, "柜台编号", wcfFC1));
// 加入标题
wsheet.mergeCells(0, 0, i - 1, 0);
wsheet.addCell(new jxl.write.Label(0, 0, "全球通积分查询", wcfFC));
// 加入打印时间
// wsheet.addCell(new Label(i - 2, 1, "打印日期:"));
// wsheet.addCell(new Label(i - 1, 1, today));
// 写入流中
StringBuilder XML = new StringBuilder();
int row = 0;
while (rs.next()) {
wsheet.addCell(new jxl.write.Label(0, row + 4, rs.getString("id"), wcfFC2));
wsheet.addCell(new jxl.write.Label(1, row + 4, rs.getString("user_mobile"), wcfFC2));
wsheet.addCell(new jxl.write.Label(2, row + 4, rs.getTimestamp("cash_date").toLocaleString(), wcfFC2));
wsheet.addCell(new jxl.write.Label(3, row + 4, rs.getString("shop_name")+rs.getString("branch_shop"), wcfFC2));
wsheet.addCell(new jxl.write.Label(4, row + 4, rs.getString("cash_amount"), wcfFC2));
wsheet.addCell(new jxl.write.Label(5, row + 4, rs.getString("cash_location_id"), wcfFC2));
row++;
}
wbook.write();
wbook.close();
os.close();
response.setContentType("text/xml;charset=utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
rs.close();
stm.close();
conn.close();
}
}
}
----------------------------------------------------------------------------
不知道是哪里写错了
-------------------------------------------------------------------------------------public static void writeExcel(HttpServletRequest request,HttpServletResponse response,String sql,
String main_shop,String branch_shop,String options) throws Exception {
Connection conn=CDataSource.mainDS.getConnection();
Statement stm=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stm.executeQuery(sql);
try{
OutputStream os = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment; filename="+ main_shop+branch_shop+options+ ".xls");
// 开始写入excel
// 加标题
// 标题字体
jxl.write.WritableFont wfc = new jxl.write.WritableFont(
jxl.write.WritableFont.COURIER, 18, jxl.write.WritableFont.NO_BOLD, true);
jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(
wfc);
wcfFC.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
// 字段字体
jxl.write.WritableFont wfc1 = new jxl.write.WritableFont(
jxl.write.WritableFont.COURIER, 10, jxl.write.WritableFont.NO_BOLD, true);
jxl.write.WritableCellFormat wcfFC1 = new jxl.write.WritableCellFormat(
wfc1);
wcfFC1.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
// 结果字体
jxl.write.WritableCellFormat wcfFC2 = new jxl.write.WritableCellFormat();
wcfFC2.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
jxl.write.WritableWorkbook wbook = Workbook.createWorkbook(os);
// 写sheet名称
jxl.write.WritableSheet wsheet= wbook.createSheet("全球通积分查询", 0);
int i = 3;
wsheet.setColumnView(0, 20);
wsheet.setColumnView(1, 30);
wsheet.setColumnView(2, 30);
// 加入字段名
wsheet.addCell(new jxl.write.Label(0, 3, "编号", wcfFC1));
wsheet.addCell(new jxl.write.Label(1, 3, "用户号码", wcfFC1));
wsheet.addCell(new jxl.write.Label(2, 3, "兑换时间", wcfFC1));
wsheet.addCell(new jxl.write.Label(3, 3, "兑换地点", wcfFC1));
wsheet.addCell(new jxl.write.Label(4, 3, "金额", wcfFC1));
wsheet.addCell(new jxl.write.Label(5, 3, "柜台编号", wcfFC1));
// 加入标题
wsheet.mergeCells(0, 0, i - 1, 0);
wsheet.addCell(new jxl.write.Label(0, 0, "全球通积分查询", wcfFC));
// 加入打印时间
// wsheet.addCell(new Label(i - 2, 1, "打印日期:"));
// wsheet.addCell(new Label(i - 1, 1, today));
// 写入流中
StringBuilder XML = new StringBuilder();
int row = 0;
while (rs.next()) {
wsheet.addCell(new jxl.write.Label(0, row + 4, rs.getString("id"), wcfFC2));
wsheet.addCell(new jxl.write.Label(1, row + 4, rs.getString("user_mobile"), wcfFC2));
wsheet.addCell(new jxl.write.Label(2, row + 4, rs.getTimestamp("cash_date").toLocaleString(), wcfFC2));
wsheet.addCell(new jxl.write.Label(3, row + 4, rs.getString("shop_name")+rs.getString("branch_shop"), wcfFC2));
wsheet.addCell(new jxl.write.Label(4, row + 4, rs.getString("cash_amount"), wcfFC2));
wsheet.addCell(new jxl.write.Label(5, row + 4, rs.getString("cash_location_id"), wcfFC2));
row++;
}
wbook.write();
wbook.close();
os.close();
response.setContentType("text/xml;charset=utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
rs.close();
stm.close();
conn.close();
}
}
}
----------------------------------------------------------------------------
不知道是哪里写错了
#14
大家好,我有个请求,希望你们可以帮我。我现在是想把从数据库查询出来的数据放到list里面,请问怎么导入到excle表中,并实现下载excle;谢谢了啊,定有重谢。
#1
告诉你个最简单的方法
1.新建个JSP页
2.复制你要导出页的所有代码到新页
3.在<head>前添加<html xmlns="http://www.w3.org/1999/xhtml">
4.在你要导出页通过<a href="test2.jsp">导出到Excel</a>
1.新建个JSP页
2.复制你要导出页的所有代码到新页
3.在<head>前添加<html xmlns="http://www.w3.org/1999/xhtml">
4.在你要导出页通过<a href="test2.jsp">导出到Excel</a>
#2
试过了,好像不行呀,急呀
#3
在数据库里导算了。。。
#4
不会呀,我都是这么做的,绝对好用的
#5
求助呀,高手们,高抬贵手,救一下。急呀
#6
你把从库里查询出来的信息先保存在List里面,然后自己写一个action,把信息的输出格式设置成Excel的形式,把List做为context的一部分加到里面就ok了!
#7
我是菜鸟,我还是不太明白,你 这样是不是要用到BEAN
#8
有个包可以搞定:jxl.jar Apache.org出品
#9
不好意思,这个东西不是apache.org出的。特纠正
给你个下载地址:
A Java library for reading/writing Excel
http://sourceforge.net/project/showfiles.php?group_id=79926
给你个下载地址:
A Java library for reading/writing Excel
http://sourceforge.net/project/showfiles.php?group_id=79926
#10
祝你成功 :
你如果需要详细帮助,可以这里找:
http://jexcelapi.sourceforge.net/
你如果需要详细帮助,可以这里找:
http://jexcelapi.sourceforge.net/
#11
告诉你两个方法,一个是在action里面写方法用poi包,这和一种要自己手动设置excel的显示格式,很麻烦,这里先不说了,如果你想知道,我再发
另一种是用javascript脚本,这一种很简单,但不适合分页
<table width="1165" border="1" id="excelTable" >注意,id不能少
<input name="print" value="导出excel" type="button" onclick="myPrint('excelTable')" />
function myPrint(tableId) {
try {
//alert('a');
var elTable = document.getElementById(tableId);
//alert('b');
var oRangeRef = document.body.createTextRange();
oRangeRef.moveToElementText(elTable);
//alert('c');
oRangeRef.execCommand("Copy");
//alert('d');
var oXL = new ActiveXObject("Excel.Application");
//alert("e");
var oWB = oXL.Workbooks.Add;
var oSheet = oWB.ActiveSheet;
oSheet.Paste();
oXL.Selection.ColumnWidth = 5;
oXL.Selection.RowHeight = 35;// 行高
//oXL.Selection.Rows("<%=rows%>:<%=rows%>").RowHeight = 35; //动态设定单行高度
oXL.Selection.Columns(3).ColumnWidth = 7; //单列设定宽度
oXL.Selection.Columns(5).ColumnWidth = 8; //单列设定宽度
oXL.Visible = true;
oSheet = null;
oWB = null;
appExcel = null;
}
catch (e) {
alert(e.description);
}
另一种是用javascript脚本,这一种很简单,但不适合分页
<table width="1165" border="1" id="excelTable" >注意,id不能少
<input name="print" value="导出excel" type="button" onclick="myPrint('excelTable')" />
function myPrint(tableId) {
try {
//alert('a');
var elTable = document.getElementById(tableId);
//alert('b');
var oRangeRef = document.body.createTextRange();
oRangeRef.moveToElementText(elTable);
//alert('c');
oRangeRef.execCommand("Copy");
//alert('d');
var oXL = new ActiveXObject("Excel.Application");
//alert("e");
var oWB = oXL.Workbooks.Add;
var oSheet = oWB.ActiveSheet;
oSheet.Paste();
oXL.Selection.ColumnWidth = 5;
oXL.Selection.RowHeight = 35;// 行高
//oXL.Selection.Rows("<%=rows%>:<%=rows%>").RowHeight = 35; //动态设定单行高度
oXL.Selection.Columns(3).ColumnWidth = 7; //单列设定宽度
oXL.Selection.Columns(5).ColumnWidth = 8; //单列设定宽度
oXL.Visible = true;
oSheet = null;
oWB = null;
appExcel = null;
}
catch (e) {
alert(e.description);
}
#12
在导出得jsp页面加上
<% response.setContentType("application/vnd.ms-excel;charset=看你是什么环境而定"); %>
<% response.setContentType("application/vnd.ms-excel;charset=看你是什么环境而定"); %>
#13
我在bean里写一个个Static函数,导出的时候,excel能出来,并且没个字段的标题也能出来,但是没有数据库查出的数据,不知是什么原因,麻烦指点一下。
-------------------------------------------------------------------------------------public static void writeExcel(HttpServletRequest request,HttpServletResponse response,String sql,
String main_shop,String branch_shop,String options) throws Exception {
Connection conn=CDataSource.mainDS.getConnection();
Statement stm=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stm.executeQuery(sql);
try{
OutputStream os = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment; filename="+ main_shop+branch_shop+options+ ".xls");
// 开始写入excel
// 加标题
// 标题字体
jxl.write.WritableFont wfc = new jxl.write.WritableFont(
jxl.write.WritableFont.COURIER, 18, jxl.write.WritableFont.NO_BOLD, true);
jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(
wfc);
wcfFC.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
// 字段字体
jxl.write.WritableFont wfc1 = new jxl.write.WritableFont(
jxl.write.WritableFont.COURIER, 10, jxl.write.WritableFont.NO_BOLD, true);
jxl.write.WritableCellFormat wcfFC1 = new jxl.write.WritableCellFormat(
wfc1);
wcfFC1.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
// 结果字体
jxl.write.WritableCellFormat wcfFC2 = new jxl.write.WritableCellFormat();
wcfFC2.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
jxl.write.WritableWorkbook wbook = Workbook.createWorkbook(os);
// 写sheet名称
jxl.write.WritableSheet wsheet= wbook.createSheet("全球通积分查询", 0);
int i = 3;
wsheet.setColumnView(0, 20);
wsheet.setColumnView(1, 30);
wsheet.setColumnView(2, 30);
// 加入字段名
wsheet.addCell(new jxl.write.Label(0, 3, "编号", wcfFC1));
wsheet.addCell(new jxl.write.Label(1, 3, "用户号码", wcfFC1));
wsheet.addCell(new jxl.write.Label(2, 3, "兑换时间", wcfFC1));
wsheet.addCell(new jxl.write.Label(3, 3, "兑换地点", wcfFC1));
wsheet.addCell(new jxl.write.Label(4, 3, "金额", wcfFC1));
wsheet.addCell(new jxl.write.Label(5, 3, "柜台编号", wcfFC1));
// 加入标题
wsheet.mergeCells(0, 0, i - 1, 0);
wsheet.addCell(new jxl.write.Label(0, 0, "全球通积分查询", wcfFC));
// 加入打印时间
// wsheet.addCell(new Label(i - 2, 1, "打印日期:"));
// wsheet.addCell(new Label(i - 1, 1, today));
// 写入流中
StringBuilder XML = new StringBuilder();
int row = 0;
while (rs.next()) {
wsheet.addCell(new jxl.write.Label(0, row + 4, rs.getString("id"), wcfFC2));
wsheet.addCell(new jxl.write.Label(1, row + 4, rs.getString("user_mobile"), wcfFC2));
wsheet.addCell(new jxl.write.Label(2, row + 4, rs.getTimestamp("cash_date").toLocaleString(), wcfFC2));
wsheet.addCell(new jxl.write.Label(3, row + 4, rs.getString("shop_name")+rs.getString("branch_shop"), wcfFC2));
wsheet.addCell(new jxl.write.Label(4, row + 4, rs.getString("cash_amount"), wcfFC2));
wsheet.addCell(new jxl.write.Label(5, row + 4, rs.getString("cash_location_id"), wcfFC2));
row++;
}
wbook.write();
wbook.close();
os.close();
response.setContentType("text/xml;charset=utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
rs.close();
stm.close();
conn.close();
}
}
}
----------------------------------------------------------------------------
不知道是哪里写错了
-------------------------------------------------------------------------------------public static void writeExcel(HttpServletRequest request,HttpServletResponse response,String sql,
String main_shop,String branch_shop,String options) throws Exception {
Connection conn=CDataSource.mainDS.getConnection();
Statement stm=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stm.executeQuery(sql);
try{
OutputStream os = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment; filename="+ main_shop+branch_shop+options+ ".xls");
// 开始写入excel
// 加标题
// 标题字体
jxl.write.WritableFont wfc = new jxl.write.WritableFont(
jxl.write.WritableFont.COURIER, 18, jxl.write.WritableFont.NO_BOLD, true);
jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(
wfc);
wcfFC.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
// 字段字体
jxl.write.WritableFont wfc1 = new jxl.write.WritableFont(
jxl.write.WritableFont.COURIER, 10, jxl.write.WritableFont.NO_BOLD, true);
jxl.write.WritableCellFormat wcfFC1 = new jxl.write.WritableCellFormat(
wfc1);
wcfFC1.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
// 结果字体
jxl.write.WritableCellFormat wcfFC2 = new jxl.write.WritableCellFormat();
wcfFC2.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
jxl.write.WritableWorkbook wbook = Workbook.createWorkbook(os);
// 写sheet名称
jxl.write.WritableSheet wsheet= wbook.createSheet("全球通积分查询", 0);
int i = 3;
wsheet.setColumnView(0, 20);
wsheet.setColumnView(1, 30);
wsheet.setColumnView(2, 30);
// 加入字段名
wsheet.addCell(new jxl.write.Label(0, 3, "编号", wcfFC1));
wsheet.addCell(new jxl.write.Label(1, 3, "用户号码", wcfFC1));
wsheet.addCell(new jxl.write.Label(2, 3, "兑换时间", wcfFC1));
wsheet.addCell(new jxl.write.Label(3, 3, "兑换地点", wcfFC1));
wsheet.addCell(new jxl.write.Label(4, 3, "金额", wcfFC1));
wsheet.addCell(new jxl.write.Label(5, 3, "柜台编号", wcfFC1));
// 加入标题
wsheet.mergeCells(0, 0, i - 1, 0);
wsheet.addCell(new jxl.write.Label(0, 0, "全球通积分查询", wcfFC));
// 加入打印时间
// wsheet.addCell(new Label(i - 2, 1, "打印日期:"));
// wsheet.addCell(new Label(i - 1, 1, today));
// 写入流中
StringBuilder XML = new StringBuilder();
int row = 0;
while (rs.next()) {
wsheet.addCell(new jxl.write.Label(0, row + 4, rs.getString("id"), wcfFC2));
wsheet.addCell(new jxl.write.Label(1, row + 4, rs.getString("user_mobile"), wcfFC2));
wsheet.addCell(new jxl.write.Label(2, row + 4, rs.getTimestamp("cash_date").toLocaleString(), wcfFC2));
wsheet.addCell(new jxl.write.Label(3, row + 4, rs.getString("shop_name")+rs.getString("branch_shop"), wcfFC2));
wsheet.addCell(new jxl.write.Label(4, row + 4, rs.getString("cash_amount"), wcfFC2));
wsheet.addCell(new jxl.write.Label(5, row + 4, rs.getString("cash_location_id"), wcfFC2));
row++;
}
wbook.write();
wbook.close();
os.close();
response.setContentType("text/xml;charset=utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
rs.close();
stm.close();
conn.close();
}
}
}
----------------------------------------------------------------------------
不知道是哪里写错了
#14
大家好,我有个请求,希望你们可以帮我。我现在是想把从数据库查询出来的数据放到list里面,请问怎么导入到excle表中,并实现下载excle;谢谢了啊,定有重谢。