jxl格式化数字,日期

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));

posted @ 2017-06-28 08:54  黑土浊墨悟吾心  阅读(698)  评论(0编辑  收藏  举报