jxl加边框,jxl合并单元格,单元格的设置

原文链接:https://my.oschina.net/u/1781072/blog/542616
jxl加边框

WritableWorkbook wwb = Workbook.createWorkbook(os);
WritableSheet ws = wwb.createSheet( "TestSheet1 ", 0);
WritableFont wf = newWritableFont(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();




jxl合并单元格

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);

本文转自:http://kingschan.iteye.com/blog/1568676/

转载于:https://my.oschina.net/u/1781072/blog/542616

上一篇:(最全最灵活地)利用Jxl工具包实现Excel表的内容读取 、写入(可向已有表中追加数据)


下一篇:java – 设置JXL自定义字体