tags:

views:

419

answers:

2

Hello,

I am facing a problem while getting contents of cell using JXL api, if I am using formula in xls sheet. Right now I am using formula - IF($L10="","",+ROUND($L10*1.375,3)) in each cell but when the cell value is blank i am getting junk charactes when i call cell.getContents() method, the code snip is as follows - >>

Workbook = Workbook.getWorkbook(p_sourceFile);

excelsheet = workbook.getSheet(0);
for (int row = 1; row < noOfRows; row++)

{ cell = excelsheet.getCell(col, row); content = cell.getContents();

System.out.println("content-" + content); //Is giving me junk character ? when the cell value is blank.

...

It will be a great help if anyone can help me !!!

Regards, Amit

A: 

Try this:

NumberFormulaCell cell = (NumberFormulaCell) excelsheet.getCell(col, row);
content = cell.getValue();

From the JavaDocs for Cell.getContents():

Quick and dirty function to return the contents of this cell as a string. For more complex manipulation of the contents, it is necessary to cast this interface to correct subinterface

The necessary subinterface for a numerical formula is NumberFormulaCell. If you want to get the formula as a String then call cell.getFormula().

I'm not sure if I'm really answering your question here or not. If I'm not, could you post these junk characters that get printed out, please?

Cosmic Flame
A: 

Thanks Boss!!

Regards, Amit

Amit Ruwali