how to read LabelCell of an excel sheet using Label

how to read LabelCell of an excel sheet using Label

Previous Home Next

 

This example make you aware of how you can read a Label Cell from an existing worksheet of an workbook. 

To read from an existing workbook you have to import the jxl.read.biff package which contains the various classes and interfaces to read a workbook.
 In this example we have used the findLabelCell(String str) method on the readable worksheet. After that we have displayed its name using the getString() method which returns the name of the Label..

In the given example we have created  a class named ReadLabelSheetXL. In its main method we have opened a workbook, and a sheet in that workbook is opened and then we have printed the name of  a particular Label contained inside the sheet.

 
package r4r.co.in
import jxl.read.biff.*;

import java.io.File;
import java.io.IOException;
import jxl.write.WriteException;

import java.util.Locale;
public class ReadLabelSheetXL {

/**
* @param args
*/
public static void main(String[] args) throws IOException, BiffException{
// TODO Auto-generated method stub
try
{
File f1=new File("F:/JAVA PROJECTS/Jexcel/src/r4r/co/in/firstsheet.xls");
WorkbookSettings ws=new WorkbookSettings();
ws.setLocale(new Locale("er","ER"));
Workbook workbook=Workbook.getWorkbook(f1,ws);

Sheet readsheet=workbook.getSheet(0);
System.out.println(readsheet.getName());
LabelCell lcobj=readsheet.findLabelCell("Sum");
System.out.println(lcobj.getString());
}
catch(IOException e)
{
e.printStackTrace();
}

catch(BiffException e)
{
e.printStackTrace();
}
}

}




Previous Home Next