package com.ts.action; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import com.opensymphony.xwork2.ActionSupport; import com.ts.service.UserService; import com.ts.vo.Users; public class ExcelAction extends ActionSupport { private UserService userService; @Override public String execute() throws Exception { // TODO Auto-generated method stub return super.execute(); } public InputStream getTargetFiles() throws Exception { String filename="联系人表格"; System.out.println(filename); List<Users> userlist=userService.listUser(); List<String> headers=new ArrayList<String>(); headers.add("用户id"); headers.add("姓名"); headers.add("性别"); headers.add("年龄"); headers.add("所属部门"); headers.add("职位"); headers.add("电子邮件"); headers.add("办公电话"); headers.add("移动电话"); headers.add("住址"); HSSFWorkbook wb=new HSSFWorkbook(); HSSFSheet sheet=wb.createSheet(filename); HSSFRow row=sheet.createRow(0); HSSFCell cell; for(int i=0;i<headers.size();i++){ cell=row.createCell((short)i); cell.setCellValue(headers.get(i)+""); } for(int i=0;i<userlist.size();i++){ row=sheet.createRow(i+1); cell=row.createCell((short)0); //cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue(userlist.get(i).getUserid());//--------- cell=row.createCell((short)1); cell.setCellValue(userlist.get(i).getUsername());//--------- cell=row.createCell((short)2); if(userlist.get(i).getSex()==0){ cell.setCellValue("女");//--------- }else{ cell.setCellValue("男"); } cell=row.createCell((short)3); cell.setCellValue(userlist.get(i).getAge());//--------- cell=row.createCell((short)4); cell.setCellValue(userlist.get(i).getDepartment().getDepartmentname());//--------- cell=row.createCell((short)5); cell.setCellValue(userlist.get(i).getPosition());//--------- cell=row.createCell((short)6); cell.setCellValue(userlist.get(i).getEmail());//--------- cell=row.createCell((short)7); cell.setCellValue(userlist.get(i).getPhone());//--------- cell=row.createCell((short)8); cell.setCellValue(userlist.get(i).getMobilephone());//--------- cell=row.createCell((short)9); cell.setCellValue(userlist.get(i).getAddress());//--------- } ByteArrayOutputStream os=new ByteArrayOutputStream(); wb.write(os); byte[] b=os.toByteArray(); InputStream is=new ByteArrayInputStream(b); return is; } private static final long serialVersionUID = 1L; public UserService getUserService() { return userService; } public void setUserService(UserService userService) { this.userService = userService; } }

微信网友_5963854197018624 LV7
2023年4月6日
akbar2020 LV9
2022年9月4日
19857460815 LV1
2022年6月20日
zeze2580 LV2
2022年5月9日
wanglinddad LV55
2022年3月26日
habiya LV3
2022年3月14日
ds9527 LV2
2022年3月3日
MarkLee 琥珀川 LV13
2022年1月21日
小豆芽 LV8
2021年6月10日
xufei123 LV4
2021年6月2日

lkke23047 LV1
5月26日
2022102154 LV1
3月27日
benben2020
3月19日
暂无贡献等级
微信网友_7398626323435520 LV3
2月25日
张泽帅 LV6
2024年10月22日
krispeng LV15
2024年8月12日
9605451tjb LV4
2024年8月7日
yunsgui LV1
2024年6月25日
liyan54188 LV2
2024年6月25日
微信网友_7009341063450624
2024年6月1日
暂无贡献等级