package spring;
import java.io.File;
import java.io.IOException;
import java.util.List;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class JxlExecl {
public static void main(String args[]) throws Exception{
String title[]={"id","userName","password","phone","email"};
UserDao userDao=new UserDaoImpl();
List<User> users=userDao.select();
File f=new File("user.xls");
if(!f.exists()){
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
WritableWorkbook ww=Workbook.createWorkbook(f);
WritableSheet sheet=ww.createSheet("sheet1", 0);
Label label=null;
for(int i=0; i<title.length;i++){
label=new Label(i, 0, title[i]);
sheet.addCell(label);
}
for(int i = 1; i<users.size(); i++){
label=new Label(0, i, String.valueOf(users.get(i).getId()));
sheet.addCell(label);
label=new Label(1, i, String.valueOf(users.get(i).getUserName()));
sheet.addCell(label);
label=new Label(2, i, String.valueOf(users.get(i).getPassord()));
sheet.addCell(label);
label=new Label(3, i, String.valueOf(users.get(i).getPhone()));
sheet.addCell(label);
label=new Label(4, i, String.valueOf(users.get(i).getEmail()));
sheet.addCell(label);
}
ww.write();
ww.close();
} catch (Exception e) {
e.printStackTrace();
}
// String title[]={"id","name","password"};
// File file=new File("/Users/zhangxuan/Documents/workspace/spring/exe.xls");
// try {
// file.createNewFile();
// WritableWorkbook w=Workbook.createWorkbook(file);
// WritableSheet sheet=w.createSheet("sheet1", 0);
// Label label=null;
// for(int i=0;i<title.length;i++){
// label=new Label(i,0,title[i]);
// sheet.addCell(label);
// }
// for(int i=1;i<10;i++){
// label=new Label(0,i, "id");
// sheet.addCell(label);
// label=new Label(1,i, "user");
// sheet.addCell(label);
// label=new Label(2,i, "password");
// sheet.addCell(label);
// }
// w.write();
// w.close();
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
}
import java.io.File;
import java.io.IOException;
import java.util.List;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class JxlExecl {
public static void main(String args[]) throws Exception{
String title[]={"id","userName","password","phone","email"};
UserDao userDao=new UserDaoImpl();
List<User> users=userDao.select();
File f=new File("user.xls");
if(!f.exists()){
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
WritableWorkbook ww=Workbook.createWorkbook(f);
WritableSheet sheet=ww.createSheet("sheet1", 0);
Label label=null;
for(int i=0; i<title.length;i++){
label=new Label(i, 0, title[i]);
sheet.addCell(label);
}
for(int i = 1; i<users.size(); i++){
label=new Label(0, i, String.valueOf(users.get(i).getId()));
sheet.addCell(label);
label=new Label(1, i, String.valueOf(users.get(i).getUserName()));
sheet.addCell(label);
label=new Label(2, i, String.valueOf(users.get(i).getPassord()));
sheet.addCell(label);
label=new Label(3, i, String.valueOf(users.get(i).getPhone()));
sheet.addCell(label);
label=new Label(4, i, String.valueOf(users.get(i).getEmail()));
sheet.addCell(label);
}
ww.write();
ww.close();
} catch (Exception e) {
e.printStackTrace();
}
// String title[]={"id","name","password"};
// File file=new File("/Users/zhangxuan/Documents/workspace/spring/exe.xls");
// try {
// file.createNewFile();
// WritableWorkbook w=Workbook.createWorkbook(file);
// WritableSheet sheet=w.createSheet("sheet1", 0);
// Label label=null;
// for(int i=0;i<title.length;i++){
// label=new Label(i,0,title[i]);
// sheet.addCell(label);
// }
// for(int i=1;i<10;i++){
// label=new Label(0,i, "id");
// sheet.addCell(label);
// label=new Label(1,i, "user");
// sheet.addCell(label);
// label=new Label(2,i, "password");
// sheet.addCell(label);
// }
// w.write();
// w.close();
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
}