|
@@ -92,19 +92,20 @@ public class XlsSheetUtil {
|
|
|
// JSONObject v_json = (JSONObject)obj;
|
|
|
JSONObject v_json = JSONUtils.toEntity(obj, JSONObject.class);
|
|
|
//样式
|
|
|
- CellStyle style= wb.createCellStyle();
|
|
|
- cell.setCellStyle(style);
|
|
|
-
|
|
|
- //bs 边框样式 //bc 边框颜色
|
|
|
- setBorderStyle(style,v_json,"bs","bc");
|
|
|
- //bs_t 上边框样式 bc_t 上边框颜色
|
|
|
- setBorderStyle(style,v_json,"bs_t","bc_t");
|
|
|
- //bs_b 下边框样式 bc_b 下边框颜色
|
|
|
- setBorderStyle(style,v_json,"bs_b","bc_b");
|
|
|
- //bs_l 左边框样式 bc_l 左边框颜色
|
|
|
- setBorderStyle(style,v_json,"bs_l","bc_l");
|
|
|
- //bs_r 右边框样式 bc_r 右边框颜色
|
|
|
- setBorderStyle(style,v_json,"bs_r","bc_r");
|
|
|
+ CellStyle style = cell.getCellStyle();
|
|
|
+// CellStyle style= wb.createCellStyle();
|
|
|
+// cell.setCellStyle(style);
|
|
|
+
|
|
|
+// //bs 边框样式 //bc 边框颜色
|
|
|
+// setBorderStyle(style,v_json,"bs","bc");
|
|
|
+// //bs_t 上边框样式 bc_t 上边框颜色
|
|
|
+// setBorderStyle(style,v_json,"bs_t","bc_t");
|
|
|
+// //bs_b 下边框样式 bc_b 下边框颜色
|
|
|
+// setBorderStyle(style,v_json,"bs_b","bc_b");
|
|
|
+// //bs_l 左边框样式 bc_l 左边框颜色
|
|
|
+// setBorderStyle(style,v_json,"bs_l","bc_l");
|
|
|
+// //bs_r 右边框样式 bc_r 右边框颜色
|
|
|
+// setBorderStyle(style,v_json,"bs_r","bc_r");
|
|
|
|
|
|
|
|
|
//合并单元格
|
|
@@ -138,55 +139,55 @@ public class XlsSheetUtil {
|
|
|
setFormatByCt(wb,cell,style,v_json);
|
|
|
|
|
|
//font设置
|
|
|
- setCellStyleFont(wb,style,v_json);
|
|
|
+// setCellStyleFont(wb,style,v_json);
|
|
|
|
|
|
//bg 背景颜色
|
|
|
- if(v_json.containsKey("bg")){
|
|
|
- String _v=getByDBObject(v_json,"bg");
|
|
|
- if(_v != null) {
|
|
|
- Short _color=ColorUtil.getColorByStr(_v);
|
|
|
- if(_color!=null) {
|
|
|
- style.setFillBackgroundColor(_color);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+// if(v_json.containsKey("bg")){
|
|
|
+// String _v=getByDBObject(v_json,"bg");
|
|
|
+// if(_v != null) {
|
|
|
+// Short _color=ColorUtil.getColorByStr(_v);
|
|
|
+// if(_color!=null) {
|
|
|
+// style.setFillBackgroundColor(_color);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
//vt 垂直对齐 垂直对齐方式(0=居中,1=上,2=下)
|
|
|
- if(v_json.containsKey("vt")){
|
|
|
- Integer _v=getIntByDBObject(v_json, "vt");
|
|
|
- if(_v!=null && _v>=0 && _v<=2){
|
|
|
- style.setVerticalAlignment(ConstantUtil.getVerticalType(_v));
|
|
|
- }
|
|
|
- }
|
|
|
+// if(v_json.containsKey("vt")){
|
|
|
+// Integer _v=getIntByDBObject(v_json, "vt");
|
|
|
+// if(_v!=null && _v>=0 && _v<=2){
|
|
|
+// style.setVerticalAlignment(ConstantUtil.getVerticalType(_v));
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
//ht 水平对齐 水平对齐方式(0=居中,1=左对齐,2=右对齐)
|
|
|
- if(v_json.containsKey("ht")){
|
|
|
- Integer _v=getIntByDBObject(v_json,"ht");
|
|
|
- if(_v!=null && _v>=0 && _v<=2){
|
|
|
- style.setAlignment(ConstantUtil.getHorizontaltype(_v));
|
|
|
- }
|
|
|
- }
|
|
|
+// if(v_json.containsKey("ht")){
|
|
|
+// Integer _v=getIntByDBObject(v_json,"ht");
|
|
|
+// if(_v!=null && _v>=0 && _v<=2){
|
|
|
+// style.setAlignment(ConstantUtil.getHorizontaltype(_v));
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
//tr 文字旋转 文字旋转角度(0=0,1=45,2=-45,3=竖排文字,4=90,5=-90)
|
|
|
- if(v_json.containsKey("tr")){
|
|
|
- Integer _v=getIntByDBObject(v_json, "tr");
|
|
|
- if(_v!=null){
|
|
|
- style.setRotation(ConstantUtil.getRotation(_v));
|
|
|
- }
|
|
|
- }
|
|
|
+// if(v_json.containsKey("tr")){
|
|
|
+// Integer _v=getIntByDBObject(v_json, "tr");
|
|
|
+// if(_v!=null){
|
|
|
+// style.setRotation(ConstantUtil.getRotation(_v));
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
//tb 文本换行 0 截断、1溢出、2 自动换行
|
|
|
// 2:setTextWrapped 0和1:IsTextWrapped = true
|
|
|
- if(v_json.containsKey("tb")){
|
|
|
- Integer _v=getIntByDBObject(v_json,"tb");
|
|
|
- if(_v!=null){
|
|
|
- if(_v>=0 && _v<=1){
|
|
|
- style.setWrapText(false);
|
|
|
- }else{
|
|
|
- style.setWrapText(true);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+// if(v_json.containsKey("tb")){
|
|
|
+// Integer _v=getIntByDBObject(v_json,"tb");
|
|
|
+// if(_v!=null){
|
|
|
+// if(_v>=0 && _v<=1){
|
|
|
+// style.setWrapText(false);
|
|
|
+// }else{
|
|
|
+// style.setWrapText(true);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
//f 公式
|
|
|
if(v_json.containsKey("f")){
|
|
@@ -284,6 +285,8 @@ public class XlsSheetUtil {
|
|
|
//单元格创建标识,false表示已有
|
|
|
boolean createCellFlag = false;
|
|
|
|
|
|
+ final CellStyle contantCellStyle = getContantCellStyle(wb);
|
|
|
+
|
|
|
for(int m = 0, n = borderInfo.size(); m < n; m++) {
|
|
|
JSONObject borderCell = borderInfo.getJSONObject(m);
|
|
|
String rangeType = borderCell.getString("rangeType");
|
|
@@ -321,28 +324,28 @@ public class XlsSheetUtil {
|
|
|
createCellFlag = false;
|
|
|
|
|
|
Cell cell = row.getCell(colStart);
|
|
|
- CellStyle cellStyle;
|
|
|
+// CellStyle cellStyle;
|
|
|
if(cell == null) {
|
|
|
createCellFlag = true;
|
|
|
cell = row.createCell(colStart);
|
|
|
}
|
|
|
|
|
|
- CellStyleCellBo cellBo = new CellStyleCellBo();
|
|
|
- cellBo.setBottomBorderColor(colorByStr);
|
|
|
- cellBo.setBorderBottom(borderStyle);
|
|
|
-
|
|
|
- cellBo.setTopBorderColor(colorByStr);
|
|
|
- cellBo.setBorderTop(borderStyle);
|
|
|
-
|
|
|
- cellBo.setLeftBorderColor(colorByStr);
|
|
|
- cellBo.setBorderLeft(borderStyle);
|
|
|
-
|
|
|
- cellBo.setRightBorderColor(colorByStr);
|
|
|
- cellBo.setBorderRight(borderStyle);
|
|
|
-
|
|
|
- cellStyle = getCellStyle(cell, cellBo, cellStyleMap, wb, createCellFlag);
|
|
|
-
|
|
|
- cell.setCellStyle(cellStyle);
|
|
|
+// CellStyleCellBo cellBo = new CellStyleCellBo();
|
|
|
+// cellBo.setBottomBorderColor(colorByStr);
|
|
|
+// cellBo.setBorderBottom(borderStyle);
|
|
|
+//
|
|
|
+// cellBo.setTopBorderColor(colorByStr);
|
|
|
+// cellBo.setBorderTop(borderStyle);
|
|
|
+//
|
|
|
+// cellBo.setLeftBorderColor(colorByStr);
|
|
|
+// cellBo.setBorderLeft(borderStyle);
|
|
|
+//
|
|
|
+// cellBo.setRightBorderColor(colorByStr);
|
|
|
+// cellBo.setBorderRight(borderStyle);
|
|
|
+
|
|
|
+// cellStyle = getCellStyle(cell, cellBo, cellStyleMap, wb, createCellFlag);
|
|
|
+
|
|
|
+ cell.setCellStyle(contantCellStyle);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -362,47 +365,74 @@ public class XlsSheetUtil {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- CellStyleCellBo cellBo = new CellStyleCellBo();
|
|
|
- JSONObject bObj = cellBorderValue.getJSONObject("b");
|
|
|
- if(bObj != null) {
|
|
|
- String color = bObj.getString("color");
|
|
|
- Short style = bObj.getShort("style");
|
|
|
- cellBo.setBottomBorderColor(ColorUtil.getColorByStr(color));
|
|
|
- cellBo.setBorderBottom(BorderStyle.valueOf(style));
|
|
|
- }
|
|
|
+// CellStyleCellBo cellBo = new CellStyleCellBo();
|
|
|
+// JSONObject bObj = cellBorderValue.getJSONObject("b");
|
|
|
+// if(bObj != null) {
|
|
|
+// String color = bObj.getString("color");
|
|
|
+// Short style = bObj.getShort("style");
|
|
|
+// cellBo.setBottomBorderColor(ColorUtil.getColorByStr(color));
|
|
|
+// cellBo.setBorderBottom(BorderStyle.valueOf(style));
|
|
|
+// }
|
|
|
+//
|
|
|
+// JSONObject tObj = cellBorderValue.getJSONObject("t");
|
|
|
+// if(tObj != null) {
|
|
|
+// String color = tObj.getString("color");
|
|
|
+// Short style = tObj.getShort("style");
|
|
|
+// cellBo.setTopBorderColor(ColorUtil.getColorByStr(color));
|
|
|
+// cellBo.setBorderTop(BorderStyle.valueOf(style));
|
|
|
+// }
|
|
|
+//
|
|
|
+// JSONObject lObj = cellBorderValue.getJSONObject("l");
|
|
|
+// if(lObj != null) {
|
|
|
+// String color = lObj.getString("color");
|
|
|
+// Short style = lObj.getShort("style");
|
|
|
+// cellBo.setLeftBorderColor(ColorUtil.getColorByStr(color));
|
|
|
+// cellBo.setBorderLeft(BorderStyle.valueOf(style));
|
|
|
+// }
|
|
|
+//
|
|
|
+// JSONObject rObj = cellBorderValue.getJSONObject("r");
|
|
|
+// if(rObj != null) {
|
|
|
+// String color = rObj.getString("color");
|
|
|
+// Short style = rObj.getShort("style");
|
|
|
+// cellBo.setRightBorderColor(ColorUtil.getColorByStr(color));
|
|
|
+// cellBo.setBorderRight(BorderStyle.valueOf(style));
|
|
|
+// }
|
|
|
+
|
|
|
+// CellStyle cellStyle = getCellStyle(cell, cellBo, cellStyleMap, wb, false);
|
|
|
+ cell.setCellStyle(contantCellStyle);
|
|
|
|
|
|
- JSONObject tObj = cellBorderValue.getJSONObject("t");
|
|
|
- if(tObj != null) {
|
|
|
- String color = tObj.getString("color");
|
|
|
- Short style = tObj.getShort("style");
|
|
|
- cellBo.setTopBorderColor(ColorUtil.getColorByStr(color));
|
|
|
- cellBo.setBorderTop(BorderStyle.valueOf(style));
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- JSONObject lObj = cellBorderValue.getJSONObject("l");
|
|
|
- if(lObj != null) {
|
|
|
- String color = lObj.getString("color");
|
|
|
- Short style = lObj.getShort("style");
|
|
|
- cellBo.setLeftBorderColor(ColorUtil.getColorByStr(color));
|
|
|
- cellBo.setBorderLeft(BorderStyle.valueOf(style));
|
|
|
- }
|
|
|
|
|
|
- JSONObject rObj = cellBorderValue.getJSONObject("r");
|
|
|
- if(rObj != null) {
|
|
|
- String color = rObj.getString("color");
|
|
|
- Short style = rObj.getShort("style");
|
|
|
- cellBo.setRightBorderColor(ColorUtil.getColorByStr(color));
|
|
|
- cellBo.setBorderRight(BorderStyle.valueOf(style));
|
|
|
- }
|
|
|
|
|
|
- CellStyle cellStyle = getCellStyle(cell, cellBo, cellStyleMap, wb, false);
|
|
|
- cell.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 获取边框线常量样式
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @param wb
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static CellStyle getContantCellStyle(Workbook wb) {
|
|
|
+ final CellStyle cellStyle = wb.createCellStyle();
|
|
|
|
|
|
+ final Short color = ColorUtil.getColorByStr("rgb(0, 0, 0)");
|
|
|
|
|
|
+ cellStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ cellStyle.setBottomBorderColor(color);
|
|
|
|
|
|
- }
|
|
|
+ cellStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ cellStyle.setTopBorderColor(color);
|
|
|
+
|
|
|
+ cellStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ cellStyle.setLeftBorderColor(color);
|
|
|
+
|
|
|
+ cellStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ cellStyle.setRightBorderColor(color);
|
|
|
+
|
|
|
+ return cellStyle;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -733,7 +763,7 @@ public class XlsSheetUtil {
|
|
|
case "d":{
|
|
|
//日期
|
|
|
Date _d=null;
|
|
|
-// String v=getByDBObject(dbObject,"m");
|
|
|
+// String v=getByDBObject(dbObdebtfree/updateCheckject,"m");
|
|
|
// if(v.length()==0){
|
|
|
// v=getByDBObject(dbObject,"v");
|
|
|
// }
|