apache POI 对Excel表的操作
2011-11-26 15:13
399 查看
package zk.excel;
import java.io.FileOutputStream;
import java.io.OutputStream;
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;
public class Excel
{
public static void main(String[] args) throws Exception
{
Student student = new Student("张凯", "123456", "男", 23,
"7095638@qq.com");
HSSFWorkbook excel = new HSSFWorkbook();
HSSFSheet sheet = excel.createSheet("用户信息");
HSSFRow titleRow = sheet.createRow(0);
sheet.setColumnWidth(4,5000);
HSSFCell titleCell0 = titleRow.createCell(0);
titleCell0.setCellValue("姓名");
HSSFCell titleCell1 = titleRow.createCell(1);
titleCell1.setCellValue("密码");
HSSFCell titleCell2 = titleRow.createCell(2);
titleCell2.setCellValue("性别");
HSSFCell titleCell3 = titleRow.createCell(3);
titleCell3.setCellValue("年龄");
HSSFCell titleCell4 = titleRow.createCell(4);
titleCell4.setCellValue("Email");
HSSFRow valueRow = sheet.createRow(1);
HSSFCell valueCell0 = valueRow.createCell(0);
valueCell0.setCellValue(student.getName());
HSSFCell valueCell1 = valueRow.createCell(1);
valueCell1.setCellValue(student.getPassword());
HSSFCell valueCell2 = valueRow.createCell(2);
valueCell2.setCellValue(student.getGender());
HSSFCell valueCell3 = valueRow.createCell(3);
valueCell3.setCellValue(student.getAge());
HSSFCell valueCell4 = valueRow.createCell(4);
valueCell4.setCellValue(student.getEmail());
OutputStream os = new FileOutputStream("excel.xls");
excel.write(os);
}
}
//要写入到Excel表中的类
class Student
{
private String name;
private String password;
private String gender;
private int age;
private String Email;
public Student(String name, String password, String gender, int age,
String email)
{
this.name = name;
this.password = password;
this.gender = gender;
this.age = age;
Email = email;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getGender()
{
return gender;
}
public void setGender(String gender)
{
this.gender = gender;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String getEmail()
{
return Email;
}
public void setEmail(String email)
{
Email = email;
}
}
相关文章推荐
- java 调用 poi(apache的专门读写microsoft office API) 操作Excel
- java操作Excel(org.apache.poi.hssf.usermodel)
- java 学习之对Excel的操作(Apache-poi 2.10 利用ss)
- java用org.apache.poi包操作excel
- java用org.apache.poi包操作excel
- org.apache.poi.ss.usermodel 类操作excel数据遗漏
- org.apache.poi.ss.usermodel 类操作excel数据遗漏
- 操作Excel工具类(基于Apache的POI类库)
- java用org.apache.poi包操作excel
- org.apache.poi.ss.usermodel 类操作excel数据遗漏
- org.apache.poi.hssf.usermodel.HSSFWorkbook 进行处理导出Excel操作
- Apache-POI操作Excel的一些小技巧
- java用org.apache.poi包操作excel
- POI 操作Excel 异常org.apache.poi.openxml4j.exceptions.invalidformatexception: package should contain a c
- 解决 POI 操作2007格式的Excel报错问题:java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlOptionsz
- java用org.apache.poi包操作excel
- Apache-POI操作Excel的一些小技巧
- java用org.apache.poi包操作excel
- java用org.apache.poi包操作excel
- 操作Excel工具类之基于Apache的POI类库