response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition","attachment; filename=MyExcel.xls");
我在jsp中加上前的两行代码,数据是导出来了,可是没有格式,背景是白色的一片,请问如
把Excel中的表格线显示出来,谢谢!
response.setHeader("Content-disposition","attachment; filename=MyExcel.xls");
我在jsp中加上前的两行代码,数据是导出来了,可是没有格式,背景是白色的一片,请问如
把Excel中的表格线显示出来,谢谢!
解决方案 »
- 了解一下java新技术,问下现在什么框架比较适合处理大量数据量
- hibernate有关query接口的一个问题
- struts2一次请求执行action里的二个方法
- 各位英语基础好的同仁请帮帮忙翻译一下有于J2EE1.4、JSTL与xml的文档,小女子不胜感激!
- axis用户验证求教
- 关于字符串反转的问题
- ■■请问怎么样在Application里调用Tomcat5.0.28创建的连接池?
- 一个jsp 注册的小问题
- iis+resin下如果需要调用javabean的问题
- 关于用jdbc oci驱动jdbc thin驱动连数据库的问题
- 数据插入过多就会出现蓝屏
- 网站数据全站静态化。数据库是压力轻了。但是产生了大量.html
但是只适合于IE内核的浏览器<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>将Web页面中的数据导出到Excel</title>
<link href="CSS/style.css" rel="stylesheet">
</head><body>
<form name="form1" method="post" action="">
<table width="540" height="343" border="0" align="center" cellspacing="0" background="main.gif" >
<tr align="center">
<td width="42" height="56" align="right" valign="bottom"><img src="add.gif" width="20" height="18"></td>
<td width="243" height="56" align="left" valign="bottom" id="doctitle"> 2007年1月份工资报表</td>
<td width="249" align="left" valign="bottom"> </td>
</tr>
<tr align="center">
<td height="24" colspan="3"> </td>
</tr>
<tr align="center">
<td colspan="3" valign="top">
<table width="90%" border="0" cellspacing="1" bgcolor="#000000" id="wage">
<tr>
<td width="79" height="27" align="center" bgcolor="#efefef">员工名称</td>
<td width="69" align="center" bgcolor="#efefef">奖金</td>
<td width="104" align="center" bgcolor="#efefef">基本工资</td>
<td width="63" align="center" bgcolor="#efefef">津贴</td>
<td width="57" align="center" bgcolor="#efefef">扣除</td>
<td width="93" align="center" bgcolor="#efefef">实发工资</td>
</tr>
<tr>
<td width="79" height="27" align="center" bgcolor="#FFFFFF">wgh</td>
<td width="69" align="center" bgcolor="#FFFFFF">200</td>
<td width="104" align="center" bgcolor="#FFFFFF">1800</td>
<td width="63" align="center" bgcolor="#FFFFFF">300</td>
<td width="57" align="center" bgcolor="#FFFFFF">0</td>
<td width="93" align="center" bgcolor="#FFFFFF">2300</td>
</tr>
<tr>
<td width="79" height="27" align="center" bgcolor="#FFFFFF">sk</td>
<td width="69" align="center" bgcolor="#FFFFFF">100</td>
<td width="104" align="center" bgcolor="#FFFFFF">2100</td>
<td width="63" align="center" bgcolor="#FFFFFF">210</td>
<td width="57" align="center" bgcolor="#FFFFFF">5</td>
<td width="93" align="center" bgcolor="#FFFFFF">2405</td>
</tr>
<tr>
<td width="79" height="27" align="center" bgcolor="#FFFFFF">春</td>
<td width="69" align="center" bgcolor="#FFFFFF">70</td>
<td width="104" align="center" bgcolor="#FFFFFF">1700</td>
<td width="63" align="center" bgcolor="#FFFFFF">100</td>
<td width="57" align="center" bgcolor="#FFFFFF">10</td>
<td width="93" align="center" bgcolor="#FFFFFF">1860</td>
</tr>
<tr>
<td width="79" height="27" align="center" bgcolor="#FFFFFF">夏</td>
<td width="69" align="center" bgcolor="#FFFFFF">100</td>
<td width="104" align="center" bgcolor="#FFFFFF">1900</td>
<td width="63" align="center" bgcolor="#FFFFFF">100</td>
<td width="57" align="center" bgcolor="#FFFFFF">20</td>
<td width="93" align="center" bgcolor="#FFFFFF">2080</td>
</tr>
<tr>
<td width="79" height="27" align="center" bgcolor="#FFFFFF">秋</td>
<td width="69" align="center" bgcolor="#FFFFFF">150</td>
<td width="104" align="center" bgcolor="#FFFFFF">1600</td>
<td width="63" align="center" bgcolor="#FFFFFF">100</td>
<td width="57" align="center" bgcolor="#FFFFFF">0</td>
<td width="93" align="center" bgcolor="#FFFFFF">1850</td>
</tr>
<tr>
<td width="79" height="27" align="center" bgcolor="#FFFFFF">冬</td>
<td width="69" align="center" bgcolor="#FFFFFF">200</td>
<td width="104" align="center" bgcolor="#FFFFFF">1500</td>
<td width="63" align="center" bgcolor="#FFFFFF">100</td>
<td width="57" align="center" bgcolor="#FFFFFF">0</td>
<td width="93" align="center" bgcolor="#FFFFFF">1800</td>
</tr>
</table>
<p align="center"><a href="#" onClick="outExcel();">导出到Excel</a></p>
</td>
</tr>
</table>
</form>
</body>
</html>
<script language="javascript">
function outExcel(){
var table=document.all.wage;
row=table.rows.length;
column=table.rows(1).cells.length;
var excelapp=new ActiveXObject("Excel.Application");
excelapp.visible=true;
objBook=excelapp.Workbooks.Add(); //添加新的工作簿
var objSheet = objBook.ActiveSheet; title=objSheet.Range("D1").MergeArea; //合并单元格
title.Cells(1,0).Value =doctitle.innerHTML.replace(" ",""); //输出标题
title.Cells(1,1).Font.Size =16;
for(i=1;i<row+1;i++){
for(j=0;j<column;j++){
objSheet.Cells(i+1,j+1).value=table.rows(i-1).cells(j).innerHTML.replace(" ","");
}
}
excelapp.UserControl = true;
}
</script>
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class FilePOIHSSFExecl { public void write(Reserve reserve_obj,List<ReserveDetail> reserveDtlList) throws IOException { HSSFWorkbook wb = new HSSFWorkbook();
//建立新的SHEET
HSSFSheet sheet = wb.createSheet("new sheet");
//订单编号:(内容) 订单内容:(**)
HSSFRow row = sheet.createRow((short)0);
row.createCell((short)0).setCellValue("订单编号"); row.createCell((short)1).setCellValue(reserve_obj.订单编号); row.createCell((short)2).setCellValue("订单内容"); row.createCell((short)3).setCellValue(reserve_obj.订单内容); //订单时间:(**) HSSFRow row2 = sheet.createRow((short)1); row2.createCell((short)0).setCellValue("订单时间"); row2.createCell((short)1).setCellValue(reserve_obj.订单时间); /* 订单详情编号 订单的时间 订单的什么什么的 内容 内容 内容 内容 内容 内容 */ //设置标题 HSSFRow row_dtl_title = sheet.createRow((short)2); row_dtl_title.createCell((short)0).setCellValue("订单详情编号"); row_dtl_title.createCell((short)1).setCellValue("订单的时间"); row_dtl_title.createCell((short)2).setCellValue("订单的什么什么的"); int line = 3; for (Iterator iter = list.iterator(); iter.hasNext(); ) { line++; ReserveDetail 订单详情 = iter.next(); if(订单详情 == null)continue; HSSFRow row_dtlvalue = sheet.createRow((short)line); row_dtlvalue.createCell((short)0).setCellValue(订单详情.订单详情编号); row_dtlvalue.createCell((short)1).setCellValue(订单详情.订单的时间); row_dtlvalue.createCell((short)2).setCellValue(订单详情.订单的什么什么的); } //inResponse.setHeader("Content-Disposition","inline; filename="+filename.toString()+".xls"); // Write the output to a file wb.write(outputStream); outputStream.close(); } }
这是用POI实现的一个例子,希望对LZ有所帮助。
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;public class FilePOIHSSFExecl {
public void write(Reserve reserve_obj,List<ReserveDetail> reserveDtlList) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
//建立新的SHEET
HSSFSheet sheet = wb.createSheet("new sheet"); //订单编号:(内容) 订单内容:(**)
HSSFRow row = sheet.createRow((short)0);
row.createCell((short)0).setCellValue("订单编号");
row.createCell((short)1).setCellValue(reserve_obj.订单编号);
wb.write(outputStream);
outputStream.close();
}} 刚才的格式有点乱,整理了下