今天遇到一个让她比较苦恼的事情,她手上有一大堆传统Excel格式的课程安排表,现在想将他们全搞成日历格式的,她只能手动一个一个搞,效率很低也很无聊,帮她做了个小工具,通过工具实现格式转换,解放双手!
原来的数据格式是这样:
转完的格式是这样的:
思路:
1.原表格中的数据可以抽象成一个类,类中的属性对应原表格中的列。
package xiaming.chen.domain;
/**
* Created by xiamingchen on 2017/7/1.
*/
public class Info {
private String date;
private String timeBegin;
private String course;
private int hours;
private String teacher;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTimeBegin() {
return timeBegin;
}
public void setTimeBegin(String timeBegin) {
this.timeBegin = timeBegin;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public int getHours() {
return hours;
}
public void setHours(int hours) {
this.hours = hours;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
@Override
public String toString() {
return course + "-" + teacher;
}
}
2.先将原表格中的数据读取出来,生成一堆的Info对象。
3.初始化新的Excel,将第一列的课表时间安排写入。
4.将日期写入表格,并返回日期总数
5.将每节课的信息填入表内
package xiaming.chen;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.u