LuckySheet打印工具类

LuckySheet工具类


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.*;
import java.awt.Color;
import java.io.*;
import java.util.*;
import java.util.List;

public class ExportExcel {
    /***
     * 基于POI解析 从0开始导出xlsx文件,不是基于模板
     * @param title 表格名
     * @param newFileDir 保存的文件夹名
     * @param newFileName 保存的文件名
     * @param excelData luckysheet 表格数据
     */
    public static void exportLuckySheetXlsxByPOI(String title, String newFileDir, String newFileName, String excelData) {
        excelData = excelData.replace("
", "\\r\\n");//去除luckysheet中 &#xA 的换行
        JSONArray jsonArray = (JSONArray) JSONObject.parse(excelData);
        XSSFWorkbook excel = new XSSFWorkbook();
        // SXSSFWorkbook excel = new SXSSFWorkbook(5000);
        for (int sheetIndex = 0; sheetIndex < jsonArray.size(); sheetIndex++) {
            JSONObject jsonObject = (JSONObject) jsonArray.get(sheetIndex);
            // System.out.println(jsonObject.toString());
            JSONArray celldataObjectList = jsonObject.getJSONArray("celldata");
            JSONArray rowObjectList = jsonObject.getJSONArray("visibledatarow");
            JSONArray colObjectList = jsonObject.getJSONArray("visibledatacolumn");
            JSONArray dataObjectList = jsonObject.getJSONArray("data");
            JSONObject mergeObject = jsonObject.getJSONObject("config").getJSONObject("merge");//合并单元格
            JSONObject columnlenObject = jsonObject.getJSONObject("config").getJSONObject("columnlen");//表格列宽
            JSONObject colhiddenObject = jsonObject.getJSONObject("config").getJSONObject("colhidden");//表格列宽
            JSONObject rowlenObject = jsonObject.getJSONObject("config").getJSONObject("rowlen");//表格行高
            JSONArray borderInfoObjectList = jsonObject.getJSONObject("config").getJSONArray("borderInfo");//边框样式
            JSONObject imagesObject =  jsonObject.getJSONObject("images");
            String imgSrc="";
            if(imagesObject!=null&&imagesObject.size()>0){
                for(String object:imagesObject.keySet()){
                    if(((JSONObject)imagesObject.get(object)).containsKey("src")){
                        imgSrc=((JSONObject)imagesObject.get(object)).getString("src");
                        break;
                    }
                }
            }

            //创建操作Excel的XSSFWorkbook对象
            //创建XSSFSheet对象
            XSSFSheet sheet = excel.createSheet(jsonObject.getString("name"));
            try {
                //add picture data to this workbook.
                String path=Thread.currentThread().getContextClassLoader().getResource("").getPath();
                InputStream is = new FileInputStream(path.substring(0,path.indexOf("图片路径");
                byte[] bytes = IOUtils.toByteArray(is);
              //  byte[] bytes= DatatypeConverter.parseBase64Binary(imgSrc);
                int pictureIdx = excel.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
                is.close();
                CreationHelper helper = excel.getCreationHelper();
                // Create the drawing patriarch.  This is the top level container for all shapes.
                Drawing drawing = sheet.createDrawingPatriarch();
                //add a picture shape
                ClientAnchor anchor = helper.createClientAnchor();
                //set top-left corner of the picture,
                //subsequent call of Picture#resize() will operate relative to it
                anchor.setCol1(1);
                anchor.setRow1(0);
                anchor.setCol2(6);
                anchor.setRow2(3);
                Picture pict = drawing.createPicture(anchor, pictureIdx);
                //auto-size picture relative to its top-left corner
                //pict.resize();
            } catch (Exception e) {
                e.printStackTrace();
            }
            //设置页眉页脚
            Header header=  sheet.getHeader();
            header.setLeft("&L&G");
            HSSFHeader.fontSize((short) 16);
  

            System.out.println("excel Sheets数量-------" + excel.getNumberOfSheets() + jsonObject.getString("name"));
            List<JSONObject> cells_json = (List<JSONObject>) jsonObject.get("celldata");
            Map<Integer, List<JSONObject>> cellMap = cellGroup(cells_json);
            //循环每一行
            System.out.println("设置单元格值BEGIN");
            long beginTime=System.currentTimeMillis();
            for (Integer r : cellMap.keySet()) {
                Row row = sheet.createRow(r);
                sheet.setForceFormulaRecalculation(true);
                //循环每一列
                for (JSONObject col : cellMap.get(r)) {
                    createCell(excel, sheet, row, col);
                }
            }
            long beginTime2=System.currentTimeMillis();
            System.out.println("设置单元格值END耗时:"+(beginTime2-beginTime));
            System.out.println("设置行列宽高BEGIN");
            if (rowlenObject != null) {
                for (String k : rowlenObject.keySet()) {
                    Integer _i = getStrToInt(k);
                    Integer _v = getStrToInt(rowlenObject.get(k).toString());
                    if (_i != null && _v != null) {
                        Row row = sheet.getRow(_i);
                        if (row != null) {
                            row.setHeightInPoints(_v.shortValue());
                        }
                    }
                }
            }
            if (columnlenObject != null) {
                for (String k : columnlenObject.keySet()) {
                    Integer _i = getStrToInt(k);
                    Integer _v = getStrToInt(columnlenObject.get(k).toString());
                    if (_i != null && _v != null) {
                        //sheet.setColumnWidth(_i,MSExcelUtil.heightUnits2Pixel(_v.shortValue()))
                        sheet.setColumnWidth(_i, _v.shortValue() * 42);
                    }
                }
            }
            if (colhiddenObject != null) {
                for (String k : colhiddenObject.keySet()) {
                    Integer _i = getStrToInt(k);
                    Integer _v = getStrToInt(colhiddenObject.get(k).toString());
                    if (_i != null && _v != null) {
                        sheet.setColumnHidden(_i,true);
                    }
                }
            }
            long beginTime3=System.currentTimeMillis();
            System.out.println("设置行列宽高END耗时:"+(beginTime3-beginTime2));
            System.out.println("设置边框BEGIN");
            //设置边框
            setBorder(borderInfoObjectList, excel, sheet);
            long beginTime4=System.currentTimeMillis();
            System.out.println("设置边框END"+(beginTime4-beginTime3));
        }
        // 判断路径是否存在
        File dir = new File(newFileDir);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        String paths = newFileDir + newFileName;
        OutputStream out = null;
        File f = new File(paths);
        if (!f.exists()) {
            System.out.println("有了");

        }
        try {
            out = new FileOutputStream(paths);

            excel.write(out);

            out.close();

        } catch (IOException e) {
            System.out.println("输出语句2");
        }
        System.out.println("输出语句0");
    }

    private static void setMergeAndColorByObject(JSONObject jsonObjectValue, XSSFSheet sheet, XSSFCellStyle style) {
        JSONObject mergeObject = (JSONObject) jsonObjectValue.get("mc");
        if (mergeObject != null) {
            int r = (int) (mergeObject.get("r"));
            int c = (int) (mergeObject.get("c"));
            if ((mergeObject.get("rs") != null && (mergeObject.get("cs") != null))) {
                int rs = (int) (mergeObject.get("rs"));
                int cs = (int) (mergeObject.get("cs"));
                CellRangeAddress region = new CellRangeAddress(r, r + rs - 1, (short) (c), (short) (c + cs - 1));
                sheet.addMergedRegion(region);
            }
        }

        if (jsonObjectValue.getString("bg") != null && jsonObjectValue.getString("bg").indexOf("rgb") != 0) {
            int bg = Integer.parseInt(jsonObjectValue.getString("bg").replace("#", ""), 16);
            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);    //设置填充方案
            style.setFillForegroundColor(new XSSFColor(new Color(bg)));  //设置填充颜色
        }

    }

    private static void setBorder(JSONArray borderInfoObjectList, XSSFWorkbook workbook, XSSFSheet sheet) {
        //设置边框样式map
        // System.out.println("边框配置:" + borderInfoObjectList + "边框配置数量:" + borderInfoObjectList.size());
        Map<Integer, BorderStyle> bordMap = new HashMap<>();
        bordMap.put(1, BorderStyle.THIN);
        bordMap.put(2, BorderStyle.HAIR);
        bordMap.put(3, BorderStyle.DOTTED);
        bordMap.put(4, BorderStyle.DASHED);
        bordMap.put(5, BorderStyle.DASH_DOT);
        bordMap.put(6, BorderStyle.DASH_DOT_DOT);
        bordMap.put(7, BorderStyle.DOUBLE);
        bordMap.put(8, BorderStyle.MEDIUM);
        bordMap.put(9, BorderStyle.MEDIUM_DASHED);
        bordMap.put(10, BorderStyle.MEDIUM_DASH_DOT);
        // bordMap.put(11, BorderStyle.MEDIUM_DASH_DOT_DOT);
        bordMap.put(12, BorderStyle.SLANTED_DASH_DOT);
        bordMap.put(13, BorderStyle.THICK);

        //一定要通过 cell.getCellStyle()  不然的话之前设置的样式会丢失
        //设置边框
        for (int i = 0; i < borderInfoObjectList.size(); i++) {
            try {
                JSONObject borderInfoObject = (JSONObject) borderInfoObjectList.get(i);
                JSONObject borderValueObject = borderInfoObject.getJSONObject("value");
                JSONObject l = borderValueObject.getJSONObject("l");
                JSONObject r = borderValueObject.getJSONObject("r");
                JSONObject t = borderValueObject.getJSONObject("t");
                JSONObject b = borderValueObject.getJSONObject("b");
                int row = borderValueObject.getInteger("row_index");
                int col = borderValueObject.getInteger("col_index");

                if (l != null && l.containsKey("color") && l.getString("color").contains("rgb")
                        || r != null && r.containsKey("color") && r.getString("color").contains("rgb")
                        || t != null && t.containsKey("color") && t.getString("color").contains("rgb")
                        || b != null && b.containsKey("color") && b.getString("color").contains("rgb")) {
                    continue;
                }
                XSSFCell cell = sheet.getRow(row).getCell(col);
                if (l != null) {
                    cell.getCellStyle().setBorderLeft(bordMap.get(l.get("style"))); //左边框
                    int bg = Integer.parseInt(l.getString("color").replace("#", ""), 16);
                    cell.getCellStyle().setLeftBorderColor(new XSSFColor(new Color(bg)));//左边框颜色
                } else {
                    cell.getCellStyle().setBorderLeft(BorderStyle.NONE);
                }
                if (r != null) {
                    cell.getCellStyle().setBorderRight(bordMap.get(r.get("style"))); //右边框
                    int bg = Integer.parseInt(r.getString("color").replace("#", ""), 16);
                    cell.getCellStyle().setRightBorderColor(new XSSFColor(new Color(bg)));//右边框颜色
                } else {
                    cell.getCellStyle().setBorderRight(BorderStyle.NONE);
                }
                if (t != null) {
                    cell.getCellStyle().setBorderTop(bordMap.get(t.get("style"))); //顶部边框
                    int bg = Integer.parseInt(t.getString("color").replace("#", ""), 16);
                    cell.getCellStyle().setTopBorderColor(new XSSFColor(new Color(bg)));//顶部边框颜色
                } else {
                    cell.getCellStyle().setBorderTop(BorderStyle.NONE);
                }
                if (b != null) {
                    cell.getCellStyle().setBorderBottom(bordMap.get(b.get("style"))); //顶部边框
                    int bg = Integer.parseInt(t.getString("color").replace("#", ""), 16);
                    cell.getCellStyle().setTopBorderColor(new XSSFColor(new Color(bg)));//顶部边框颜色
                } else {
                    cell.getCellStyle().setBorderBottom(BorderStyle.NONE);
                }
            } catch (Exception e) {

            }
        }
    }

    public static boolean isNumeric(String str) {
        // 正则表达式,匹配数字
        String regex = "\\d+(\\.\\d+)?";
        return str.matches(regex);
    }

    private static Integer getStrToInt(Object str) {
        try {
            if (str != null) {
                return Integer.parseInt(str.toString());
            }
            return null;
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            return null;
        }
    }

    public static Map<Integer, List<JSONObject>> cellGroup(List<JSONObject> cells) {
        Map<Integer, List<JSONObject>> cellMap = new HashMap<>(100);
        for (JSONObject dbObject : cells) {
            //行号
            if (dbObject.containsKey("r")) {
                Integer r = getStrToInt(dbObject.get("r"));
                if (r != null) {
                    if (cellMap.containsKey(r)) {
                        cellMap.get(r).add(dbObject);
                    } else {
                        List<JSONObject> list = new ArrayList<>(10);
                        list.add(dbObject);
                        cellMap.put(r, list);
                    }
                }
            }

        }
        return cellMap;
    }

    private static void createCell(XSSFWorkbook wb, XSSFSheet sheet, Row row, JSONObject dbObject) {
        if (dbObject.containsKey("c")) {
            Integer c = getStrToInt(dbObject.get("c"));
            if (c != null) {
                Cell cell = row.createCell(c);
                //取单元格中的v_json
                if (dbObject.containsKey("v")) {
                    //获取v对象
                    Object obj = dbObject.get("v");
                    if (obj == null) {
                        //没有内容
                        return;
                    }
                    //如果v对象直接是字符串
                    if (obj instanceof String) {
                        if (((String) obj).length() > 0) {
                            cell.setCellValue(obj.toString());
                        }
                        return;
                    }

                    //转换v为对象(v是一个对象)
                    JSONObject v_json = (JSONObject) obj;
                    //样式
                    XSSFCellStyle style = wb.createCellStyle();
                    cell.setCellStyle(style);
                    if (v_json.containsKey("mc")) {
                        //是合并的单元格
                        JSONObject mc = v_json.getJSONObject("mc");
                        if (mc.containsKey("rs") && mc.containsKey("cs")) {
                            //合并的第一个单元格
                            if (mc.containsKey("r") && mc.containsKey("c")) {
                                Integer _rs = getIntByDBObject(mc, "rs") - 1;
                                Integer _cs = getIntByDBObject(mc, "cs") - 1;
                                Integer _r = getIntByDBObject(mc, "r");
                                Integer _c = getIntByDBObject(mc, "c");

                                CellRangeAddress region = new CellRangeAddress(_r.shortValue(),
                                        (_r.shortValue() + _rs.shortValue()), _c.shortValue(),
                                        (_c.shortValue() + _cs.shortValue()));
                                sheet.addMergedRegion(region);
                            }
                        } else {
                            //不是合并的第一个单元格
                            return;
                        }
                    }


                    //取v值 (在数据类型中处理)
                    //ct 单元格值格式 (fa,t)
                    setFormatByCt(wb, cell, style, v_json);

                    //font设置
                    setCellStyleFont(wb, style, v_json,cell);

                    //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);
                                style.setFillForegroundColor(_color);
                                style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                            }
                        }

                    }

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

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

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

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

                    //f  公式
                    if (v_json.containsKey("f")) {
                        String _v = getByDBObject(v_json, "f");
                        // System.out.println("公式:"+_v);
                        if (_v.length() > 0) {
                            try {
                                if (_v.startsWith("=")) {
                                    //cell.setCellValue(_v);
                                    cell.setCellFormula(_v.substring(1));
                                } else {
                                    cell.setCellFormula(_v);
                                    //cell.setCellValue(_v);
                                }
                            } catch (Exception ex) {
                                System.out.println(ex.toString());
                            }
                        }
                    }

                }
            }
        }
    }
    public static Integer getIntByDBObject(JSONObject b, String k) {
        if (b.containsKey(k)) {
            if (b.get(k) != null) {
                try {
                    String _s = b.getString(k).replace("px", "");
                    Double _d = Double.parseDouble(_s);
                    return _d.intValue();
                } catch (Exception ex) {
                    System.out.println(ex.getMessage());
                    return null;
                }
            }
        }
        return null;
    }
    public static String getByDBObject(JSONObject b, String k) {
        if (b.containsKey(k)) {
            if (b.get(k) != null && b.get(k) instanceof String) {
                return b.getString(k);
            }
        }
        return null;
    }
    private static void setFormatByCt(Workbook wb, Cell cell, CellStyle style, JSONObject dbObject) {

        if (!dbObject.containsKey("v") && dbObject.containsKey("ct")) {
            JSONObject ct = dbObject.getJSONObject("ct");
            if (ct.containsKey("s")) {
                Object s = ct.get("s");
                if (s instanceof List && ((List) s).size() > 0) {
                    StringBuilder _v=new StringBuilder();
                    //解决一个单元格文本为不同类型字体
                    for(int i=0;i<((List<?>) s).size();i++){
                        JSONObject _s1 = (JSONObject) ((List) s).get(i);
                        if (_s1.containsKey("v") && _s1.get("v") instanceof String) {
                            _v.append(_s1.getString("v"));
                        }
                    }
                    dbObject.put("v", _v);
                    style.setWrapText(true);
                }
            }
            if (ct.containsKey("fa")) {
                String fa = ct.getString("fa");//单元格格式(包括小数位数)
                //System.out.println("单元格格式:"+fa+cell.getRowIndex()+"_"+cell.getColumnIndex());
                DataFormat format = wb.createDataFormat();
                style.setDataFormat(format.getFormat(fa));
            }
        }
        if (dbObject.containsKey("v")) {
            Object obj = getObjectByDBObject(dbObject, "v");
            if (obj instanceof Number) {
                cell.setCellValue(Double.valueOf(obj.toString()));
            } else if (obj instanceof Double) {
                cell.setCellValue((Double) obj);
            } else if (obj instanceof Date) {
                cell.setCellValue((Date) obj);
            } else if (obj instanceof Calendar) {
                cell.setCellValue((Calendar) obj);
            } else if (obj instanceof RichTextString) {
                cell.setCellValue((RichTextString) obj);
            } else if (obj instanceof String) {
                cell.setCellValue((String) obj);
            } else {
                cell.setCellValue(obj.toString());
            }

        }

        if (dbObject.containsKey("ct")) {
            JSONObject ct = dbObject.getJSONObject("ct");
            if (ct.containsKey("fa") && ct.containsKey("t")) {
                //t 0=bool,1=datetime,2=error,3=null,4=numeric,5=string,6=unknown
                String fa = getByDBObject(ct, "fa"); //单元格格式format定义串
                String t = getByDBObject(ct, "t"); //单元格格式type类型

                Integer _i = ConstantUtil.getNumberFormatMap(fa);
                switch (t) {
                    case "s": {
                        //字符串
                        if (_i >= 0) {
                            style.setDataFormat(_i.shortValue());
                        } else {
                            style.setDataFormat((short) 0);
                        }
                        //cell.setCellType(1);
                        //cell.setCellType(CellType.STRING);
                        break;
                    }
                    case "d": {
                        //日期
                        Date _d = null;
                        String v = getByDBObject(dbObject, "m");
                        if (v.length() == 0) {
                            v = getByDBObject(dbObject, "v");
                        }
                        if (v.length() > 0) {
                            if (v.indexOf("-") > -1) {
                                if (v.indexOf(":") > -1) {
                                    _d = ConstantUtil.stringToDateTime(v);
                                } else {
                                    _d = ConstantUtil.stringToDate(v);
                                }
                            } else {
                                _d = ConstantUtil.toDate(v);
                            }
                        }
                        if (_d != null) {
                            //能转换为日期
                            cell.setCellValue(_d);
                            DataFormat format = wb.createDataFormat();
                            style.setDataFormat(format.getFormat(fa));

                        } else {
                            //不能转换为日期
                            if (_i >= 0) {
                                style.setDataFormat(_i.shortValue());
                            } else {
                                style.setDataFormat((short) 0);
                            }
                        }
                        break;
                    }
                    case "b": {
                        //逻辑
                        //cell.setCellType(CellType.BOOLEAN);
                        if (_i >= 0) {
                            style.setDataFormat(_i.shortValue());
                        } else {
                            DataFormat format = wb.createDataFormat();
                            style.setDataFormat(format.getFormat(fa));
                        }
                        break;
                    }
                    case "n": {
                        //数值
                        //cell.setCellType(CellType.NUMERIC);
                        if (_i >= 0) {
                            style.setDataFormat(_i.shortValue());
                        } else {
                            DataFormat format = wb.createDataFormat();
                            style.setDataFormat(format.getFormat(fa));
                        }
                        break;
                    }
                    case "u":
                    case "g": {
                        //general 自动类型
                        //cell.setCellType(CellType._NONE);
                        if (_i >= 0) {
                            style.setDataFormat(_i.shortValue());
                        } else {
                            DataFormat format = wb.createDataFormat();
                            style.setDataFormat(format.getFormat(fa));
                        }
                        break;
                    }
                    case "e": {
                        //错误
                        //cell.setCellType(CellType.ERROR);
                        if (_i >= 0) {
                            style.setDataFormat(_i.shortValue());
                        } else {
                            DataFormat format = wb.createDataFormat();
                            style.setDataFormat(format.getFormat(fa));
                        }
                        break;
                    }

                }

            }

        }
    }
    public static Object getObjectByDBObject(JSONObject b, String k) {
        if (b.containsKey(k)) {
            if (b.get(k) != null) {
                return b.get(k);
            }
        }
        return "";
    }
    private static void setCellStyleFont(XSSFWorkbook wb, CellStyle style, JSONObject dbObject,Cell cell) {
        XSSFFont font = wb.createFont();
        //ff 字体
        if (dbObject.containsKey("ff")) {
            if (dbObject.get("ff") instanceof Integer) {
                Integer _v = getIntByDBObject(dbObject, "ff");
                if (_v != null && ConstantUtil.ff_IntegerToName.containsKey(_v)) {
                    font.setFontName(ConstantUtil.ff_IntegerToName.get(_v));
                }
            } else if (dbObject.get("ff") instanceof String) {
                font.setFontName(getByDBObject(dbObject, "ff"));
            }
        }
        //fc 字体颜色
        if (dbObject.containsKey("fc")) {
            String _v = getByDBObject(dbObject, "fc");
            if (_v != null) {
                Short _color = ColorUtil.getColorByStr(_v);
                if (_color != null) {
                    font.setColor(_color);
                }
            }
        }
        //bl 粗体
        if (dbObject.containsKey("bl")) {
            Integer _v = getIntByDBObject(dbObject, "bl");
            if (_v != null) {
                if (_v.equals(1)) {
                    //是否粗体显示
                    font.setBold(true);
                } else {
                    font.setBold(false);
                }
            }
        }
        //it 斜体
        if (dbObject.containsKey("it")) {
            Integer _v = getIntByDBObject(dbObject, "it");
            if (_v != null) {
                if (_v.equals(1)) {
                    font.setItalic(true);
                } else {
                    font.setItalic(false);
                }
            }
        }
        //fs 字体大小
        if (dbObject.containsKey("fs")) {
            Integer _v = getStrToInt(getObjectByDBObject(dbObject, "fs"));
            if (_v != null) {
                font.setFontHeightInPoints(_v.shortValue());
            }
        }
        //cl 删除线 (导入没有)   0 常规 、 1 删除线
        if (dbObject.containsKey("cl")) {
            Integer _v = getIntByDBObject(dbObject, "cl");
            if (_v != null) {
                if (_v.equals(1)) {
                    font.setStrikeout(true);
                }
            }
        }
        //ul 下划线
        if (dbObject.containsKey("ul")) {
            Integer _v = getIntByDBObject(dbObject, "ul");
            if (_v != null) {
                if (_v.equals(1)) {
                    font.setUnderline(Font.U_SINGLE);
                } else {
                    font.setUnderline(Font.U_NONE);
                }
            }
        }
        style.setFont(font);
        cell.setCellStyle(style);
    }
}
  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值