/*
* 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.
* I will be adding formating constructors as well to format and organize by the
* different catagory. This is just a hard shell copy for the writing of the
* data
*/
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();
}
}
}