jxl单元格合并,样式

来源:互联网 发布:淘宝新店提取软件 编辑:程序博客网 时间:2024/03/28 20:47
wcfstringexceptiontablepathfile
[java] view plaincopyprint?
  1. public static String testEx() {  
  2.     // a, 计算路径   
  3.     SimpleDateFormat sdf = new SimpleDateFormat("/yyyy-MM-dd/");  
  4.     String datePath = sdf.format(new Date());  
  5.     datePath = "中国石油西部管道输气量交接电子文档" + datePath;  
  6.     String uuidFileName = UUID.randomUUID().toString();  
  7.   
  8.     // 创建文件夹   
  9.     File dir = new File(Globals.fielImportPath + datePath);  
  10.   
  11.     if (!dir.exists()) {  
  12.         dir.mkdirs();  
  13.     }  
  14.   
  15.     String path = Globals.fielImportPath + datePath + uuidFileName + "."  
  16.             + "xls";  
  17.   
  18.     try {  
  19.         WritableWorkbook wwb = Workbook.createWorkbook(new File(  
  20.                 path));  
  21.   
  22.         WritableSheet sheet1= wwb.createSheet("前五个站队"0);  
  23.         WritableSheet sheet2 = wwb.createSheet("后两个站队"1);  
  24.         WritableSheet sheet3 = wwb.createSheet("后三个站队"2);  
  25.           
  26.         sheet1.setColumnView(030); // 设置列的宽度  
  27.         sheet1.setColumnView(130); // 设置列的宽度  
  28.         sheet1.setColumnView(230); // 设置列的宽度  
  29.         sheet1.setColumnView(330); // 设置列的宽度  
  30.         sheet1.setColumnView(430); // 设置列的宽度  
  31.         sheet1.setColumnView(530); // 设置列的宽度  
  32.           
  33.         sheet1.setRowView(01000); // 设置行的高度  
  34.         sheet1.setRowView(1500); // 设置行的高度  
  35.           
  36.         /** 
  37.          * 定义单元格样式 
  38.          */  
  39.         WritableFont wf_title = new WritableFont(WritableFont.ARIAL, 20,  
  40.                 WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,  
  41.                 jxl.format.Colour.RED); // 定义格式 字体 下划线 斜体 粗体 颜色  
  42.         WritableFont wf_head = new WritableFont(WritableFont.ARIAL, 10,  
  43.                 WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,  
  44.                 jxl.format.Colour.GREEN); // 定义格式 字体 下划线 斜体 粗体 颜色  
  45.         WritableFont wf_table = new WritableFont(WritableFont.ARIAL, 8,  
  46.                 WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,  
  47.                 jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色  
  48.       
  49.         WritableCellFormat wcf_title = new WritableCellFormat(wf_title); // 单元格定义  
  50.         wcf_title.setBackground(jxl.format.Colour.BLACK); // 设置单元格的背景颜色  
  51.         wcf_title.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式  
  52.       
  53.         WritableCellFormat wcf_head = new WritableCellFormat(wf_head);   
  54.         wcf_head.setBackground(jxl.format.Colour.BLACK);  
  55.         wcf_head.setAlignment(jxl.format.Alignment.CENTRE);   
  56.       
  57.         WritableCellFormat wcf_table = new WritableCellFormat(wf_table);   
  58.         wcf_table.setBackground(jxl.format.Colour.BLACK);   
  59.         wcf_table.setAlignment(jxl.format.Alignment.CENTRE);   
  60.           
  61.         /** 
  62.          * 使用样式的单元格 
  63.          */  
  64.         // 1.添加Label对象三个参数意思:【列,行,值】   
  65.         sheet1.addCell(new Label(00"标题", wcf_title)); // 普通的带有定义格式的单元格  
  66.         sheet1.addCell(new Label(01"表头1", wcf_head));  
  67.         sheet1.addCell(new Label(11"表头2", wcf_head));  
  68.         sheet1.addCell(new Label(21"表头3", wcf_head));  
  69.         sheet1.addCell(new Label(31"表头4", wcf_head));  
  70.         sheet1.addCell(new Label(41"表头5", wcf_head));  
  71.         sheet1.addCell(new Label(51"表头6", wcf_head));  
  72.           
  73.         sheet1.mergeCells(0050); // 合并单元格  
  74.           
  75.   
  76.           
  77.   
  78.         // 写入Exel工作表   
  79.         wwb.write();  
  80.         // 关闭Excel工作薄对象   
  81.         wwb.close();  
  82.           
  83.   
  84.     } catch (Exception e) {  
  85.         e.printStackTrace();  
  86.         return "0";  
  87.     }  
  88.       
  89.   
  90.     return path;  
  91. }  
  92.   
  93. public static void main(String[] args) {  
  94.     UtilIO uio=new UtilIO();  
  95.     System.out.println(uio.testEx());  
  96. }  


 

0 0