jxl格式化数字,日期

时间:2022-08-09 19:21:46

WritableFont NormalFont = new WritableFont(WritableFont.createFont("宋体"), 11);
jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#"); // 设置数字格式
jxl.write.NumberFormat dob = new jxl.write.NumberFormat("#.##"); // 设置数字格式
jxl.write.WritableCellFormat formatInt = new jxl.write.WritableCellFormat(NormalFont, nf); // 设置表单格式
jxl.write.WritableCellFormat formatDouble = new jxl.write.WritableCellFormat(NormalFont, dob); // 设置表单格式

NormalFont可以不写(new jxl.write.WritableCellFormat(NormalFont, nf); // 设置表单格式)
DateFormat df = new jxl.write.DateFormat("yyyy/MM/dd");
WritableCellFormat formatDate = new WritableCellFormat(NormalFont, df);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");


String str= “555”;
double dstr = Double.parseDouble(str);
writeSheet.addCell(new jxl.write.Number(7, i + 1, dstr , formatInt));
String str2= “5.55”;

double cell6 = Double.parseDouble(str2);
writeSheet.addCell(new jxl.write.Number(6, i + 1, cell6, formatDouble));

String use_date1 = use_date.toString();
writeSheet.addCell(new jxl.write.DateTime(3, i + 1, sdf.parse(use_date1), formatDate));