public class ManageDiyAction extends DispatchAction {
/**
* ��Ա�һ���Ϣͳ��
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws IOException
*/
public ActionForward print2Excel(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException {
String startDate = request.getParameter("startDate");
String endDate = request.getParameter("endDate");
String stat = request.getParameter("stat");
if(stat == null)
stat = "";
Session sess = HibernateUtil.currentSession();
String hql = "from VcCheck vk where vk.checkDate >= '" + startDate +"' and vk.checkDate <= '" + endDate +"'";
Query query = sess.createQuery(hql);
List list = query.list();
JspStreamDownload jspDown = new JspStreamDownload();
String datalist[][] = new String[list.size() + 1][10];
datalist[0][0] = "列名";
datalist[0][1] = "列名";
datalist[0][2] = "列名";
datalist[0][3] = "列名";
datalist[0][4] = "列名";
datalist[0][5] = "列名";
datalist[0][6] = "列名";
datalist[0][7] = "列名";
datalist[0][8] = "列名";
datalist[0][9] = "列名";
//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
for(int i =1;i<=list.size();i++){
VcCheck vc = (VcCheck) list.get(i-1);
datalist[i][0] = vc.getVcName();
datalist[i][1] = vc.getVcModelName();
datalist[i][2] = vc.getWarehName();
datalist[i][3] = vc.getCheckSort().toString();
System.out.println(vc.getCheckSort().toString());
datalist[i][4] = vc.getShouldNum().toString();
datalist[i][5] = vc.getRealyNum().toString();
datalist[i][6] = vc.getMarginNum().toString();
datalist[i][7] = vc.getUnitName();
datalist[i][8] = vc.getCheckPeople();
datalist[i][9] = vc.getCheckDate();
}
request.setAttribute("VcCheckNoteList", list);
if(stat.equals("ok")){
String checkname = ToUTF8.toUtf8String("设备盘点表"); //解决下载后中文文件名问题
jspDown.writeExcel(checkname+".xls", "设备盘点", datalist, response);
return null;
}
return mapping.findForward("success");
}
}
==========================================
public class JspStreamDownload
{
public JspStreamDownload()
{
}
/**
*
* @param strFileName �����exl���ļ�������
* @param strTableName exl���������
* @param strData �������ݶ��