java Jxl 操作Excel(五)

2014-11-24 03:29:11 · 作者: · 浏览: 4
Border(Border.ALL, BorderLineStyle.THICK); // 添加边框
cell.setCellFormat(wcf);

// 将B3的字体改为仿宋_GB2312
cell = sheet.getWritableCell(1,2);
WritableFont fs = new WritableFont(WritableFont.createFont("仿宋_GB2312"),
11);
wcf = new WritableCellFormat(fs);
cell.setCellFormat(wcf);

// 将B4的字号改为20
cell = sheet.getWritableCell(1,3);
WritableFont size20 = new WritableFont(WritableFont.createFont("宋体"),
20);
wcf = new WritableCellFormat(size20);
cell.setCellFormat(wcf);

// 将B5的字体改为加粗
cell = sheet.getWritableCell(1,4);
WritableFont bold = new WritableFont(WritableFont.createFont("宋体"),
11,
WritableFont.BOLD);
wcf = new WritableCellFormat(bold);
cell.setCellFormat(wcf);

// 将B6的字体改为倾斜
cell = sheet.getWritableCell(1,5);
WritableFont italic = new WritableFont(WritableFont.createFont("宋体"),
11,
WritableFont.NO_BOLD,
true);
wcf = new WritableCellFormat(italic);
cell.setCellFormat(wcf);

// 将B7字体加下划线
cell = sheet.getWritableCell(1,6);
WritableFont underline = new WritableFont(WritableFont.createFont("宋体"),
11,
WritableFont.NO_BOLD,
false,
UnderlineStyle.SINGLE);
wcf = new WritableCellFormat(underline);
cell.setCellFormat(wcf);

// 将B8的文字改为“待修改文字-已修改”
cell = sheet.getWritableCell(1,7);
if (cell.getType() == CellType.LABEL)
{
Label lc = (Label) cell;
lc.setString(lc.getString() + " - 已修改");
}

// 将B9文字对齐方式改为垂直居中、右对齐
cell = sheet.getWritableCell(1,8);
WritableFont align = new WritableFont(WritableFont.createFont("宋体"),
11);
wcf = new WritableCellFormat(align);
wcf.setAlignment(Alignment.RIGHT); // 设置为右对齐
wcf.setVerticalAlignment(VerticalAlignment.CENTRE); // 设置为垂直居中
cell.setCellFormat(wcf);

// 将E3文字改为自动换行
cell = sheet.getWritableCell(4,2);
WritableFont justify = new WritableFont(WritableFont.createFont("宋体"),
11);
wcf = new WritableCellFormat(justify);
wcf.setAlignment(Alignment.JUSTIFY);
cell.setCellFormat(wcf);