作者在 2010-09-09 12:34:38 发布以下内容
import java.io.File;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.Sheet;
import jxl.Workbook;
public class Jwork {
public static void main(String[] args) {
try {
File file=new File("E:/Jexe.xls");
Workbook workbook=Workbook.getWorkbook(file);//构建工作表
Sheet sheet=workbook.getSheet(0);//创建Sheet对象 调用Sheet1
int rows=sheet.getRows();//获取行
int cols=sheet.getColumns();//获取列
System.out.print(rows +"and"+cols);
Cell cell=sheet.getCell(0, 0);
Jstudents jstudents1[]=new Jstudents[rows-1];//为17个学生创建数组
/*
)*/
//为15个学生对象设置属性
for (int i = 1; i < rows; i++) {
Jstudents jstudents=new Jstudents();
jstudents.setName(sheet.getCell(0, i).getContents());
jstudents.setSex(Integer.parseInt(sheet.getCell(1, i).getContents()));
jstudents.setAge(Integer.parseInt(sheet.getCell(2, i).getContents()));
jstudents.setBanji(Integer.parseInt(sheet.getCell(3, i).getContents()));
jstudents.setNo(Integer.parseInt(sheet.getCell(4, i).getContents()));
jstudents1[i-1]=jstudents;// 为17个学生创建数组设值
}
for (int j = 0; j < jstudents1.length; j++) {
Jstudents jstudents2=jstudents1[j];
System.out.println(jstudents2.getName());
System.out.print(jstudents2.getSex());
System.out.print(jstudents2.getAge());
System.out.print(jstudents2.getBanji());
System.out.print(jstudents2.getNo());
}
} catch (Exception e) {
}
}
}
public static void main(String[] args) {
try {
File file=new File("E:/Jexe.xls");
Workbook workbook=Workbook.getWorkbook(file);//构建工作表
Sheet sheet=workbook.getSheet(0);//创建Sheet对象 调用Sheet1
int rows=sheet.getRows();//获取行
int cols=sheet.getColumns();//获取列
System.out.print(rows +"and"+cols);
Cell cell=sheet.getCell(0, 0);
Jstudents jstudents1[]=new Jstudents[rows-1];//为17个学生创建数组
/*
)*/
//为15个学生对象设置属性
for (int i = 1; i < rows; i++) {
Jstudents jstudents=new Jstudents();
jstudents.setName(sheet.getCell(0, i).getContents());
jstudents.setSex(Integer.parseInt(sheet.getCell(1, i).getContents()));
jstudents.setAge(Integer.parseInt(sheet.getCell(2, i).getContents()));
jstudents.setBanji(Integer.parseInt(sheet.getCell(3, i).getContents()));
jstudents.setNo(Integer.parseInt(sheet.getCell(4, i).getContents()));
jstudents1[i-1]=jstudents;// 为17个学生创建数组设值
}
for (int j = 0; j < jstudents1.length; j++) {
Jstudents jstudents2=jstudents1[j];
System.out.println(jstudents2.getName());
System.out.print(jstudents2.getSex());
System.out.print(jstudents2.getAge());
System.out.print(jstudents2.getBanji());
System.out.print(jstudents2.getNo());
}
} catch (Exception e) {
}
}
}
import java.util.Date;
public class Jstudents {
private String name;
private int sex;
private int age;
private int banji;
private int no;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getBanji() {
return banji;
}
public void setBanji(int banji) {
this.banji = banji;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
}
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getBanji() {
return banji;
}
public void setBanji(int banji) {
this.banji = banji;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
}