Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Excel;
- import java.io.File;
- import jxl.Cell;
- import jxl.Sheet;
- import jxl.Workbook;
- public class ReadSheets {
- public static void main(String[] args) throws Exception {
- ReadSheets(6,3,2018);
- }
- static void ReadSheets(int date, int month, int year) {
- File f = new File( "/home1/ugrads/jtan1/CS2043/Practices/docs/CS2043_Template.xls");
- try {
- Workbook wb=Workbook.getWorkbook(f);
- int Num = wb.getNumberOfSheets();
- int mode = 0;
- for (int i = 0; i < 1; i++) {
- Sheet s = wb.getSheet(i);
- int row = s.getRows();
- int col = s.getColumns();
- for(int i1=0; i1<row;i1++) {
- int reading = -1;
- int counter = -1;
- for(int j=0;j<col;j++) {
- Cell c =s.getCell(j, i1);
- String str = c.getContents();
- if(str.equals("Teacher")) {
- mode = 1;
- i1 += 2;
- reading = -1;
- System.out.println("Teacher:");
- break;
- }
- else if(str.equals("Substitute ")) {
- mode = 2;
- reading = -1;
- i1 += 1;
- System.out.println("Substitute: ");
- System.out.println("ID Name Skill");
- break;
- }
- else if(str.equals("On-Caller"))
- {
- System.out.println();
- mode = 2;
- i1 += 1;
- break;
- }
- switch(mode) {
- case 0:
- System.exit(0);
- break;
- //Teacher Info Gathering
- case 1:
- if(str.equals("")) {
- break;
- }
- else if(reading == -1)
- {
- String name = str;
- System.out.println("Name: " +str);
- reading = 0;
- System.out.println("Period Class Room");
- }
- else if((reading)%2 == 0) {
- int period = reading/2+1;
- String course = str;
- System.out.print((reading/2)+1 + " " + str + " ");
- reading++;
- }
- else
- {
- String room = str;
- reading++;
- System.out.println(str);
- }
- break;
- case 2:
- if(str.equals("")) {
- break;
- }
- else if(counter == -1) {
- String ID = str;
- counter = 0;
- System.out.print(str + " ");
- }
- else if(counter < 1) {
- System.out.print(str + " ");
- counter++;
- }
- else if(counter < 2){
- String skill = str;
- counter++;
- System.out.println(str + " ");
- }
- else if(counter == 6){
- counter = 0;
- }
- break;
- }
- }
- }
- }
- System.out.println();
- int increase = 0;
- String firstDate = "";
- String finalDate = "";
- for(int i1 = 1; i1 < Num; i1++) {
- Sheet s = wb.getSheet(i1);
- int row = s.getRows();
- int col = s.getColumns();
- for(int i = 0; i < row; i++) {
- for(int j = 0; j < col; j++) {
- Cell c = s.getCell(j,0);
- String line = c.getContents();
- if(increase == 0) {
- firstDate = line;
- }else if(increase == 27) {
- finalDate = line;
- }
- increase++;
- }
- }
- increase = 0;
- int day1 = 0, month1 = 0, year1 = 0;
- int day2 = 0, month2 = 0, year2 = 0;
- String[] Date = firstDate.split("-");
- month1 = Integer.parseInt(Date[0]);
- day1 = Integer.parseInt(Date[1]);
- year1 = Integer.parseInt(Date[2]);
- String[] Date2 = finalDate.split("-");
- month2 = Integer.parseInt(Date2[0]);
- day2 = Integer.parseInt(Date2[1]);
- year2 = Integer.parseInt(Date2[2]);
- if(date < day2 && date > day1 && month == month2 && year == year2) {
- absent(date,day1,row,s);
- }
- }
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- System.out.println("completed");
- }
- public static void absent(int date, int day1, int row, Sheet s) {
- int different = date - day1;
- int distance = different *5;
- int position = 2;
- int Periodcounter = 1;
- for(int i = 2; i < row; i++) {
- Cell name = s.getCell(0,position);
- String teacher = name.getContents();
- System.out.println("Teacher:" + teacher);
- for(int j = distance-3; j < distance+1; j++) {
- Cell c = s.getCell(j,i);
- String line = c.getContents();
- System.out.print("Period" + Periodcounter + ": " + line + "\n");
- if(Periodcounter < 4) {
- Periodcounter++;
- }else {
- Periodcounter = 1;
- }
- }
- position++;
- }
- }
- }
Add Comment
Please, Sign In to add comment