jxl operation excel styling

WritableFont headFont = new WritableFont(WritableFont.TIMES, 14,WritableFont.BOLD); 
//设置标题,字号14,加粗

  
<P>WritableFont countents = new WritableFont(WritableFont.TIMES,12); // 设置单元格内容,字号12
WritableCellFormat cell = new WritableCellFormat(contentFont);

cell.setAlignment(jxl.format.Alignment.CENTRE);// 单元格内容水平居中
cell.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 单元格内容垂直居中

cell.setBorder(Border.ALL, BorderLineStyle.THIN,jxl.format.Colour.BLACK); // 边框
// Border.ALL:上下左右都设置边框; BorderLineStyle.THIN: 细边框; jxl.format.Colour.BLACK: 黑颜色 

cell.setWrap(true);//是否换行 
 
 


WritableSheet sheet = book.createSheet("公文检索", 0); //创建一个新sheet
sheet.setColumnView(0, 80); //第1列宽
sheet.setColumnView(1, 80); //第2列宽
 

sheet.setRowView(i+1, 400);//某行的行高,一般用在循环中

//合并单元格
sheet.mergeCells(3,0,4,0);//(列,行,列,行)
 

//设置页边距(0.1d=0.26cm)
sheet.getSettings().setBottomMargin(0.7d);
sheet.getSettings().setTopMargin(0.7d);
sheet.getSettings().setLeftMargin(0.75d);
sheet.getSettings().setRightMargin(0.75d);


//设置打印方向为 横向,不设置为纵向

sheet.setPageSetup(PageOrientation.LANDSCAPE.LANDSCAPE,PaperSize.A4,0.5d,0.5d);
 

//设置页码,3个参数位置分别对应:左边、中间、右边
 sheet.setFooter("", "&P", "");

//设置冻结单元格,下拉时第一列固定
sheet.getSettings().setVerticalFreeze(1); 
 

//设置是否显示行数列数编号
sheet.getSettings().setPrintHeaders(true);

 

Reproduced in: https: //my.oschina.net/u/2260184/blog/540566

Guess you like

Origin blog.csdn.net/weixin_34090562/article/details/92186284
jxl