jxl 解析格式中的border並將此border添加到另一個cell上

 
jxl.write.DateFormat df = new jxl.write.DateFormat(
"yyyy-MM-dd hh:mm:ss");
jxl.write.WritableCellFormat wcfDF = new jxl.write.WritableCellFormat(
df);
CellFormat format = sheet.getCell(c, r).getCellFormat();
//如果format中有邊框格式,則爲該datecell設置邊框
if(format.hasBorders()){
try {
//根據format得到邊框樣式//注:不能Border.ALL,這樣獲取不到邊框的樣式
BorderLineStyle border = format.getBorder(Border.BOTTOM);
Colour color = format.getBorderColour(Border.BOTTOM);
//Border.All所有邊框也可以是Border.BOTTOM等,border邊框樣式,color邊框顏色
//注:有方法wcfDF.setBorder(Border.ALL, border)此方法得到的邊框爲默認顏色-黑色。因此如果需要完全複製邊框格式,那麼需要加上顏色這個變量
wcfDF.setBorder(Border.ALL, border,color);
} catch (WriteException e) {
e.printStackTrace();
}
}

此時得到的樣式wcfDF就是僅有邊框格式的樣式了。此格式可用在new jxl.write.DateTime(c, r,(Date)value, wcfDF);中而不會造成data內容的破壞。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章