JSP如下:<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page contentType="text/html; charset=gb2312" %>
<html:html xhtml="true">
<HEAD>
<TITLE>单位季度报表</TITLE>
<LINK href="../css/allpageCSS.css" type=text/css rel=stylesheet>
</HEAD>
<BODY leftmargin="0" topmargin="0">
<DIV align=center>
<html:form method="post" action="report_quarter.do">
<TABLE cellSpacing=1 cellPadding=1 width="100%" bgColor=#94AAD6 border=0>
<TBODY>
<TR>
<TD height=30 colSpan=2 valign="middle">
<FONT color=white><B>单位季度报表</B></FONT>
</TD>
<TD height=23 valign="middle">
<div align="right">
<html:select property="quartersel">
<html:optionsCollection property="quarterlist" label="labels_quarter" value="values_quarter" />
</html:select>
</div>
</TD>
</TR>
<TR bgColor=#BFCAE6>
<TD width="40%" height="26" align=right> <div align="center">单位名称</div></TD>
<TD width="30%" height="26"> <div align="center">报表生成日期</div></TD>
<TD width="30%" height="26"> <div align="center">生成报表数据</div></TD>
</TR>
<logic:iterate id="list" property="cplist" offset="offset" length="length" name="report_QuarterForm" >
<TR bgColor=white>
<TD height="22" align=center><bean:write name="list" property="company" /></TD>
<TD height="22" align="center"><bean:write name="list" property="date" /></TD>
<TD height="22" align="center"><INPUT name="button" type="button" style="BORDER-RIGHT: #94AAD6 1px solid; BORDER-TOP: #94AAD6 1px solid; BORDER-LEFT: #94AAD6 1px solid; WIDTH: 120px; COLOR: white; BORDER-BOTTOM: #94AAD6 1px solid; HEIGHT: 20px; BACKGROUND-COLOR: #94AAD6" onclick="submitform()" value="生成报表数据"></TD>
</TR>
</logic:iterate>
</TBODY>
</TABLE>
</html:form>
</DIV>
</BODY>
</html:html>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page contentType="text/html; charset=gb2312" %>
<html:html xhtml="true">
<HEAD>
<TITLE>单位季度报表</TITLE>
<LINK href="../css/allpageCSS.css" type=text/css rel=stylesheet>
</HEAD>
<BODY leftmargin="0" topmargin="0">
<DIV align=center>
<html:form method="post" action="report_quarter.do">
<TABLE cellSpacing=1 cellPadding=1 width="100%" bgColor=#94AAD6 border=0>
<TBODY>
<TR>
<TD height=30 colSpan=2 valign="middle">
<FONT color=white><B>单位季度报表</B></FONT>
</TD>
<TD height=23 valign="middle">
<div align="right">
<html:select property="quartersel">
<html:optionsCollection property="quarterlist" label="labels_quarter" value="values_quarter" />
</html:select>
</div>
</TD>
</TR>
<TR bgColor=#BFCAE6>
<TD width="40%" height="26" align=right> <div align="center">单位名称</div></TD>
<TD width="30%" height="26"> <div align="center">报表生成日期</div></TD>
<TD width="30%" height="26"> <div align="center">生成报表数据</div></TD>
</TR>
<logic:iterate id="list" property="cplist" offset="offset" length="length" name="report_QuarterForm" >
<TR bgColor=white>
<TD height="22" align=center><bean:write name="list" property="company" /></TD>
<TD height="22" align="center"><bean:write name="list" property="date" /></TD>
<TD height="22" align="center"><INPUT name="button" type="button" style="BORDER-RIGHT: #94AAD6 1px solid; BORDER-TOP: #94AAD6 1px solid; BORDER-LEFT: #94AAD6 1px solid; WIDTH: 120px; COLOR: white; BORDER-BOTTOM: #94AAD6 1px solid; HEIGHT: 20px; BACKGROUND-COLOR: #94AAD6" onclick="submitform()" value="生成报表数据"></TD>
</TR>
</logic:iterate>
</TBODY>
</TABLE>
</html:form>
</DIV>
</BODY>
</html:html>
{
static final private String FORWARD_failed = "failed"; static final private String FORWARD_unsession = "unsession"; static Logger logger = Logger.getLogger(AddUserAction.class.getName()); public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception
{
Report_Quarter_CorpForm rqcForm = (Report_Quarter_CorpForm) form; HttpSession session = request.getSession(); String name = (String)session.getAttribute("mainname"); String corpname = "";
String companyid = request.getParameter("companyid"); //单位编号
String rq_date = request.getParameter("date");
String rq_quartersel = request.getParameter("quartersel");
String rq_startdate = request.getParameter("startdate");
String rq_enddate = request.getParameter("enddate");
String startdate = "";
String enddate = "";
String tablename = ""; corpname = LinkAct.getCorpname(companyid); Calendar cal = Calendar.getInstance();
String year = Integer.toString(cal.get(Calendar.YEAR));
String oldyear = Integer.toString(cal.get(Calendar.YEAR)-1); tablename = companyid+"_ResultQuery"; String pathtop = request.getRealPath("/"); ActionForward af = new ActionForward();
System.out.println(pathtop+Static.MYJKEXCEL+createExcel(rq_date,year,rq_quartersel,name,corpname,companyid,tablename,pathtop));
af.setPath("/excel/"+createExcel(rq_date,year,rq_quartersel,name,corpname,companyid,startdate,enddate,tablename,pathtop));
return af;
} public static String createExcel(String rq_date,String year,String rq_quartersel,String name,String corpname,String companyid,String tablename,String pathtop) throws Exception
{
String title = "";
String title1 = ""; if ( rq_date.equals("0") )
{
title = corpname+year;
title1 = corpname+year;
}
if ( rq_date.equals("1") )
{
title = corpname;
title1 = corpname;
} String path = title + ".xls"; //创建可写入的Excel工作薄(文件名)
WritableWorkbook workbook = Workbook.createWorkbook(new File(Static.MYJKEXCEL+path));
//创建工作表 title为工作表名,0为第一页
WritableSheet sheet = workbook.createSheet(title, 0);
//设置列的宽度
sheet.setColumnView(0,20); WritableCellFormat writetableTitle = JxlCss.getTableCellCss("title","CENTRE","","ALL","THIN",""); Label label1= new Label(0,0,title,writetableTitle);
sheet.addCell(label1); workbook.write();
workbook.close(); return path;
}
}
------------------------------------
体验速度,体验CSDN新版论坛助手:http://community.csdn.net/Expert/TopicView.asp?id=3108679