//实体类
package com.cn.peitest.excel;
import java.io.Serializable; /**
* 员工基本信息
*
* @author pei
*/
public class EmployeeBasicInformation implements Serializable { private static final long serialVersionUID = 1L;
/**
* 创建人名称
*/
private String creatorName; /**
* 创建人编号
*/
private String creatorCode; /**
* 姓名
*/
private String name; /**
* 工号
*/
private String employeeNumber; /**
* 身份证号码
*/
private String idCardNumber; /**
* 入职日期
*/
private String entryDate; /**
* 转正日期
*/
private String becomeFullMemberDate; /**
* 性别
*/
private String sex; /**
* 部门名称
*/
private String department; /**
* 部门编号
*/
private String departmentCode; /**
* 组别
*/
private String group; /**
* 组编号
*/
private String groupCode; /**
* 职位
*/
private String position; /**
* 职能
*/
private String function; /**
* 职级
*/
private String positionRank; /**
* 婚否
*/
private String isMarry; /**
* 合同开始日期
*/
private String contractStartDate; /**
* 合同结束日期
*/
private String contractEndDate; /**
* 专业
*/
private String profession; /**
* 学历
*/
private String educationBackground; /**
* 政治面貌
*/
private String politicsStatus; /**
* 毕业院校
*/
private String schoolOfGraduation; /**
* 户籍地址
*/
private String censusRegisterAddress; /**
* 户口类型
*/
private String registeredResidenceType; /**
* 暂住地址
*/
private String temporaryAddress; /**
* 联系电话
*/
private String contactPhone; /**
* 紧急联系人
*/
private String emergencyContact; /**
* 电话
*/
private String phone; /**
* 在职状态
*/
private String workingState; /**
* 表id
*/
private String id;
/**
* 租户id
*/
private String tenantId;
/**
* 入职月数
*/
private Double entryMonths;
/**
* 是否删除 0 未删除 1删除
*/
private String isDelete;
public String getCreatorName() {
return creatorName;
}
public void setCreatorName(String creatorName) {
this.creatorName = creatorName;
}
public String getCreatorCode() {
return creatorCode;
}
public void setCreatorCode(String creatorCode) {
this.creatorCode = creatorCode;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmployeeNumber() {
return employeeNumber;
}
public void setEmployeeNumber(String employeeNumber) {
this.employeeNumber = employeeNumber;
}
public String getIdCardNumber() {
return idCardNumber;
}
public void setIdCardNumber(String idCardNumber) {
this.idCardNumber = idCardNumber;
}
public String getEntryDate() {
return entryDate;
}
public void setEntryDate(String entryDate) {
this.entryDate = entryDate;
}
public String getBecomeFullMemberDate() {
return becomeFullMemberDate;
}
public void setBecomeFullMemberDate(String becomeFullMemberDate) {
this.becomeFullMemberDate = becomeFullMemberDate;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getDepartmentCode() {
return departmentCode;
}
public void setDepartmentCode(String departmentCode) {
this.departmentCode = departmentCode;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public String getGroupCode() {
return groupCode;
}
public void setGroupCode(String groupCode) {
this.groupCode = groupCode;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getFunction() {
return function;
}
public void setFunction(String function) {
this.function = function;
}
public String getPositionRank() {
return positionRank;
}
public void setPositionRank(String positionRank) {
this.positionRank = positionRank;
}
public String getIsMarry() {
return isMarry;
}
public void setIsMarry(String isMarry) {
this.isMarry = isMarry;
}
public String getContractStartDate() {
return contractStartDate;
}
public void setContractStartDate(String contractStartDate) {
this.contractStartDate = contractStartDate;
}
public String getContractEndDate() {
return contractEndDate;
}
public void setContractEndDate(String contractEndDate) {
this.contractEndDate = contractEndDate;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
public String getEducationBackground() {
return educationBackground;
}
public void setEducationBackground(String educationBackground) {
this.educationBackground = educationBackground;
}
public String getPoliticsStatus() {
return politicsStatus;
}
public void setPoliticsStatus(String politicsStatus) {
this.politicsStatus = politicsStatus;
}
public String getSchoolOfGraduation() {
return schoolOfGraduation;
}
public void setSchoolOfGraduation(String schoolOfGraduation) {
this.schoolOfGraduation = schoolOfGraduation;
}
public String getCensusRegisterAddress() {
return censusRegisterAddress;
}
public void setCensusRegisterAddress(String censusRegisterAddress) {
this.censusRegisterAddress = censusRegisterAddress;
}
public String getRegisteredResidenceType() {
return registeredResidenceType;
}
public void setRegisteredResidenceType(String registeredResidenceType) {
this.registeredResidenceType = registeredResidenceType;
}
public String getTemporaryAddress() {
return temporaryAddress;
}
public void setTemporaryAddress(String temporaryAddress) {
this.temporaryAddress = temporaryAddress;
}
public String getContactPhone() {
return contactPhone;
}
public void setContactPhone(String contactPhone) {
this.contactPhone = contactPhone;
}
public String getEmergencyContact() {
return emergencyContact;
}
public void setEmergencyContact(String emergencyContact) {
this.emergencyContact = emergencyContact;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getWorkingState() {
return workingState;
}
public void setWorkingState(String workingState) {
this.workingState = workingState;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTenantId() {
return tenantId;
}
public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}
public Double getEntryMonths() {
return entryMonths;
}
public void setEntryMonths(Double entryMonths) {
this.entryMonths = entryMonths;
}
public String getIsDelete() {
return isDelete;
}
public void setIsDelete(String isDelete) {
this.isDelete = isDelete;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public String toString() {
return "EmployeeBasicInformation [creatorName=" + creatorName + ", creatorCode=" + creatorCode + ", name="
+ name + ", employeeNumber=" + employeeNumber + ", idCardNumber=" + idCardNumber + ", entryDate="
+ entryDate + ", becomeFullMemberDate=" + becomeFullMemberDate + ", sex=" + sex + ", department="
+ department + ", departmentCode=" + departmentCode + ", group=" + group + ", groupCode=" + groupCode
+ ", position=" + position + ", function=" + function + ", positionRank=" + positionRank + ", isMarry="
+ isMarry + ", contractStartDate=" + contractStartDate + ", contractEndDate=" + contractEndDate
+ ", profession=" + profession + ", educationBackground=" + educationBackground + ", politicsStatus="
+ politicsStatus + ", schoolOfGraduation=" + schoolOfGraduation + ", censusRegisterAddress="
+ censusRegisterAddress + ", registeredResidenceType=" + registeredResidenceType + ", temporaryAddress="
+ temporaryAddress + ", contactPhone=" + contactPhone + ", emergencyContact=" + emergencyContact
+ ", phone=" + phone + ", workingState=" + workingState + ", id=" + id + ", tenantId=" + tenantId
+ ", entryMonths=" + entryMonths + ", isDelete=" + isDelete + "]";
} } //运行类
package com.cn.peitest.excel;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List; import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook; public class ExcelBook {
public static void main(String[] args) { ArrayList<EmployeeBasicInformation> arrayList=new
ArrayList<EmployeeBasicInformation>(); EmployeeBasicInformation bean0 =new
EmployeeBasicInformation(); bean0.setId("主表id"); bean0.setName("姓名");
bean0.setCreatorCode("用户号"); EmployeeBasicInformation bean =new
EmployeeBasicInformation(); bean.setId("000220"); bean.setName("裴");
bean.setCreatorCode("001223456"); EmployeeBasicInformation bean1 =new
EmployeeBasicInformation(); bean1.setId("000220"); bean1.setName("裴");
bean1.setCreatorCode("001223456"); arrayList.add(bean0); arrayList.add(bean);
arrayList.add(bean1); System.out.println("arrayList============="+arrayList);
excelOut(arrayList); reflect(bean1); } //将数据导出到Excel
public static void excelOut(ArrayList<EmployeeBasicInformation> arrayList) {
WritableWorkbook bWorkbook = null;
try {
// 创建Excel对象
bWorkbook = Workbook.createWorkbook(new File("D:/book.xls"));
// 通过Excel对象创建一个选项卡对象
WritableSheet sheet = bWorkbook.createSheet("sheet1", 0);
//使用循环将数据读出
for (int i =0; i < arrayList.size(); i++) {
EmployeeBasicInformation book=arrayList.get(i);
Label label=new Label(0,i,String.valueOf(book.getId()));
Label label1=new Label(1,i,String.valueOf(book.getName()));
Label label2=new Label(2,i,String.valueOf(book.getCreatorCode()));
sheet.addCell(label);
sheet.addCell(label1);
sheet.addCell(label2); } // 创建一个单元格对象,第一个为列,第二个为行,第三个为值
Label label = new Label(0, 2, "test");
// 将创建好的单元格放入选项卡中
//sheet.addCell(label);
// 写如目标路径
bWorkbook.write(); } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
bWorkbook.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
//循环获取实体中的值
public static List reflect(EmployeeBasicInformation e){
List list=new ArrayList();
try {
Class cls = e.getClass();
Field[] fields = cls.getDeclaredFields();
for(int i=0; i<fields.length; i++){
Field f = fields[i];
f.setAccessible(true);
System.out.println("属性名:" + f.getName() + " 属性值:" + f.get(e));
list.add(f.get(e));
}
} catch (Exception e2) {
e2.printStackTrace();
// TODO: handle exception
}
return list; } }

  

java中将信息写入excel的更多相关文章

  1. JAVA读取、写入Excel表格(含03版)

    引言 工作中可能会遇到对Excel读取和写入,如果我们自己手动写的话,会很麻烦,但是Apache中有poi工具类.poi工具类封装好了对于Excel读取和写入,我们需要用的时候,直接调用该方法就好了. ...

  2. Java poi读取,写入Excel,处理row和cell可能为空的情况

    首先需要导入包 import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.NP ...

  3. Java使用jxl写入Excel文件

    首先添加jxl的maven依赖: <!-- https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl --> < ...

  4. Java读取、写入、处理Excel文件中的数据(转载)

    原文链接 在日常工作中,我们常常会进行文件读写操作,除去我们最常用的纯文本文件读写,更多时候我们需要对Excel中的数据进行读取操作,本文将介绍Excel读写的常用方法,希望对大家学习Java读写Ex ...

  5. Python爬虫学习(二) ——————爬取前程无忧招聘信息并写入excel

    作为一名Pythoner,相信大家对Python的就业前景或多或少会有一些关注.索性我们就写一个爬虫去获取一些我们需要的信息,今天我们要爬取的是前程无忧!说干就干!进入到前程无忧的官网,输入关键字&q ...

  6. 读取xml文件,写入excel

    在上一篇 Python写xml文件已经将所有订单写入xml文件,这一篇我们把xml文件中的内容读出来,写入excel文件. 输入xml格式: <?xml version="1.0&qu ...

  7. java数据写入Excel

    正好最近公司要写一个对账的功能,后台用java从银行获得对账信息,数据是json类型的,然后写入excel中发送给一卡通中心的服务器上,网上找了很多代码,然后整合和改正,代码如下. import ja ...

  8. Java使用POI读取和写入Excel指南

    Java使用POI读取和写入Excel指南 做项目时经常有通过程序读取Excel数据,或是创建新的Excel并写入数据的需求: 网上很多经验教程里使用的POI版本都比较老了,一些API在新版里已经废弃 ...

  9. Java使用POI读取和写入Excel指南(转)

    做项目时经常有通过程序读取Excel数据,或是创建新的Excel并写入数据的需求: 网上很多经验教程里使用的POI版本都比较老了,一些API在新版里已经废弃,这里基于最新的Apache POI 4.0 ...

随机推荐

  1. ABAP CDS-Part 1(ABAP CDS实体)

    文章翻译自Tushar Sharma的文章,转载请注明原作者和译者! 目录 预备条件 一.概述 二.ABAP CDS实体(CDS Entity) a.定义ABAP CDS Views b.ABAP C ...

  2. 网络拓扑实例09:VRRP组网下同网段内配置基于全局地址池的DHCP服务器

    组网图形 DHCP服务器简介 见前面DHCP服务器文章,不再赘述. 组网需求 如图1所示,某企业内的一台主机通过Switch双归属到SwitchA和SwitchB,SwitchA为主设备,作为DHCP ...

  3. 一万字详解 Redis Cluster Gossip 协议

    Redis Cluster Gossip 协议 大家好,我是历小冰,今天来讲一下 Reids Cluster 的 Gossip 协议和集群操作,文章的思维导图如下所示. 集群模式和 Gossip 简介 ...

  4. 第8.3节 Python类的__init__方法深入剖析:构造方法与继承详解

    第8.3节 Python类的__init__方法深入剖析:构造方法与继承详解 一.    引言 上两节介绍了构造方法的语法及参数,说明了构造方法是Python的类创建实例后首先执行的方法,并说明如果类 ...

  5. 将一个数组转化为需要的格式,来自react官网的商品列表示例

    //原来的格式 const PRODUCTS = [ { category: 'Sporting Goods', price: '$49.99', stocked: true, name: 'Foot ...

  6. 2020 AC Saber夏季赛 游记

    看着 \(\text{Acwing}\) 成长的我,还是写一下游记吧(?). 刚刚中考完,手速本来就老年,更慢,算法每次写完都要调,而且还查不出错.. Day 1 初赛.紧张,因为中考四五个月没打了, ...

  7. 题解-MtOI2019 幽灵乐团

    题面 MtOI2019 幽灵乐团 给定 \(p\),\(Cnt\) 组测试数据,每次给 \(a,b,c\),求 \[\prod_{i=1}^a\prod_{j=1}^b\prod_{k=1}^c\le ...

  8. 计算机语言与JAVA的发展

    计算机语言与JAVA的发展 第一代语言 2进制 第二代语言 汇编语言 解决人类无法读懂的问题 指令替代二进制 目前应用 逆向工程 机器人 病毒 第三代语言 摩尔定律 性能提升愈来愈慢 高级语言 面向过 ...

  9. zstd c++ string 压缩&解压

    zstd 简介 维基百科定义: Zstandard(或Zstd)是由Facebook的Yann Collet开发的一个无损数据压缩算法.该名称也指其C语言的参考实现.第1版的实现于2016年8月31日 ...

  10. Jmeter之分布式执行测试 (2)

    一. 安装Java 1.1下载JDK 1) Windows安装jdk,下载完成后,双击安装 2) Linux解压:tar -zxvf jdk-8u74-linux-x64.gz 1.2 Java环境变 ...