Преглед изворни кода

完成了align和text解析的 一部分

4.1.3.A
jueyue пре 8 година
родитељ
комит
559ff7c7c7
16 измењених фајлова са 355 додато и 53 уклоњено
  1. +3
    -2
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/HtmlToExcelServer.java
  2. +144
    -15
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/CssParseServer.java
  3. +1
    -1
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/ICssConvertToExcel.java
  4. +1
    -1
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/ICssConvertToHtml.java
  5. +23
    -4
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/AlignCssConvertImpl.java
  6. +1
    -1
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/BackgroundCssConvertImpl.java
  7. +2
    -2
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/BorderCssConverImpl.java
  8. +1
    -1
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/HeightCssConverImpl.java
  9. +36
    -4
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/TextCssConvertImpl.java
  10. +1
    -1
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/css/impl/WidthCssConverImpl.java
  11. +27
    -0
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/ExcelCssConstant.java
  12. +3
    -1
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/HtmlCssConstant.java
  13. +1
    -3
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CellStyleBorderEntity.java
  14. +14
    -4
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CellStyleEntity.java
  15. +93
    -0
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/style/CssStyleFontEnity.java
  16. +4
    -13
      easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiCssUtils.java

+ 3
- 2
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<String, Sheet> sheets = new HashMap<String, Sheet>();
Map<String, Integer> maxrowMap = new HashMap<String, Integer>();
for (Element table : els) {
String sheetName = table.attr("sheet");
String sheetName = table.attr(ExcelCssConstant.SHEET_NAME);
if (StringUtils.isBlank(sheetName)) {
LOGGER.error("table必须存在name属性!");


+ 144
- 15
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<String, String> mapStyle = new HashMap<String, String>();
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<String, String> 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<String, String> 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<String, String> 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<String, String> style) {
Map<String, String> mapRtn = new HashMap<String, String>();
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;


+ 1
- 1
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 转换类


+ 1
- 1
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 转换类


+ 23
- 4
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);
}
}
}

+ 1
- 1
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 {


+ 2
- 2
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;
/**
* 边框转换实现类


+ 1
- 1
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;


+ 36
- 4
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);
}
}

+ 1
- 1
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;
/**


+ 27
- 0
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";
}

+ 3
- 1
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";


easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/CellStyleBorderEntity.java → 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;
/**
* 边框样式

easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/entity/CellStyleEntity.java → 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();
}
}

+ 93
- 0
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();
}
}

+ 4
- 13
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;
}

// --


Loading…
Откажи
Сачувај