s2sh开发轻松实现导出excel功能

package com.jjznkj.oa.utills;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;

import com.jjznkj.oa.domain.LoginLog;
import com.jjznkj.oa.domain.OperatorLog;
import com.jjznkj.oa.vo.AccountVO;

/**
 * @项目名称 : ZNKJOA
 * @类名称 : Write2Excel
 * @类描述 : 写出到xls
 * @创建人 :
 * @创建时间 : 2014-6-28 上午10:02:20
 * @修改人 : 
 * @修改时间 : 2014-6-28 上午10:02:20
 * @修改备注 :
 * @version :
 */

public class Write2Excel {

	/**
	 * xls头
	 * 
	 * @return
	 */
	public static String getHearder() {
		return "  " + "  " + " 
   
    " + " 
   
    " + "  " + " 
   
    " + "  " + "  " + " 
   
   
"; } /** * xls尾 * * @return */ public static String getFooter() { return " "; } public static InputStream getAccountInputStream(String[] titile, List accountVOList) throws UnsupportedEncodingException { StringBuffer sb = new StringBuffer(); sb.append(" "); for (String t : titile) { sb.append(" " + t + " "); } sb.append(" "); for (AccountVO accountVO : accountVOList) { sb.append(" " + " " + accountVO.getLoginName() + " " + "" + accountVO.getStatus() + " " + " " + accountVO.getLoginIp() + " "// + " " + accountVO.getName() + " "+ "" + accountVO.getNumber() + " "+ "" + accountVO.getSex() + " "// + " " + accountVO.getBirthday() + " "+ "" + accountVO.getTel() + " "+ "" + accountVO.getEmail() + " "// + " " + accountVO.getQq() + " "+ "" + accountVO.getFax() + " "+ "" + accountVO.getMobile() + " "// + " " + accountVO.getExplain1() + " " + "" + accountVO.getAddress() + " "+ "" + accountVO.getIsDocumentUser() + " "// + " " + accountVO.getDepartmentName() + " "+ "" + accountVO.getPositionName() + " "// // + " "); } return new ByteArrayInputStream((getHearder() + sb.toString() + getFooter()).getBytes("utf-8")); } public static InputStream getLogInputStream(String[] titile, List loginLogList) throws UnsupportedEncodingException { StringBuffer sb = new StringBuffer(); sb.append(" "); for (String t : titile) { sb.append(" " + t + " "); } sb.append(" "); for (LoginLog loginLog : loginLogList) { sb.append(" " + " " + loginLog.getName() + " " + " " + loginLog.getIP() + " " + " '" + (loginLog.getLogindata() == null ? "未登录":loginLog.getLogindata().toString()) + " " + " '" + (loginLog.getEnddata() == null ? "未退出":loginLog.getEnddata().toString()) + " "); } return new ByteArrayInputStream((getHearder() + sb.toString() + getFooter()).getBytes("utf-8")); } public static InputStream getOperatorLogInputStream(String[] titile, List operatorLogs) throws UnsupportedEncodingException { StringBuffer sb = new StringBuffer(); sb.append(" "); for (String t : titile) { sb.append(" " + t + " "); } sb.append(" "); for (OperatorLog operatorLog : operatorLogs) { sb.append(" " + " " // + operatorLog.getUserId() + " " // + " " // + operatorLog.getIp()+ " "// + " " // + (operatorLog.getCreateDate() == null ? "未登录":operatorLog.getCreateDate().toString()) // + " "// + " "// + (operatorLog.getEnddata() == null ? "未退出":operatorLog.getEnddata().toString()) // +""// +" "// +operatorLog.getMacAddress()+""// +""// +operatorLog.getContent()+""// +""// +operatorLog.getOperation() + " "); } return new ByteArrayInputStream((getHearder() + sb.toString() + getFooter()).getBytes("utf-8")); } } /** * 导出数据 */ public String exportData() throws Exception { return "export"; } /** * struts2通过此方法获取输入流 * @return */ public InputStream getExportData() throws Exception { //获取选中的部门 List operatorLogs = operatorLogService.getByIds(operatorLogIds); //输出excel表头 String[] titile = {"姓名","IP","登录时间","退出时间","MAC地址","操作","操作内容"}; //输出excel的表内容 //返回输入流 return Write2Excel.getOperatorLogInputStream(titile, operatorLogs); } application/vnd.ms-excel;charset=utf-8 exportData attachment;filename="exportOperatorLog.xls" 1024
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值