JXL数字格式和单元格类型 [英] JXL Number Format and Cell Type
问题描述
文件excelFile =新文件(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();
如果我将数字格式更改为NumberFormats中的变量之一(例如NumberFormats.INTEGER)细胞类型是正确的。但数字当然显示为整数。我找不到符合我需要的NumberFormats中的一个变量。
任何人都知道一个方法来获取数字和单元格类型的显示是否正确?我需要所有数字显示1个十进制(即使它们是整数)。我不能切换到任何其他技术,我必须使用JXL。
对不起,如果这不是你想要的。但是,我了解您的需求是将单元格类型=数字与小数点后一位。您可以定义自己的数字格式。您可以使用此格式(#.0)来获取所需内容(例如:900.0,23.0,34324.0和.etc)
NumberFormat decimalNo = new NumberFormat(#。0);
WritableCellFormat numberFormat = new WritableCellFormat(decimalNo);
//写入数据表
Number numberCell = new Number(0,0,25,numberFormat);
excelSheet.addCell(numberCell);
I am using JXL to write an Excel file. The customer wants a certain 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 to be 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 matches my needs.
Anyone know of a way to get both the display of the numbers and the cell types correct? I need all of the numbers displayed with 1 decimal (even if they are integers). And I cannot switch to any other technology, I must use JXL.
I'm sorry if this is not what you want. But, what I understand about your needs is to have cell type=number with 1 decimal place. It is possible for you to define your own number formats. You can use this format ("#.0") to get what you want (eg: 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);
这篇关于JXL数字格式和单元格类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!