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

11,278

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));
Share:
11,278
engg
Author by

engg

Updated on June 04, 2022

Comments

  • engg
    engg about 2 years

    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.