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
s2sh开发轻松实现导出excel功能
最新推荐文章于 2020-09-06 09:11:24 发布