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!!!
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!!!