JXL number format and cell type

I am using JXL to write an excel file. The client wants a specific column to display numbers with one decimal place. They also want the cell types to be Number. When I use the following (test) code, the numbers are displayed correctly, but the cell type is "Custom".

File excelFile = new File("C:\\Users\\Rachel\\Desktop\\TestFile.xls"); WritableWorkbook excelBook = Workbook.createWorkbook(excelFile); WritableSheet excelSheet = excelBook.createSheet("Test Sheet", 0); WritableFont numberFont = new WritableFont(WritableFont.ARIAL); WritableCellFormat numberFormat = new WritableCellFormat(numberFont, new NumberFormat("#0.0")); Number numberCell = new Number(0, 0, 25, numberFormat); excelSheet.addCell(numberCell); excelBook.write(); excelBook.close(); 

If I change the number format as one of the variables in NumberFormats (e.g. NumberFormats.INTEGER), the cell type is correct. But the numbers are displayed as integers, of course. I cannot find a variable in NumberFormats that fits my needs.

Does anyone know how to choose the right display of numbers and cell types? I need all numbers to display with 1 decimal point (even if they are integers). And I can’t switch to any other technology, I have to use JXL.

+6
source share
1 answer

Sorry if this is not what you want. But, what I understand about your needs, you need to have cell type = number with 1 decimal point. You can define your own number formats. You can use this format ("# .0") to get what you want (for example: 900.0,23.0,34324.0 and .etc)

 NumberFormat decimalNo = new NumberFormat("#.0"); WritableCellFormat numberFormat = new WritableCellFormat(decimalNo); //write to datasheet Number numberCell = new Number(0, 0, 25, numberFormat); excelSheet.addCell(numberCell); 
+7
source

Source: https://habr.com/ru/post/891733/


All Articles