当前位置:网站首页 > 技术博客 > 正文

jconsole怎么使用

jxl加边框

WritableFont   wf   =   new   WritableFont(WritableFont.TIMES,18,WritableFont.BOLD,true);
WritableCellFormat   wcf   =   new   WritableCellFormat(wf);
wcf.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
Label   labelcf   =   new   Label(1,0, "this   is   a   label   with   border   test ",wcf);
ws.addCell(labelcf);
wwb.write();
wwb.close();

 

public static void writeExcel(OutputStream os )throws Exception
   {
           try
           {
          
            jxl.write.WritableWorkbook wwb=Workbook.createWorkbook(os);
//                jxl.write.WritableSheet ws = wwb.createSheet("TestSheet1", 0);
                jxl.write.WritableSheet ws =wwb.createSheet("testsheet1",0);
                jxl.write.Label labelC =new jxl.write.Label(0,0,"我爱中国");
        ws.addCell(labelC);
                labelC =new jxl.write.Label(1,2,"我爱中国1,2");
        ws.addCell(labelC);

                jxl.write.WritableFont wfc =new jxl.write.WritableFont(WritableFont.ARIAL,20,
                        WritableFont.BOLD,false,
                        UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.GREEN);
                jxl.write.WritableCellFormat wcfFc =new jxl.write.WritableCellFormat(wfc);
                 labelC =new jxl.write.Label(6,0,"中国我爱",wcfFc);
                ws.addCell(labelC);
                WritableFont wf_merge = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,
                        false,UnderlineStyle.DOUBLE_ACCOUNTING,jxl.format.Colour.GREEN);
   WritableCellFormat wff_merge = new WritableCellFormat(wf_merge);
  // wff_merge.setBackground(jxl.format.Colour.BLACK);
   jxl.write.Label label30 = new Label(3,0,"Label30",wff_merge);   
   ws.addCell(label30);
   //合并单元格
    ws.mergeCells(3,0,4,0);


                wwb.write();
                wwb.close();
                       
           }
           catch (Exception e )
           {
                   throw e;
           }
   }

使用WritableCellFormat 的setWrap(true)可以设成自动换行,然后再用WritableSheet的setRowView设置行的高度,setColumnView设置列的宽度

行高和列宽
WritableSheet.setRowView(int i,int height);
作用是指定第i+1行的高度,比如:
//将第一行的高度设为200
sheet.setRowView(0,200);
WritableSheet.setColumnView(int i,int width);
作用是指定第i+1列的宽度,比如:
//将第一列的宽度设为30
sheet.setColumnView(0,30);

 

单元格居中

Label label=new Label(column,row,labelValue);
       WritableCellFormat cellFormat=new WritableCellFormat();
       cellFormat.setAlignment(jxl.format.Alignment.CENTER);
       label.setCellFormat(cellFormat);
       sheetWrite.addCell(label);

 

 

 

  WritableCellFormat headerFormat = new WritableCellFormat();

  //水平居中对齐

  headerFormat.setAlignment(Alignment.CENTRE);

  //竖直方向居中对齐

  headerFormat.setVerticalAlignment

  (VerticalAlignment.CENTRE);

  //建立标签,参数依次为:列索引、行索引、内容、格式

  Label seqLabel = new Label(0, 0, "序号", headerFormat);

  //增加单元格

  sheet.addCell(seqLabel);

  //合并单元格,参数依次为:列索引、行索引、列索引+需要合并

  的列的个数、行索引+需要合并的行的个数

  sheet.mergeCells(0, 0, 0, 1);

  //设置单元格宽度,以字符为单位

  sheet.setColumnView(0, "序号".length() + 10);

  Label basicInfoLabel = new Label(1, 0, "基本信息",

  headerFormat);

  sheet.addCell(basicInfoLabel);

  sheet.mergeCells(1, 0, 3, 0);//合并垮了3行。

  sheet.mergeCells(1, 1, 1, 3);//合并垮了3列。

  label = new Label(0, 1, "苹果”);

  sheet.mergeCells(0,1, 0, 3- 1);//合并垮了3列。

  WritableCellFormat cellFormat = new WritableCellFormat();

  cellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);

  // 垂直居中

  label.setCellFormat(cellFormat);

  sheet.addCell(label);

 

版权声明


相关文章:

  • 无法更新项目的依赖项2024-10-23 19:30:01
  • js都是怎么服务的2024-10-23 19:30:01
  • vue2使用swiper2024-10-23 19:30:01
  • vue3使用vue2组件2024-10-23 19:30:01
  • excel xll开发工具2024-10-23 19:30:01
  • js switch判断成绩2024-10-23 19:30:01
  • 如何用vue cli创建一个项目2024-10-23 19:30:01
  • javax.jws2024-10-23 19:30:01
  • 创建一个vue项目具体步骤2024-10-23 19:30:01
  • vue2.2024-10-23 19:30:01