Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write formatted numbers as numbers in JExcel (jxl)

I am using Java Spring and jxl to create Excel workbook on server side. The data that needs to be shown in Excel consists of already formatted numbers. I am using

WritableCellFormat wcf = new WritableCellFormat();
wcf.setAlignment(Alignment.RIGHT);
....
....
sheet.addCell(new Label(j, i + 1, xxx, wcf));
//where xxx is a string which is a number already formatted

In the downloaded excel file, all these numbers are stored as text and so Excel can't use formulas on them, it gives a warning as 'Number stored as Text' and I have to do 'Convert to Number'.

In jxl, can we pass strings and tell to interpret them as numbers? All the numbers I have are valid numbers formatted differently using $, %, thousands separators. I don't want to convert them to valid numbers and give them formatting again while exporting to excel.

Please help. Thank you.

like image 235
engg Avatar asked Dec 22 '10 20:12

engg


1 Answers

I had a similar problem

I changed the variable to int and used new Number function it helped.

int eday =  Integer.parseInt(Trainingresult.getString("Day"));
//Label Eday = new Label(1, i, eday);
firstsheet.addCell(new Number(1,i,eday));
like image 143
Krishnakanth Jc Avatar answered Oct 10 '22 02:10

Krishnakanth Jc