如何将数据导出成EXCEL文件

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 �������ݶ��

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值