JXL 颜色使用方式

来源:互联网 发布:淘宝老七家 编辑:程序博客网 时间:2024/05/20 23:06

一、颜色的转换。

#112233  这个颜色转为RGB数据的方式就是:把11,22,33从16进制分别计算成10进制赋给R,G,B即可。

 

二、jxl.format.Colour 

设置字体颜色,可以用

jxl.write.WritableFont wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD, false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);


设置背景颜色,可以用

wcfFC.setBackground(Colour.RED)或者Colour c=new Colour(int,String,int,int,int);这个该死的函数,网上都没有使用方法,只好打开反编译看了下 public static final Colour RED = new Colour(10, "red", 255, 0, 0);//这个字符串仅仅是一个描述,第一个参数也跟颜色没有关系,仅仅表明该颜色的VALUE值,最终还是调用RGB类

源代码如下

protected Colour(int paramInt1, String paramString, int paramInt2, int paramInt3, int paramInt4)  {    this.value = paramInt1;    this.string = paramString;    this.rgb = new RGB(paramInt2, paramInt3, paramInt4);

    Colour[] arrayOfColour = colours;    colours = new Colour[arrayOfColour.length + 1];    System.arraycopy(arrayOfColour, 0, colours, 0, arrayOfColour.length);    colours[arrayOfColour.length] = this;  }


另外附上一段操作的完整示例,没有使用背景颜色。

public ActionForward ExportExcel(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {    String operaterName=request.getParameter("operaterName");    String startTime=request.getParameter("startTime");    String endTime=request.getParameter("endTime");    String success=request.getParameter("success");    List<Map<String,Object>> list=dao.findAll(operaterName,startTime,endTime,success);    OutputStream os=null;try {os=response.getOutputStream();int PAGESIZE=5000;int t=0;//页签int listno=0;response.reset();String filename = new String(("操作日志").getBytes("GBK"), "ISO-8859-1");// 对文件名做编码设置response.setHeader("Content-disposition","attachment; filename=" + filename + ".xls");// 设定输出文件头response.setContentType("application/vnd.ms-excel;charset=GBK");// 定义输出类型jxl.write.WritableWorkbook wbook = Workbook.createWorkbook(os); // 建立excel文件jxl.write.WritableSheet wsheet = null;int listSize=list.size();int page=0;if(listSize%PAGESIZE==0){page=listSize/PAGESIZE;}else{page=listSize/PAGESIZE+1;}t=page;listno=listSize;for(int i=0;i<page;i++){//分页签,5000行一个页签// 设置excel标题jxl.write.WritableFont wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD, false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);wsheet = wbook.createSheet("当前第"+(t--)+"页", 0); // sheet名称wsheet.setColumnView(0, 15);//日志IDwsheet.setColumnView(1, 20);//操作者用户名wsheet.setColumnView(2, 15);//操作类型wsheet.setColumnView(3, 21);//操作时间wsheet.setColumnView(4, 100);//内容wsheet.setColumnView(4, 20);//操作结果wsheet.setColumnView(4, 30);//IPwsheet.setColumnView(4, 30);//主机名wsheet.setRowView(0, 550);wsheet.setRowView(1, 400);WritableCellFormat wcfFC = new WritableCellFormat(wfont);Label wlabel=null;wlabel=new Label(0, 0, "日志ID", wcfFC);wsheet.addCell(wlabel);wlabel=new Label(1, 0, "操作者用户名", wcfFC);wsheet.addCell(wlabel);wlabel=new Label(2, 0, "操作类型", wcfFC);wsheet.addCell(wlabel);wlabel=new Label(3, 0, "操作时间", wcfFC);wsheet.addCell(wlabel);wlabel=new Label(4, 0, "操作内容", wcfFC);wsheet.addCell(wlabel);wlabel=new Label(5, 0, "操作结果", wcfFC);wsheet.addCell(wlabel);wlabel=new Label(6, 0, "IP", wcfFC);wsheet.addCell(wlabel);wlabel=new Label(7, 0, "主机名", wcfFC);wsheet.addCell(wlabel);//设置内容wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 12,WritableFont.NO_BOLD, false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);wcfFC = new WritableCellFormat(wfont);//当总集合数不够一页,或者 总集合数比一页要大if(listSize>0&&(listSize<=PAGESIZE||(listSize>PAGESIZE&&listSize%PAGESIZE>=0))){Label label=null;while(listno>0){int j=listno-1;listno--;label=new Label(0,j%PAGESIZE+1,null2Str(list.get(j).get("ID")), wcfFC);wsheet.addCell(label);label=new Label(1, j%PAGESIZE+1,null2Str(list.get(j).get("USERID")), wcfFC);wsheet.addCell(label);label=new Label(2, j%PAGESIZE+1,null2Str(list.get(j).get("DESC_VALUE")), wcfFC);wsheet.addCell(label);label=new Label(3, j%PAGESIZE+1,null2Str(list.get(j).get("OPERATION_TIME")), wcfFC);wsheet.addCell(label);label=new Label(4, j%PAGESIZE+1,null2Str(list.get(j).get("CONTENT")), wcfFC);wsheet.addCell(label);label=new Label(5, j%PAGESIZE+1,null2Str(list.get(j).get("SUCCESS")), wcfFC);wsheet.addCell(label);label=new Label(6, j%PAGESIZE+1,null2Str(list.get(j).get("OPERATION_IP")), wcfFC);wsheet.addCell(label);label=new Label(7, j%PAGESIZE+1,null2Str(list.get(j).get("OPERATION_HOST")), wcfFC);wsheet.addCell(label);if(listno>0&&listno%PAGESIZE==0)break;}}}wbook.write();wbook.close();} catch (Exception e) {logger.info("TsOtherLogQueryAction:ExportExcel eror:"+e.getMessage());} finally {if(os!=null){try{os.flush();os.close();}catch(Exception e){}}if (null != list) {list.clear();}}return null;}        public String null2Str(Object s) {if (s == null) {return "";}return s.toString();}


 

原创粉丝点击