添加单元格的时候可以设定单元格格式:
WritableFont wfc = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false,UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.RED);
WritableCellFormat wcfFC = new WritableCellFormat(wfc);
Label labelC = new Label(1, 0, "This is a Label Cell", wcfFC);
ws.addCell(labelCFC);
WritableCellFormat wcfFC = new WritableCellFormat(wfc);
Label labelC = new Label(1, 0, "This is a Label Cell", wcfFC);
ws.addCell(labelCFC);
还可以添加数字单元格(就单元格内容为数字(非以文本格式保存)):
Number number = new jxl.write.Number(3, 4, 3.14159); //将数字3.14159 放到单元格D5
ws.addCell(number);
ws.addCell(number);
设定数字格式:
NumberFormat nf = new jxl.write.NumberFormat("#.##"); //设定带小数点数字格式
WritableCellFormat wcfN = new jxl.write.WritableCellFormat(wfc,nf);//设定带小数数字单元格格式,wcf见上
WritableCellFormat wcfN = new jxl.write.WritableCellFormat(wfc,nf);//设定带小数数字单元格格式,wcf见上
number = new Number(3, 4, 3.14159,wcfN); //只保存3.14
ws.addCell(number);
jxl还可以向excel中添加图片:
File image = new File("E:\\MyDoc\\2.png");//图片文件
WritableImage wimage = new WritableImage(0,1,3,2,image);//将图片放到excel中,
WritableImage wimage = new WritableImage(0,1,3,2,image);//将图片放到excel中,
//起始点为单元格(0,1)即A2左上角,宽度为3个单元格,高度为2个单元格
ws.addImage(wimage);
删除已有图片:
ws.addImage(wimage);
删除已有图片:
WritableImage img = ws.getImage(0);//获得工作表中图片(以图片所在图层标示),最底层为0,依次增长
if(null != img)
ws.removeImage(img);//删除图片
if(null != img)
ws.removeImage(img);//删除图片