[go: up one dir, main page]

Menu

[r8]: / reports / Report.java  Maximize  Restore  History

Download this file

104 lines (76 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
/*
* Created by Matt--AKA Ziggy
* 10/28/10
*
* this is just a general outline of how we could write to the excel sheet
* we would of course first need to know how the text files actually will look
* like. Sorry for not breaking it down more with more constructors and ect
*/
package test;
import java.io.*;
import java.util.*;
import jxl.Workbook;
import jxl.write.*;
public class Report
{
/** Create the Excel sheet
*
*/
public static void writeDataSheet()
{
String employee = "";
String hoursWorked = "0";
String moneyEarned = "0";
String data;
try
{
//Used for reading file
BufferedReader br = new BufferedReader(new FileReader("names.txt"));
//Creating Excel Document
WritableWorkbook workbook =
Workbook.createWorkbook(new File("report.xls"));
WritableSheet sheet1 =
workbook.createSheet("Employee Timeclock", 0);
//Creating heading inside excel
Label employeeHeading = new Label(0,0,"Employee Name");
Label hoursHeading = new Label(1,0,"Hours Worked");
Label incomeHeading = new Label(2,0,"Income");
//writing the Heading to excel
sheet1.addCell(employeeHeading);
sheet1.addCell(hoursHeading);
sheet1.addCell(incomeHeading);
for(int i = 1; i < 4; i++)
{
if(br.ready())
{
//Obtain data from file
data = br.readLine();
StringTokenizer st = new StringTokenizer(data,",");
//seperate the data from the file
employee = st.nextToken();
hoursWorked = st.nextToken();
moneyEarned = st.nextToken();
//set location of the data to be printed
Label lbl_employee = new Label(0,i,employee);
Label lbl_hours = new Label(1,i,hoursWorked);
Label lbl_income = new Label(2,i,moneyEarned);
//print data to the excel document
sheet1.addCell(lbl_employee);
sheet1.addCell(lbl_hours);
sheet1.addCell(lbl_income);
System.out.println(data);
}
}
workbook.write();
workbook.close();
}
catch( IOException e )
{
e.printStackTrace();
}
catch( WriteException e )
{
e.printStackTrace();
}
}
}