poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "usharani chikkam" <usha.chik...@gmail.com>
Subject Re: one question regarding reading cell values
Date Tue, 09 May 2006 12:11:45 GMT
Hi Ramdas.....
I understand that you want to read content from a cell with a hearder name.
But the statement which you gave is wrong.
Followng is similar to your requirement you can try it....


public double getCellNumber(String cellName) throws Exception
 {
  fs = new POIFSFileSystem(new FileInputStream("workbook4.xls"));
  m_workbook = new HSSFWorkbook(fs);
  HSSFName myName = m_workbook.getNameAt(m_workbook.getNameIndex(cellName));
  String ref = myName.getReference();
  AreaReference myAreaReference = new AreaReference(ref);
  CellReference[] myCellReference = myAreaReference.getCells();
  HSSFSheet mySheet = m_workbook.getSheetAt(0);
  HSSFRow myRow = mySheet.getRow(myCellReference[0].getRow());
  HSSFCell myCell = myRow.getCell((short) myCellReference[0].getCol());
  return myCell.getNumericCellValue();

 }
cellName is the name of the cell header. we can get that cell using
getNameAt() method. For even more details you can go through the java docs.
This is a method in the class HSSFWorkbook and this class is in usermodel
package.

Hope this fils your requirement. Please do intimate me if you dint get it

Bye
Usha.


On 5/5/06, Sawant, Ramdas (IT) <Ramdas.Sawant@morganstanley.com> wrote:
>
> Hi all,
>
>            Can I read value from the cell using some header name
> instead of using the actual cell no.
>
> e.g instead of writing-
>
>                        HSSFCell secondCell = row.getCell((short)1);
>
> Can I write something like
>
>                        HSSFCell secondCell = row.getCell("headername");
>
>
>
> This similar problem like how we access the columns from the resultset.
>
>
>
> Incase if there is addition or deletion of  columns in the excel, then
> our code should not get affected..
>
>
>
> Thanks in advance..
>
>
>
>
>
> Regards,
>
> Ramdas Sawant
>
> ........................................................................
>
> Associate Consultant, Kanbay
>
> Manikchand Ikon, South Wing 18 Dhole Patil Road
> Pune  411001
> INDIA
>
> ........................................................................
> --------------------------------------------------------
>
> NOTICE: If received in error, please destroy and notify sender.  Sender
> does not waive confidentiality or privilege, and use is prohibited.
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message