File file = new File("test.xls"); try { Workbook wb = Workbook.getWorkbook(file); WritableWorkbook wwb = Workbook.createWorkbook(file,wb); WritableSheet ws = (WritableSheet) wwb.getSheet(0); //设置样式 WritableFont wf = new WritableFont(WritableFont.createFont("宋体"), 10,WritableFont.NO_BOLD,false);//字体设置 WritableCellFormat wcfF = new WritableCellFormat(wf); wcfF.setAlignment(jxl.format.Alignment.LEFT);//左右对齐 wcfF.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);//上下对齐 wcfF.setBorder(jxl.format.Border.RIGHT, jxl.format.BorderLineStyle.THIN);//边框 wcfF.setBorder(jxl.format.Border.BOTTOM, jxl.format.BorderLineStyle.THIN);//边框
Label lab = new Label(0, 2, "第一列第三行"); //可以Label lab = new Label(0, 2, "第一列第三行",wcfF); lab.setCellFormat(wcfF); ws.addCell(lab); wwb.write(); wwb.close(); } catch (IOException e) { e.printStackTrace(); } catch (BiffException e) { e.printStackTrace(); } catch (RowsExceededException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); }
金额列设置
// jxl.write.Number num = new jxl.write.Number(p_x, p_y, 9999);
// jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); //千分位与保留小数点后两位设置 // jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf);
//其他样式设置
// wcfN.setAlignment(jxl.format.Alignment.RIGHT); // wcfN.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); // wcfN.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK); // wcfN.setFont(new WritableFont(WritableFont.createFont("宋体"), 10));
// num.setCellFormat(wcfN);
// ws.addCell(num);