package com.beacon.sms.utils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.struts2.ServletActionContext;
import com.beacon.sms.bean.Address;
import com.beacon.sms.bean.Class;
import com.beacon.sms.bean.Course;
import com.beacon.sms.bean.Score;
import com.beacon.sms.bean.Semester;
import com.beacon.sms.bean.Student;
import com.beacon.sms.bean.Teacher;
import com.beacon.sms.bean.Teaching;
/**
*
* 作者:beacon 创建日期:2017年11月8日下午4:21:49 描述:处理Excel的工具类
*/
public class ExcelUtil {
private String[] headers = { "学年学期", "学号", "姓名", "所在班级", "课程名称", "成绩" };
public List<Student> readStudentExcel(InputStream inputStream) throws IOException {
List<Student> list = new ArrayList<Student>();
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(inputStream);
Sheet sheet = hssfWorkbook.getSheetAt(0);
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
Student student = new Student();
student.setStudentName(row.getCell(0).getStringCellValue());
student.setSex(row.getCell(1).getStringCellValue());
Address address = new Address();
address.setProvince(row.getCell(2).getStringCellValue());
address.setCity(row.getCell(3).getStringCellValue());
address.setCounty(row.getCell(4).getStringCellValue());
address.setDetailedAddress(row.getCell(5).getStringCellValue());
student.setAddress(address);
student.setBirthday(row.getCell(6).getStringCellValue());
student.setOrigin(row.getCell(7).getStringCellValue());
Cell cell = row.getCell(8);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
String content = cell.getStringCellValue();
student.setCellphone(content);
cell = row.getCell(9);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
content = cell.getStringCellValue();
student.setIdCard(content);
student.setPolitics(row.getCell(10).getStringCellValue());
list.add(student);
}
return list;
}
public List<Teacher> readTeacherExcel(InputStream inputStream) throws IOException {
List<Teacher> list = new ArrayList<Teacher>();
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(inputStream);
Sheet sheet = hssfWorkbook.getSheetAt(0);
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
Teacher teacher = new Teacher();
teacher.setTeacherName(row.getCell(0).getStringCellValue());
Cell cell = row.getCell(1);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
String content = cell.getStringCellValue();
teacher.setCellphone(content);
teacher.setSex(row.getCell(2).getStringCellValue());
teacher.setBirthday(row.getCell(3).getStringCellValue());
teacher.setEducation(row.getCell(4).getStringCellValue());
cell = row.getCell(5);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
content = cell.getStringCellValue();
teacher.setIdCard(content);
Address address = new Address();
address.setProvince(row.getCell(6).getStringCellValue());
address.setCity(row.getCell(7).getStringCellValue());
address.setCounty(row.getCell(8).getStringCellValue());
address.setDetailedAddress(row.getCell(9).getStringCellValue());
teacher.setAddress(address);
list.add(teacher);
}
return list;
}
public void exportExcel(List<Score> list) throws IOException {
HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
Sheet sheet = hssfWorkbook.createSheet("学生成绩表");
Row header = sheet.createRow(0);
for (int i = 0; i < headers.length; i++) {
header.createCell(i).setCellValue(headers[i]);
}
for (int i = 0; i < list.size(); i++) {
Row row = sheet.createRow(i + 1);
Score score = list.get(i);
Teaching teaching = score.getTeaching();
Student student = score.getStudent();
int fenshu = score.getScore();
Semester semester = teaching.getSemester();
Class class1 = student.getClass1();
Course course = teaching.getCourse();
row.createCell(0).setCellValue(semester.getSemesterName());
row.createCell(1).setCellValue(student.getStudentNo());
row.createCell(2).setCellValue(student.getStudentName());
row.createCell(3).setCellValue(class1.getClassName());
row.createCell(4).setCellValue(course.getCourseName());
row.createCell(5).setCellValue(fenshu);
}
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment;filename=score.xls");
OutputStream ouputStream = response.getOutputStream();
hssfWorkbook.write(ouputStream);
ouputStream.flush();
ouputStream.close();
}
public InputStream getExcelInputStream(List<Score> list) throws IOException {
HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
Sheet sheet = hssfWorkbook.createSheet("学生成绩表");
Row header = sheet.createRow(0);
for (int i = 0; i < headers.length; i++) {
header.createCell(i).setCellValue(headers[i]);
}
for (int i = 0; i < list.size(); i++) {
Row row = sheet.createRow(i + 1);
Score score = list.get(i);
Teaching teaching = score.getTeaching();
Student student = score.getStudent();
int fenshu = score.getScore();
Semester semester = teaching.getSemester();
Class class1 = student.getClass1();
Course course = teaching.getCourse();
row.createCell(0).setCellValue(semester.getSemesterName());
row.createCell(1).setCellValue(student.getStudentNo());
row.createCell(2).setCellValue(student.getStudentName());
row.createCell(3).setCellValue(class1.getClassName());
row.createCell(4).setCellValue(course.getCourseName());
row.createCell(5).setCellValue(fenshu);
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
hssfWorkbook.write(byteArrayOutputStream);
byte[] buffer = byteArrayOutputStream.toByteArray();
ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(buffer);
return byteArrayInputStream;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java物流管理系统.rar
共295个文件
png:67个
class:58个
java:58个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 144 浏览量
2022-01-15
20:55:41
上传
评论
收藏 14.53MB RAR 举报
温馨提示
java物流管理系统
资源推荐
资源详情
资源评论
收起资源包目录
java物流管理系统.rar (295个子文件)
ExcelUtil.class 7KB
UpLoadAction.class 7KB
LoginAction.class 6KB
TeacherAction.class 5KB
TeachingAction.class 5KB
StudentServiceImpl.class 5KB
StudentAction.class 5KB
TeacherServiceImpl.class 5KB
CourseAction.class 4KB
ScoreAction.class 4KB
TeachingServiceImpl.class 4KB
Student.class 4KB
ValidateCodeUtil.class 4KB
Teacher.class 3KB
MajorServiceImpl.class 3KB
ScoreSearchBean.class 3KB
TeachingSearchBean.class 2KB
MajorAction.class 2KB
Class.class 2KB
CourseServiceImpl.class 2KB
Teaching.class 2KB
LoginServiceImpl.class 2KB
Score.class 2KB
Address.class 2KB
Course.class 2KB
ValidateCodeServlet.class 2KB
TeacherSearchBean.class 2KB
DatagridBean.class 1KB
SemesterAction.class 1KB
EncodingFilter.class 1KB
Major.class 1KB
ScoreServiceImpl.class 1KB
StudentSearchBean.class 1KB
Admin.class 1KB
PageBean.class 1KB
Semester.class 1KB
Department.class 1KB
JsonUtil.class 994B
CourseSearchBean.class 917B
SemesterServiceImpl.class 911B
TeacherService.class 873B
TeacherDao.class 869B
StudentDao.class 839B
DateUtil.class 697B
TeachingService.class 688B
StringUtil.class 687B
StudentService.class 673B
CourseService.class 655B
CourseDao.class 594B
TeachingDao.class 591B
ScoreDao.class 511B
MajorDao.class 483B
ScoreService.class 441B
LoginDao.class 431B
LoginService.class 427B
MajorService.class 285B
SemesterService.class 254B
SemesterDao.class 242B
.classpath 817B
org.eclipse.wst.common.component 458B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.css 143KB
bootstrap.min.css 118KB
easyui.css 65KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
icon.css 3KB
main.css 459B
glyphicons-halflings-regular.eot 20KB
loading.gif 2KB
blank.gif 43B
blank.gif 43B
poi-3.9.jar 1.78MB
aspectjweaver-1.6.8.jar 1.55MB
mybatis-3.4.4.jar 1.53MB
mysql-connector-java-5.1.38.jar 961KB
freemarker-2.3.19.jar 909KB
struts2-core-2.3.16.3.jar 782KB
spring-context-3.0.5.RELEASE.jar 653KB
xwork-core-2.3.16.3.jar 639KB
javassist-3.11.0.GA.jar 600KB
spring-beans-3.0.5.RELEASE.jar 542KB
fastjson-1.2.31.jar 452KB
spring-jdbc-4.3.9.RELEASE.jar 418KB
spring-web-3.0.5.RELEASE.jar 386KB
spring-core-3.0.5.RELEASE.jar 373KB
spring-aop-3.1.0.RELEASE.jar 324KB
commons-lang3-3.1.jar 308KB
spring-tx-3.1.0.RELEASE.jar 240KB
ognl-3.0.6.jar 223KB
commons-io-2.2.jar 170KB
spring-expression-3.0.5.RELEASE.jar 166KB
javax.servlet-api-3.1.0.jar 94KB
commons-codec-1.5.jar 71KB
commons-fileupload-1.3.1.jar 67KB
commons-logging-1.1.1.jar 59KB
mybatis-spring-1.3.0.jar 52KB
spring-asm-3.0.5.RELEASE.jar 52KB
asm-3.3.jar 43KB
asm-commons-3.3.jar 37KB
共 295 条
- 1
- 2
- 3
资源评论
- 指北2562023-06-25支持这个资源,内容详细,主要是能解决当下的问题,感谢大佬分享~
一枚渣渣程序猿
- 粉丝: 50
- 资源: 328
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功