Writing to an excel

Joined
Aug 29, 2006
Messages
4
Reaction score
0
I have written the following code. This is taking the data from an excel “Report.xla”. The excel sheet contains 2 columns. Name and Counter. The programme check if the value of name “Sam” is already there in the excel sheet, if yes, then it will increase the value of the counter in the same row, by one and print it. If no, then it will print “Not!!!”

Now, I want that this increased value of the counter should be replaced in the excel sheet. Can anyone help me for this?

CODE:

import java.io.File;
import java.io.*;
import jxl.*;
import java.util.*;
import jxl.Workbook;
import jxl.read.biff.*;
import jxl.Sheet;
import jxl.Cell;
import jxl.write.*;

class readXl
{
public static void main(String[] args)
{
try
{
String filename = "Report.xls";
WorkbookSettings ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));

Workbook workbook = Workbook.getWorkbook(
new File(filename),ws);

Sheet sheet1;
sheet1 = workbook.getSheet(0);
//LabelCell lc = sheet1.findLabelCell("Name");
//System.out.println(lc.getString());
int i;
for (i=1; i<=3; i++)
{
Cell tempName = sheet1.getCell(0,i);
String[] name = new String[100];
name = tempName.getContents();
System.out.println(name);
if ("Sam".equalsIgnoreCase(name))
{
//System.out.println("Already available");
NumberCell tempCounter = (NumberCell)sheet1.getCell(1,i);
double[] counter = new double[100];
counter = tempCounter.getValue() + 1;
//counter = counter+1;
System.out.println(counter);
} else {
System.out.println("Not!!!");
}
}
workbook.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
catch (BiffException be)
{
be.printStackTrace();
}
}
}

Current OUTPUT:
A
Not!!!
Sam
4.0
Simmi
Not!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,039
Messages
2,570,376
Members
47,032
Latest member
OdellBerg4

Latest Threads

Top