1。先申明一个book(创建一本书)
jxl.write.WritableWorkbook book = jxl.Workbook.createWorkbook(baos);
2。book创建好后就要创建一个sheet(创建书的一张纸)
jxl.write.WritableSheet sheet = book.createSheet("导出Excel", 0);
3。设置logo文件样式
<1 设置字体样式
jxl.write.WritableFont font_logo = new jxl.write.WritableFont(jxl.write.WritableFont.createFont("宋体"),14,jxl.write.WritableFont.BOLD);
<2 设置单元格样式
jxl.write.WritableCellFormat format_logo = new jxl.write.WritableCellFormat(font_logo);
<3 设置标题logo
format_logo.setAlignment(jxl.format.Alignment.CENTRE);
format_logo.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
4。设置列标题title文件样式
jxl.write.WritableFont font_title = new jxl.write.WritableFont(jxl.write.WritableFont.createFont("黑体"),10,jxl.write.WritableFont.BOLD);
jxl.write.WritableCellFormat format_title = new jxl.write.WritableCellFormat(font_title);
format_title.setBackground(jxl.format.Colour.GRAY_50);
format_title.setBorder(jxl.format.Border.LEFT, jxl.format.BorderLineStyle.THIN);
format_title.setAlignment(jxl.format.Alignment.CENTRE);
format_title.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
5。把logo与title添加进去
<1 添加logo
jxl.write.Label lableLogo = new jxl.write.Label(0,0,title,format_title);
sheet.addCell(lableLogo);
sheet.mergeCells(0, 0, columns.length - 1, 0);
<2 添加title
6。写出excel