diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/HtmlToExcelServer.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/HtmlToExcelServer.java index f037c58..07bd15b 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/HtmlToExcelServer.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/HtmlToExcelServer.java @@ -32,8 +32,9 @@ import org.jeecgframework.poi.excel.html.css.impl.BorderCssConverImpl; import org.jeecgframework.poi.excel.html.css.impl.HeightCssConverImpl; import org.jeecgframework.poi.excel.html.css.impl.TextCssConvertImpl; import org.jeecgframework.poi.excel.html.css.impl.WidthCssConverImpl; -import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; +import org.jeecgframework.poi.excel.html.entity.ExcelCssConstant; import org.jeecgframework.poi.excel.html.entity.HtmlCssConstant; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleEntity; /** * 读取Table数据生成Excel @@ -130,7 +131,7 @@ public class HtmlToExcelServer { Map sheets = new HashMap(); Map maxrowMap = new HashMap(); for (Element table : els) { - String sheetName = table.attr("sheet"); + String sheetName = table.attr(ExcelCssConstant.SHEET_NAME); if (StringUtils.isBlank(sheetName)) { LOGGER.error("table必须存在name属性!"); diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/CssParseServer.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/CssParseServer.java index 3b0ebb8..f56a1df 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/CssParseServer.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/CssParseServer.java @@ -1,13 +1,19 @@ package org.jeecgframework.poi.excel.html.css; +import static org.jeecgframework.poi.excel.html.entity.HtmlCssConstant.*; + import java.util.HashMap; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; -import org.jeecgframework.poi.excel.html.entity.CellStyleBorderEntity; -import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; -import org.jeecgframework.poi.excel.html.entity.HtmlCssConstant; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleEntity; +import org.jeecgframework.poi.excel.html.entity.style.CssStyleFontEnity; import org.jeecgframework.poi.util.PoiCssUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * 把Css样式解析成对应的Model @@ -16,6 +22,8 @@ import org.jeecgframework.poi.util.PoiCssUtils; */ public class CssParseServer { + private static final Logger log = LoggerFactory.getLogger(CssParseServer.class); + public CellStyleEntity parseStyle(String style) { Map mapStyle = new HashMap(); for (String s : style.split("\\s*;\\s*")) { @@ -26,8 +34,7 @@ public class CssParseServer { String attrName = ss[0].toLowerCase(); String attrValue = ss[1]; // do not change font name - if (!HtmlCssConstant.FONT.equals(attrName) - && !HtmlCssConstant.FONT_FAMILY.equals(attrName)) { + if (!FONT.equals(attrName) && !FONT_FAMILY.equals(attrName)) { attrValue = attrValue.toLowerCase(); } mapStyle.put(attrName, attrValue); @@ -35,16 +42,124 @@ public class CssParseServer { } } + parseFontAttr(mapStyle); + return mapToCellStyleEntity(mapStyle); } + private void parseFontAttr(Map mapRtn) { + + log.debug("Parse Font Style."); + // color + String color = PoiCssUtils.processColor(mapRtn.get(COLOR)); + if (StringUtils.isNotBlank(color)) { + log.debug("Text Color [{}] Found.", color); + mapRtn.put(COLOR, color); + } + // font + String font = mapRtn.get(FONT); + if (StringUtils.isNotBlank(font) + && !ArrayUtils.contains(new String[] { "small-caps", "caption", "icon", "menu", + "message-box", "small-caption", "status-bar" }, + font)) { + log.debug("Parse Font Attr [{}].", font); + String[] ignoreStyles = new String[] { "normal", + // font weight normal + "[1-3]00" }; + StringBuffer sbFont = new StringBuffer( + font.replaceAll("^|\\s*" + StringUtils.join(ignoreStyles, "|") + "\\s+|$", " ")); + log.debug("Font Attr [{}] After Process Ingore.", sbFont); + // style + Matcher m = Pattern.compile("(?:^|\\s+)(italic|oblique)(?:\\s+|$)") + .matcher(sbFont.toString()); + if (m.find()) { + sbFont.setLength(0); + if (log.isDebugEnabled()) { + log.debug("Font Style [{}] Found.", m.group(1)); + } + mapRtn.put(FONT_STYLE, ITALIC); + m.appendReplacement(sbFont, " "); + m.appendTail(sbFont); + } + // weight + m = Pattern.compile("(?:^|\\s+)(bold(?:er)?|[7-9]00)(?:\\s+|$)") + .matcher(sbFont.toString()); + if (m.find()) { + sbFont.setLength(0); + if (log.isDebugEnabled()) { + log.debug("Font Weight [{}](bold) Found.", m.group(1)); + } + mapRtn.put(FONT_WEIGHT, BOLD); + m.appendReplacement(sbFont, " "); + m.appendTail(sbFont); + } + // size xx-small | x-small | small | medium | large | x-large | xx-large | 18px [/2] + m = Pattern.compile( + // before blank or start + new StringBuilder("(?:^|\\s+)") + // font size + .append("(xx-small|x-small|small|medium|large|x-large|xx-large|").append("(?:") + .append(PATTERN_LENGTH).append("))") + // line height + .append("(?:\\s*\\/\\s*(").append(PATTERN_LENGTH).append("))?") + // after blank or end + .append("(?:\\s+|$)").toString()) + .matcher(sbFont.toString()); + if (m.find()) { + sbFont.setLength(0); + log.debug("Font Size[/line-height] [{}] Found.", m.group()); + String fontSize = m.group(1); + if (StringUtils.isNotBlank(fontSize)) { + fontSize = StringUtils.deleteWhitespace(fontSize); + log.debug("Font Size [{}].", fontSize); + if (fontSize.matches(PATTERN_LENGTH)) { + mapRtn.put(FONT_SIZE, fontSize); + } else { + log.info("Font Size [{}] Not Supported, Ignore.", fontSize); + } + } + String lineHeight = m.group(2); + if (StringUtils.isNotBlank(lineHeight)) { + log.info("Line Height [{}] Not Supported, Ignore.", lineHeight); + } + m.appendReplacement(sbFont, " "); + m.appendTail(sbFont); + } + // font family + if (sbFont.length() > 0) { + log.debug("Font Families [{}].", sbFont); + // trim & remove '" + String fontFamily = sbFont.toString().split("\\s*,\\s*")[0].trim() + .replaceAll("'|\"", ""); + log.debug("Use First Font Family [{}].", fontFamily); + mapRtn.put(FONT_FAMILY, fontFamily); + } + } + font = mapRtn.get(FONT_STYLE); + if (ArrayUtils.contains(new String[] { ITALIC, "oblique" }, font)) { + log.debug("Font Italic [{}] Found.", font); + mapRtn.put(FONT_STYLE, ITALIC); + } + font = mapRtn.get(FONT_WEIGHT); + if (StringUtils.isNotBlank(font) && Pattern.matches("^bold(?:er)?|[7-9]00$", font)) { + log.debug("Font Weight [{}](bold) Found.", font); + mapRtn.put(FONT_WEIGHT, BOLD); + } + font = mapRtn.get(FONT_SIZE); + if (!PoiCssUtils.isNum(font)) { + log.debug("Font Size [{}] Error.", font); + mapRtn.remove(FONT_SIZE); + } + } + private CellStyleEntity mapToCellStyleEntity(Map mapStyle) { CellStyleEntity entity = new CellStyleEntity(); - entity.setAlign(mapStyle.get(HtmlCssConstant.TEXT_ALIGN)); - entity.setVetical(mapStyle.get(HtmlCssConstant.VETICAL_ALIGN)); + entity.setAlign(mapStyle.get(TEXT_ALIGN)); + entity.setVetical(mapStyle.get(VETICAL_ALIGN)); entity.setBackground(getBackground(mapStyle)); - entity.setHeight(mapStyle.get(HtmlCssConstant.HEIGHT)); - entity.setWidth(mapStyle.get(HtmlCssConstant.WIDTH)); + entity.setHeight(mapStyle.get(HEIGHT)); + entity.setWidth(mapStyle.get(WIDTH)); + entity.setFont(getCssStyleFontEnity(mapStyle)); // TODO 这里较为复杂,后期处理 /*CellStyleBorderEntity border = new CellStyleBorderEntity(); entity.setBorder(border); @@ -52,27 +167,41 @@ public class CssParseServer { return entity; } + private CssStyleFontEnity getCssStyleFontEnity(Map style) { + CssStyleFontEnity font = new CssStyleFontEnity(); + font.setStyle(style.get(FONT_STYLE)); + int fontSize = PoiCssUtils.getInt(style.get(FONT_SIZE)); + if (fontSize > 0) { + font.setSize(fontSize); + } + font.setWeight(style.get(FONT_WEIGHT)); + font.setFamily(style.get(FONT_FAMILY)); + font.setDecoration(style.get(TEXT_DECORATION)); + font.setColor(PoiCssUtils.parseColor(style.get(COLOR))); + return font; + } + private String getBackground(Map style) { Map mapRtn = new HashMap(); - String bg = style.get(HtmlCssConstant.BACKGROUND); + String bg = style.get(BACKGROUND); String bgColor = null; if (StringUtils.isNotBlank(bg)) { for (String bgAttr : bg.split("(?<=\\)|\\w|%)\\s+(?=\\w)")) { if ((bgColor = PoiCssUtils.processColor(bgAttr)) != null) { - mapRtn.put(HtmlCssConstant.BACKGROUND_COLOR, bgColor); + mapRtn.put(BACKGROUND_COLOR, bgColor); break; } } } - bg = style.get(HtmlCssConstant.BACKGROUND_COLOR); + bg = style.get(BACKGROUND_COLOR); if (StringUtils.isNotBlank(bg) && (bgColor = PoiCssUtils.processColor(bg)) != null) { - mapRtn.put(HtmlCssConstant.BACKGROUND_COLOR, bgColor); + mapRtn.put(BACKGROUND_COLOR, bgColor); } if (bgColor != null) { - bgColor = mapRtn.get(HtmlCssConstant.BACKGROUND_COLOR); + bgColor = mapRtn.get(BACKGROUND_COLOR); if (!"#ffffff".equals(bgColor)) { - return mapRtn.get(HtmlCssConstant.BACKGROUND_COLOR); + return mapRtn.get(BACKGROUND_COLOR); } } return null; diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/ICssConvertToExcel.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/ICssConvertToExcel.java index c231ee8..03b783e 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/ICssConvertToExcel.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/ICssConvertToExcel.java @@ -17,7 +17,7 @@ package org.jeecgframework.poi.excel.html.css; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; -import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleEntity; /** * CSS Cell Style 转换类 diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/ICssConvertToHtml.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/ICssConvertToHtml.java index 1176f75..20c103b 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/ICssConvertToHtml.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/ICssConvertToHtml.java @@ -17,7 +17,7 @@ package org.jeecgframework.poi.excel.html.css; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; -import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleEntity; /** * CSS Cell Style 转换类 diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/AlignCssConvertImpl.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/AlignCssConvertImpl.java index 8d6cc73..35adf5c 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/AlignCssConvertImpl.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/AlignCssConvertImpl.java @@ -4,20 +4,39 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.jeecgframework.poi.excel.html.css.ICssConvertToExcel; import org.jeecgframework.poi.excel.html.css.ICssConvertToHtml; -import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; +import org.jeecgframework.poi.excel.html.entity.HtmlCssConstant; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleEntity; public class AlignCssConvertImpl implements ICssConvertToExcel, ICssConvertToHtml { @Override public String convertToHtml(Cell cell, CellStyle cellStyle, CellStyleEntity style) { - + return null; } @Override public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { + // align + if (HtmlCssConstant.RIGHT.equals(style.getAlign())) { + cellStyle.setAlignment(CellStyle.ALIGN_RIGHT); + } else if (HtmlCssConstant.CENTER.equals(style.getAlign())) { + cellStyle.setAlignment(CellStyle.ALIGN_CENTER); + } else if (HtmlCssConstant.LEFT.equals(style.getAlign())) { + cellStyle.setAlignment(CellStyle.ALIGN_LEFT); + } else if (HtmlCssConstant.JUSTIFY.equals(style.getAlign())) { + cellStyle.setAlignment(CellStyle.ALIGN_JUSTIFY); + } + // vertical align + if (HtmlCssConstant.TOP.equals(style.getVetical())) { + cellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); + } else if (HtmlCssConstant.CENTER.equals(style.getAlign())) { + cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); + } else if (HtmlCssConstant.BOTTOM.equals(style.getAlign())) { + cellStyle.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); + } else if (HtmlCssConstant.JUSTIFY.equals(style.getAlign())) { + cellStyle.setVerticalAlignment(CellStyle.VERTICAL_JUSTIFY); + } } - - } diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/BackgroundCssConvertImpl.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/BackgroundCssConvertImpl.java index ca35eca..4482f51 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/BackgroundCssConvertImpl.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/BackgroundCssConvertImpl.java @@ -4,7 +4,7 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.jeecgframework.poi.excel.html.css.ICssConvertToExcel; import org.jeecgframework.poi.excel.html.css.ICssConvertToHtml; -import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleEntity; public class BackgroundCssConvertImpl implements ICssConvertToExcel, ICssConvertToHtml { diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/BorderCssConverImpl.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/BorderCssConverImpl.java index 5ea6d46..8bf1759 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/BorderCssConverImpl.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/BorderCssConverImpl.java @@ -19,8 +19,8 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.jeecgframework.poi.excel.html.css.ICssConvertToExcel; import org.jeecgframework.poi.excel.html.css.ICssConvertToHtml; -import org.jeecgframework.poi.excel.html.entity.CellStyleBorderEntity; -import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleBorderEntity; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleEntity; /** * 边框转换实现类 diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/HeightCssConverImpl.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/HeightCssConverImpl.java index d905943..417ff90 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/HeightCssConverImpl.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/HeightCssConverImpl.java @@ -21,7 +21,7 @@ import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Row; import org.jeecgframework.poi.excel.html.css.ICssConvertToExcel; import org.jeecgframework.poi.excel.html.css.ICssConvertToHtml; -import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleEntity; import org.jeecgframework.poi.util.PoiCssUtils; diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/TextCssConvertImpl.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/TextCssConvertImpl.java index b3bdbd1..485a321 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/TextCssConvertImpl.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/TextCssConvertImpl.java @@ -1,23 +1,55 @@ package org.jeecgframework.poi.excel.html.css.impl; +import static org.jeecgframework.poi.excel.html.entity.HtmlCssConstant.*; + +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFFont; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.hssf.util.HSSFColor.BLACK; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Font; import org.jeecgframework.poi.excel.html.css.ICssConvertToExcel; import org.jeecgframework.poi.excel.html.css.ICssConvertToHtml; -import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleEntity; public class TextCssConvertImpl implements ICssConvertToExcel, ICssConvertToHtml { @Override public String convertToHtml(Cell cell, CellStyle cellStyle, CellStyleEntity style) { - + return null; } @Override public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { + if (style == null || style.getFont() == null) { + return; + } + Font font = cell.getSheet().getWorkbook().createFont(); + if (ITALIC.equals(style.getFont().getStyle())) { + font.setItalic(true); + } + int fontSize = style.getFont().getSize(); + if (fontSize > 0) { + font.setFontHeightInPoints((short) fontSize); + } + if (BOLD.equals(style.getFont().getWeight())) { + font.setBoldweight(Font.BOLDWEIGHT_BOLD); + } + String fontFamily = style.getFont().getFamily(); + if (StringUtils.isNotBlank(fontFamily)) { + font.setFontName(fontFamily); + } + int color = style.getFont().getColor(); + if (color != 0 && color != BLACK.index) { + font.setColor((short) color); + } + if (UNDERLINE.equals(style.getFont().getDecoration())) { + font.setUnderline(Font.U_SINGLE); + } + cellStyle.setFont(font); } - - } diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/WidthCssConverImpl.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/WidthCssConverImpl.java index 1347a8b..da05362 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/WidthCssConverImpl.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/WidthCssConverImpl.java @@ -21,7 +21,7 @@ import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Sheet; import org.jeecgframework.poi.excel.html.css.ICssConvertToExcel; import org.jeecgframework.poi.excel.html.css.ICssConvertToHtml; -import org.jeecgframework.poi.excel.html.entity.CellStyleEntity; +import org.jeecgframework.poi.excel.html.entity.style.CellStyleEntity; import org.jeecgframework.poi.util.PoiCssUtils; /** diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/ExcelCssConstant.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/ExcelCssConstant.java new file mode 100644 index 0000000..bc72854 --- /dev/null +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/ExcelCssConstant.java @@ -0,0 +1,27 @@ +/** + * Copyright 2013-2017 JueYue (qrb.jueyue@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jeecgframework.poi.excel.html.entity; + +/** + * Excel 自定义处理的自定义Html标签 + * @author JueYue + * 2017年3月26日 + */ +public interface ExcelCssConstant { + + public final String SHEET_NAME = "sheetName"; + +} diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/HtmlCssConstant.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/HtmlCssConstant.java index ab2c00f..6ee13f2 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/HtmlCssConstant.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/HtmlCssConstant.java @@ -1,5 +1,5 @@ /** - * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) + * Copyright 2013-2017 JueYue (qrb.jueyue@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,8 @@ public interface HtmlCssConstant { public final String FONT_WEIGHT = "font-weight"; public final String FONT_SIZE = "font-size"; public final String FONT_FAMILY = "font-family"; + public final String TEXT_DECORATION = "text-decoration"; + public final String UNDERLINE = "underline"; public final String ITALIC = "italic"; public final String BOLD = "bold"; public final String NORMAL = "normal"; diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/CellStyleBorderEntity.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CellStyleBorderEntity.java similarity index 92% rename from easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/CellStyleBorderEntity.java rename to easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CellStyleBorderEntity.java index 4e13a04..56813ba 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/CellStyleBorderEntity.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CellStyleBorderEntity.java @@ -13,9 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jeecgframework.poi.excel.html.entity; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +package org.jeecgframework.poi.excel.html.entity.style; /** * 边框样式 diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/CellStyleEntity.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CellStyleEntity.java similarity index 82% rename from easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/CellStyleEntity.java rename to easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CellStyleEntity.java index 8b9ed79..e0d68b9 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/CellStyleEntity.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CellStyleEntity.java @@ -13,9 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jeecgframework.poi.excel.html.entity; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +package org.jeecgframework.poi.excel.html.entity.style; /** * Cell 具有的样式 @@ -47,6 +45,10 @@ public class CellStyleEntity { * 垂直位置 */ private String vetical; + /** + * 字体设置 + */ + private CssStyleFontEnity font; public String getWidth() { return width; @@ -96,10 +98,18 @@ public class CellStyleEntity { this.vetical = vetical; } + public CssStyleFontEnity getFont() { + return font; + } + + public void setFont(CssStyleFontEnity font) { + this.font = font; + } + @Override public String toString() { return new StringBuilder().append(align).append(background).append(border).append(height) - .append(vetical).append(width).toString(); + .append(vetical).append(width).append(font).toString(); } } diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CssStyleFontEnity.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CssStyleFontEnity.java new file mode 100644 index 0000000..51724ad --- /dev/null +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CssStyleFontEnity.java @@ -0,0 +1,93 @@ +/** + * Copyright 2013-2017 JueYue (qrb.jueyue@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jeecgframework.poi.excel.html.entity.style; + +/** + * 字体样式 + * @author JueYue + * 2017年3月26日 + */ +public class CssStyleFontEnity { + /** + * italic 浏览器会显示一个斜体的字体样式。 + */ + private String style; + /** + * bold 定义粗体字符 + */ + private String weight; + /** + * 仅支持**px获取不带px的数字大小 + */ + private int size; + private String family; + private String decoration; + private int color; + + public String getStyle() { + return style; + } + + public void setStyle(String style) { + this.style = style; + } + + public String getWeight() { + return weight; + } + + public void setWeight(String weight) { + this.weight = weight; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public String getFamily() { + return family; + } + + public void setFamily(String family) { + this.family = family; + } + + public int getColor() { + return color; + } + + public void setColor(int color) { + this.color = color; + } + + public String getDecoration() { + return decoration; + } + + public void setDecoration(String decoration) { + this.decoration = decoration; + } + + @Override + public String toString() { + return new StringBuilder().append(style).append(decoration).append(color).append(family) + .append(size).append(weight).toString(); + } +} diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiCssUtils.java b/easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiCssUtils.java index b660527..c5f8f04 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiCssUtils.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiCssUtils.java @@ -132,26 +132,17 @@ public class PoiCssUtils { /** * parse color - * @param workBook work book * @param color string color - * @return HSSFColor + * @return int */ - public static HSSFColor parseColor(HSSFWorkbook workBook, String color) { - HSSFColor poiColor = null; + public static int parseColor(String color) { if (StringUtils.isNotBlank(color)) { Color awtColor = Color.decode(color); if (awtColor != null) { - int r = awtColor.getRed(); - int g = awtColor.getGreen(); - int b = awtColor.getBlue(); - HSSFPalette palette = workBook.getCustomPalette(); - poiColor = palette.findColor((byte) r, (byte) g, (byte) b); - if (poiColor == null) { - poiColor = palette.findSimilarColor(r, g, b); - } + return awtColor.getRGB(); } } - return poiColor; + return 0; } // --