package com.mathlab.action;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import com.mathlab.model.Student;
import com.mathlab.service.StuService;
import com.opensymphony.xwork2.ActionSupport;
public class ModelToExcelAction extends ActionSupport {
StuService stuService;
public StuService getStuService() {
return stuService;
}
public void setStuService(StuService stuService) {
this.stuService = stuService;
}
@Override
public String execute() throws Exception {
JFileChooser jfc = new JFileChooser();
jfc.setAcceptAllFileFilterUsed(false);
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//只是针对文件夹有效
jfc.setFileFilter(
new FileFilter(){
public boolean accept(File f) {
// TODO Auto-generated method stub
return f.getName().toLowerCase().endsWith(".xls");
}
public String getDescription() {
// TODO Auto-generated method stub
return "Excel File";
}
}
);
jfc.showSaveDialog(null);
String filePath = jfc.getSelectedFile().getPath();
System.out.println(filePath);
WritableWorkbook wwb;
FileOutputStream fos;
try{
fos = new FileOutputStream(filePath+"\\"+"学生名单"+".xls");
wwb = Workbook.createWorkbook(fos);
WritableSheet ws = wwb.createSheet("sheet1", 0); // 创建一个工作表
// 设置单元格的文字格式
WritableFont wf = new WritableFont(WritableFont.ARIAL,12,WritableFont.NO_BOLD,false,
UnderlineStyle.NO_UNDERLINE,Colour.BLUE);
WritableCellFormat wcf = new WritableCellFormat(wf);
wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
wcf.setAlignment(Alignment.CENTRE);
ws.setRowView(1, 500);
ws.addCell(new Label(0, 0, "记录编号",wcf));
ws.addCell(new Label(1, 0, "用户名", wcf));
ws.addCell(new Label(2, 0, "用户密码", wcf));
ws.addCell(new Label(3, 0, "学生姓名", wcf));
ws.addCell(new Label(4, 0, "学号", wcf));
ws.addCell(new Label(5, 0, "所属班级", wcf));
ws.addCell(new Label(6, 0, "权限", wcf));
//填充数据的内容
Student[] stu = new Student[stuService.listStu().size()];
for (int i = 0; i < stuService.listStu().size(); i++){
stu[i] = (Student)stuService.listStu().get(i);
ws.addCell(new Label(0, i + 1, stu[i].getStuID().toString()));
System.out.println(stu[i].getStuID().toString());
ws.addCell(new Label(1, i + 1, stu[i].getStuName()));
ws.addCell(new Label(2, i + 1, stu[i].getStuPwd()));
ws.addCell(new Label(3, i + 1, stu[i].getRealName()));
ws.addCell(new Label(4, i + 1, stu[i].getStuNum()));
ws.addCell(new Label(5, i + 1, stu[i].getGrade()));
ws.addCell(new Label(6, i + 1, stu[i].getAuthority()));
if(i == 0)
wcf = new WritableCellFormat();
}
wwb.write();
wwb.close();
} catch (IOException e){
} catch (RowsExceededException e){
} catch (WriteException e){}
return "success";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 基于MATLAB+SSH的在线实验系统源码+详细文档+全部数据(高分课程设计).zip基于MATLAB+SSH的在线实验系统源码+详细文档+全部数据(高分课程设计).zip基于MATLAB+SSH的在线实验系统源码+详细文档+全部数据(高分课程设计).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也可作为毕设项目、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 3、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
基于MATLAB+SSH的在线实验系统源码+详细文档+全部数据(高分课程设计).zip (580个子文件)
ModelToExcelAction.class 5KB
QueryUserByNameAction.class 4KB
UploadConfigurationRead.class 4KB
StuDaoImpl.class 4KB
UploadAction.class 3KB
ListExpForStuAction.class 3KB
DrawWebMagicAction.class 3KB
ExcelToModelAction.class 3KB
AddExpAction.class 3KB
LoginAction.class 3KB
TeaDaoImpl.class 3KB
PreAddStuAndCourseAction.class 3KB
EditStuAction.class 3KB
ListGradeAuthAction.class 2KB
PreAddExpAction.class 2KB
AddStuAction.class 2KB
DownloadAction.class 2KB
DisplayFilesAction.class 2KB
ReplyNoteAction.class 2KB
ManDaoImpl.class 2KB
AuthDaoImpl.class 2KB
ExperimentDaoImpl.class 2KB
AddNoteAction.class 2KB
StuAndCourseDaoImpl.class 2KB
Experiment.class 2KB
EditTeaAction.class 2KB
NoteDaoImpl.class 2KB
AddCourseAction.class 2KB
AddStuAndCourseAction.class 2KB
EditAuthAction.class 2KB
StuServiceImpl.class 2KB
Student.class 2KB
AddAuthAction.class 2KB
LoginServiceImpl.class 2KB
AddManagerAction.class 2KB
AddTeacherAction.class 2KB
AddGradeAction.class 2KB
ListTeaAuthAction.class 2KB
ListManAuthAction.class 2KB
ListCourseTeaAction.class 2KB
ListGradeAction.class 2KB
ListAuthAction.class 2KB
TeaServiceImpl.class 2KB
PreReplyNoteAction.class 2KB
ListNoteAction.class 2KB
ListTeaAction.class 2KB
ListStuAction.class 2KB
PreEditStuAction.class 2KB
PreEditTeaAction.class 2KB
PreEditAuthAction.class 1KB
ListExpAction.class 1KB
ExpServiceImpl.class 1KB
DataAccessUtil.class 1KB
AuthServiceImpl.class 1KB
Course.class 1KB
TimeGenerator.class 1KB
ManServiceImpl.class 1KB
LoginOutAction.class 1KB
NoteServiceImpl.class 1KB
StuAndCourseServiceImpl.class 1KB
DeleteNoteAction.class 1KB
DeleteAuthAction.class 1KB
DeleteStuAction.class 1KB
DeleteTeaAction.class 1KB
Manager.class 1KB
Teacher.class 1KB
Grade.class 1KB
Note.class 1KB
CourseServiceImpl.class 1KB
CourseDaoImpl.class 1KB
GradeServiceImpl.class 1KB
GradeDaoImpl.class 1KB
UploadFiles.class 1009B
StuAndCourse.class 999B
ExcelToModelAction$1.class 962B
ModelToExcelAction$1.class 962B
Authority.class 931B
ExportDB.class 761B
StuDao.class 639B
StuService.class 588B
TeaDao.class 569B
TeaService.class 521B
ManDao.class 445B
ExperimentDao.class 403B
ExpService.class 398B
ManService.class 397B
AuthService.class 392B
AuthDao.class 381B
StuAndCourseService.class 364B
StuAndCourseDao.class 357B
NoteService.class 354B
NoteDao.class 345B
CourseService.class 290B
GradeService.class 284B
CourseDao.class 281B
GradeDao.class 275B
LoginService.class 236B
fox.css 7KB
skin.css 4KB
addExp.ftl 2KB
共 580 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
不走小道
- 粉丝: 3206
- 资源: 5122
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Python 程序语言设计模式思路-创建型模式:原型模式:通过复制现有对象来创建新对象,面向对象编程
- 卸载软件geek卸载软件geek
- Python 程序语言设计模式思路-创建型模式:单例模式,确保一个类的唯一实例(装饰器)面向对象编程、继承
- skywalking-plugins.jar skywalking-alarm.jar
- 独栋别墅图纸D020-两层-10.00&11.00米- 施工图.dwg
- Python 程序语言设计模式思路-创建型模式:工厂模式,创建对象的统一接口,封装对象的创建逻辑
- python自学教程-05-json数据格式的介绍.ev4.rar
- python自学教程-04-自定义JavaScript.ev4.rar
- 《淘宝后台系统...》
- skywalking-plugins.jar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功