@@ -4,7 +4,7 @@ | |||||
<parent> | <parent> | ||||
<groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
<artifactId>easypoi</artifactId> | <artifactId>easypoi</artifactId> | ||||
<version>3.3.0</version> | |||||
<version>4.0.0-SNAPSHOT</version> | |||||
</parent> | </parent> | ||||
<artifactId>easypoi-annotation</artifactId> | <artifactId>easypoi-annotation</artifactId> | ||||
<description>基础注解类,解耦合</description> | <description>基础注解类,解耦合</description> |
@@ -4,7 +4,7 @@ | |||||
<parent> | <parent> | ||||
<groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
<artifactId>easypoi</artifactId> | <artifactId>easypoi</artifactId> | ||||
<version>3.3.0</version> | |||||
<version>4.0.0-SNAPSHOT</version> | |||||
</parent> | </parent> | ||||
<artifactId>easypoi-base</artifactId> | <artifactId>easypoi-base</artifactId> | ||||
<dependencies> | <dependencies> | ||||
@@ -19,7 +19,6 @@ import java.io.InputStream; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; | |||||
import org.apache.poi.ss.usermodel.Workbook; | import org.apache.poi.ss.usermodel.Workbook; | ||||
import org.apache.poi.ss.usermodel.WorkbookFactory; | import org.apache.poi.ss.usermodel.WorkbookFactory; | ||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
@@ -53,8 +52,6 @@ public final class ExcelCache { | |||||
} | } | ||||
} | } | ||||
return wb; | return wb; | ||||
} catch (InvalidFormatException e) { | |||||
LOGGER.error(e.getMessage(), e); | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
LOGGER.error(e.getMessage(), e); | LOGGER.error(e.getMessage(), e); | ||||
} finally { | } finally { | ||||
@@ -70,11 +70,11 @@ public class ExportParams extends ExcelBaseParams { | |||||
/** | /** | ||||
* 表头颜色 | * 表头颜色 | ||||
*/ | */ | ||||
private short color = HSSFColor.WHITE.index; | |||||
private short color = HSSFColor.HSSFColorPredefined.WHITE.getIndex(); | |||||
/** | /** | ||||
* 属性说明行的颜色 例如:HSSFColor.SKY_BLUE.index 默认 | * 属性说明行的颜色 例如:HSSFColor.SKY_BLUE.index 默认 | ||||
*/ | */ | ||||
private short headerColor = HSSFColor.SKY_BLUE.index; | |||||
private short headerColor = HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex(); | |||||
/** | /** | ||||
* Excel 导出版本 | * Excel 导出版本 | ||||
*/ | */ | ||||
@@ -24,11 +24,7 @@ import java.util.List; | |||||
import cn.afterturn.easypoi.util.PoiMergeCellUtil; | import cn.afterturn.easypoi.util.PoiMergeCellUtil; | ||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Drawing; | |||||
import org.apache.poi.ss.usermodel.Row; | |||||
import org.apache.poi.ss.usermodel.Sheet; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
import org.apache.poi.ss.usermodel.*; | |||||
import org.apache.poi.ss.util.CellRangeAddress; | import org.apache.poi.ss.util.CellRangeAddress; | ||||
import cn.afterturn.easypoi.excel.annotation.ExcelTarget; | import cn.afterturn.easypoi.excel.annotation.ExcelTarget; | ||||
@@ -146,7 +142,7 @@ public class ExcelExportService extends BaseExportService { | |||||
row = sheet.createRow(1); | row = sheet.createRow(1); | ||||
row.setHeight(entity.getSecondTitleHeight()); | row.setHeight(entity.getSecondTitleHeight()); | ||||
CellStyle style = workbook.createCellStyle(); | CellStyle style = workbook.createCellStyle(); | ||||
style.setAlignment(CellStyle.ALIGN_RIGHT); | |||||
style.setAlignment(HorizontalAlignment.RIGHT); | |||||
createStringCell(row, 0, entity.getSecondTitle(), style, null); | createStringCell(row, 0, entity.getSecondTitle(), style, null); | ||||
for (int i = 1; i <= fieldWidth; i++) { | for (int i = 1; i <= fieldWidth; i++) { | ||||
createStringCell(row, i, "", | createStringCell(row, i, "", | ||||
@@ -17,14 +17,7 @@ import org.apache.commons.lang3.StringUtils; | |||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder; | import org.apache.commons.lang3.builder.ReflectionToStringBuilder; | ||||
import org.apache.poi.hssf.usermodel.HSSFClientAnchor; | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; | ||||
import org.apache.poi.hssf.usermodel.HSSFRichTextString; | import org.apache.poi.hssf.usermodel.HSSFRichTextString; | ||||
import org.apache.poi.ss.usermodel.Cell; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.ClientAnchor; | |||||
import org.apache.poi.ss.usermodel.Drawing; | |||||
import org.apache.poi.ss.usermodel.RichTextString; | |||||
import org.apache.poi.ss.usermodel.Row; | |||||
import org.apache.poi.ss.usermodel.Sheet; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
import org.apache.poi.ss.usermodel.*; | |||||
import org.apache.poi.ss.util.CellRangeAddress; | import org.apache.poi.ss.util.CellRangeAddress; | ||||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor; | import org.apache.poi.xssf.usermodel.XSSFClientAnchor; | ||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString; | import org.apache.poi.xssf.usermodel.XSSFRichTextString; | ||||
@@ -265,7 +258,7 @@ public abstract class BaseExportService extends ExportCommonService { | |||||
Cell cell = row.createCell(index); | Cell cell = row.createCell(index); | ||||
if (style != null && style.getDataFormat() > 0 && style.getDataFormat() < 12) { | if (style != null && style.getDataFormat() > 0 && style.getDataFormat() < 12) { | ||||
cell.setCellValue(Double.parseDouble(text)); | cell.setCellValue(Double.parseDouble(text)); | ||||
cell.setCellType(Cell.CELL_TYPE_NUMERIC); | |||||
cell.setCellType(CellType.NUMERIC); | |||||
} else { | } else { | ||||
RichTextString rtext; | RichTextString rtext; | ||||
if (type.equals(ExcelType.HSSF)) { | if (type.equals(ExcelType.HSSF)) { | ||||
@@ -290,7 +283,7 @@ public abstract class BaseExportService extends ExportCommonService { | |||||
if (text != null && text.length() > 0) { | if (text != null && text.length() > 0) { | ||||
cell.setCellValue(Double.parseDouble(text)); | cell.setCellValue(Double.parseDouble(text)); | ||||
} | } | ||||
cell.setCellType(Cell.CELL_TYPE_NUMERIC); | |||||
cell.setCellType(CellType.NUMERIC); | |||||
if (style != null) { | if (style != null) { | ||||
cell.setCellStyle(style); | cell.setCellStyle(style); | ||||
} | } | ||||
@@ -1,13 +1,13 @@ | |||||
/** | /** | ||||
* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | * Copyright 2013-2015 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 | |||||
* <p> | |||||
* 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 | |||||
* <p> | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* <p> | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
@@ -15,17 +15,16 @@ | |||||
*/ | */ | ||||
package cn.afterturn.easypoi.excel.export.styler; | package cn.afterturn.easypoi.excel.export.styler; | ||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Font; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
import org.apache.poi.ss.usermodel.*; | |||||
/** | /** | ||||
* 带有边框的Excel样式 | * 带有边框的Excel样式 | ||||
* | |||||
* @author JueYue | * @author JueYue | ||||
* 2015年1月9日 下午5:55:29 | |||||
* 2015年1月9日 下午5:55:29 | |||||
*/ | */ | ||||
public class ExcelExportStylerBorderImpl extends AbstractExcelExportStyler | public class ExcelExportStylerBorderImpl extends AbstractExcelExportStyler | ||||
implements IExcelExportStyler { | |||||
implements IExcelExportStyler { | |||||
public ExcelExportStylerBorderImpl(Workbook workbook) { | public ExcelExportStylerBorderImpl(Workbook workbook) { | ||||
super.createStyles(workbook); | super.createStyles(workbook); | ||||
@@ -37,24 +36,24 @@ public class ExcelExportStylerBorderImpl extends AbstractExcelExportStyler | |||||
Font font = workbook.createFont(); | Font font = workbook.createFont(); | ||||
font.setFontHeightInPoints((short) 12); | font.setFontHeightInPoints((short) 12); | ||||
titleStyle.setFont(font); | titleStyle.setFont(font); | ||||
titleStyle.setBorderLeft((short) 1); // 左边框 | |||||
titleStyle.setBorderRight((short) 1); // 右边框 | |||||
titleStyle.setBorderBottom((short) 1); | |||||
titleStyle.setBorderTop((short) 1); | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
titleStyle.setBorderLeft(BorderStyle.THIN); | |||||
titleStyle.setBorderRight(BorderStyle.THIN); | |||||
titleStyle.setBorderBottom(BorderStyle.THIN); | |||||
titleStyle.setBorderTop(BorderStyle.THIN); | |||||
titleStyle.setAlignment(HorizontalAlignment.CENTER); | |||||
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
return titleStyle; | return titleStyle; | ||||
} | } | ||||
@Override | @Override | ||||
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { | ||||
CellStyle style = workbook.createCellStyle(); | CellStyle style = workbook.createCellStyle(); | ||||
style.setBorderLeft((short) 1); // 左边框 | |||||
style.setBorderRight((short) 1); // 右边框 | |||||
style.setBorderBottom((short) 1); | |||||
style.setBorderTop((short) 1); | |||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setBorderLeft(BorderStyle.THIN); | |||||
style.setBorderRight(BorderStyle.THIN); | |||||
style.setBorderBottom(BorderStyle.THIN); | |||||
style.setBorderTop(BorderStyle.THIN); | |||||
style.setAlignment(HorizontalAlignment.CENTER); | |||||
style.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
style.setDataFormat(STRING_FORMAT); | style.setDataFormat(STRING_FORMAT); | ||||
if (isWarp) { | if (isWarp) { | ||||
style.setWrapText(true); | style.setWrapText(true); | ||||
@@ -65,12 +64,12 @@ public class ExcelExportStylerBorderImpl extends AbstractExcelExportStyler | |||||
@Override | @Override | ||||
public CellStyle getTitleStyle(short color) { | public CellStyle getTitleStyle(short color) { | ||||
CellStyle titleStyle = workbook.createCellStyle(); | CellStyle titleStyle = workbook.createCellStyle(); | ||||
titleStyle.setBorderLeft((short) 1); // 左边框 | |||||
titleStyle.setBorderRight((short) 1); // 右边框 | |||||
titleStyle.setBorderBottom((short) 1); | |||||
titleStyle.setBorderTop((short) 1); | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
titleStyle.setBorderLeft(BorderStyle.THIN); | |||||
titleStyle.setBorderRight(BorderStyle.THIN); | |||||
titleStyle.setBorderBottom(BorderStyle.THIN); | |||||
titleStyle.setBorderTop(BorderStyle.THIN); | |||||
titleStyle.setAlignment(HorizontalAlignment.CENTER); | |||||
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
titleStyle.setWrapText(true); | titleStyle.setWrapText(true); | ||||
return titleStyle; | return titleStyle; | ||||
} | } | ||||
@@ -15,9 +15,7 @@ | |||||
*/ | */ | ||||
package cn.afterturn.easypoi.excel.export.styler; | package cn.afterturn.easypoi.excel.export.styler; | ||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Font; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
import org.apache.poi.ss.usermodel.*; | |||||
/** | /** | ||||
* 带有样式的导出服务 | * 带有样式的导出服务 | ||||
@@ -38,20 +36,20 @@ public class ExcelExportStylerColorImpl extends AbstractExcelExportStyler | |||||
font.setFontHeightInPoints((short) 24); | font.setFontHeightInPoints((short) 24); | ||||
titleStyle.setFont(font); | titleStyle.setFont(font); | ||||
titleStyle.setFillForegroundColor(headerColor); | titleStyle.setFillForegroundColor(headerColor); | ||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
titleStyle.setAlignment(HorizontalAlignment.CENTER); | |||||
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
return titleStyle; | return titleStyle; | ||||
} | } | ||||
@Override | @Override | ||||
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { | ||||
CellStyle style = workbook.createCellStyle(); | CellStyle style = workbook.createCellStyle(); | ||||
style.setBorderLeft((short) 1); // 左边框 | |||||
style.setBorderRight((short) 1); // 右边框 | |||||
style.setBorderBottom((short) 1); | |||||
style.setBorderTop((short) 1); | |||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setBorderLeft(BorderStyle.THIN); | |||||
style.setBorderRight(BorderStyle.THIN); | |||||
style.setBorderBottom(BorderStyle.THIN); | |||||
style.setBorderTop(BorderStyle.THIN); | |||||
style.setAlignment(HorizontalAlignment.CENTER); | |||||
style.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
style.setDataFormat(STRING_FORMAT); | style.setDataFormat(STRING_FORMAT); | ||||
if (isWarp) { | if (isWarp) { | ||||
style.setWrapText(true); | style.setWrapText(true); | ||||
@@ -62,10 +60,10 @@ public class ExcelExportStylerColorImpl extends AbstractExcelExportStyler | |||||
@Override | @Override | ||||
public CellStyle getTitleStyle(short color) { | public CellStyle getTitleStyle(short color) { | ||||
CellStyle titleStyle = workbook.createCellStyle(); | CellStyle titleStyle = workbook.createCellStyle(); | ||||
titleStyle.setFillForegroundColor(color); // 填充的背景颜色 | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
titleStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); // 填充图案 | |||||
titleStyle.setFillForegroundColor(color); | |||||
titleStyle.setAlignment(HorizontalAlignment.CENTER); | |||||
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | |||||
titleStyle.setWrapText(true); | titleStyle.setWrapText(true); | ||||
return titleStyle; | return titleStyle; | ||||
} | } | ||||
@@ -73,14 +71,14 @@ public class ExcelExportStylerColorImpl extends AbstractExcelExportStyler | |||||
@Override | @Override | ||||
public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { | public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { | ||||
CellStyle style = workbook.createCellStyle(); | CellStyle style = workbook.createCellStyle(); | ||||
style.setBorderLeft((short) 1); // 左边框 | |||||
style.setBorderRight((short) 1); // 右边框 | |||||
style.setBorderBottom((short) 1); | |||||
style.setBorderTop((short) 1); | |||||
style.setFillForegroundColor((short) 41); // 填充的背景颜色 | |||||
style.setFillPattern(CellStyle.SOLID_FOREGROUND); // 填充图案 | |||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setBorderLeft(BorderStyle.THIN); | |||||
style.setBorderRight(BorderStyle.THIN); | |||||
style.setBorderBottom(BorderStyle.THIN); | |||||
style.setBorderTop(BorderStyle.THIN); | |||||
style.setFillForegroundColor((short) 41); | |||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND); | |||||
style.setAlignment(HorizontalAlignment.CENTER); | |||||
style.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
style.setDataFormat(STRING_FORMAT); | style.setDataFormat(STRING_FORMAT); | ||||
if (isWarp) { | if (isWarp) { | ||||
style.setWrapText(true); | style.setWrapText(true); | ||||
@@ -15,9 +15,7 @@ | |||||
*/ | */ | ||||
package cn.afterturn.easypoi.excel.export.styler; | package cn.afterturn.easypoi.excel.export.styler; | ||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Font; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
import org.apache.poi.ss.usermodel.*; | |||||
/** | /** | ||||
* 样式的默认实现 | * 样式的默认实现 | ||||
@@ -34,8 +32,8 @@ public class ExcelExportStylerDefaultImpl extends AbstractExcelExportStyler | |||||
@Override | @Override | ||||
public CellStyle getTitleStyle(short color) { | public CellStyle getTitleStyle(short color) { | ||||
CellStyle titleStyle = workbook.createCellStyle(); | CellStyle titleStyle = workbook.createCellStyle(); | ||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
titleStyle.setAlignment(HorizontalAlignment.CENTER); | |||||
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
titleStyle.setWrapText(true); | titleStyle.setWrapText(true); | ||||
return titleStyle; | return titleStyle; | ||||
} | } | ||||
@@ -43,8 +41,8 @@ public class ExcelExportStylerDefaultImpl extends AbstractExcelExportStyler | |||||
@Override | @Override | ||||
public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { | public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { | ||||
CellStyle style = workbook.createCellStyle(); | CellStyle style = workbook.createCellStyle(); | ||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setAlignment(HorizontalAlignment.CENTER); | |||||
style.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
style.setDataFormat(STRING_FORMAT); | style.setDataFormat(STRING_FORMAT); | ||||
if (isWarp) { | if (isWarp) { | ||||
style.setWrapText(true); | style.setWrapText(true); | ||||
@@ -58,16 +56,16 @@ public class ExcelExportStylerDefaultImpl extends AbstractExcelExportStyler | |||||
Font font = workbook.createFont(); | Font font = workbook.createFont(); | ||||
font.setFontHeightInPoints((short) 12); | font.setFontHeightInPoints((short) 12); | ||||
titleStyle.setFont(font); | titleStyle.setFont(font); | ||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
titleStyle.setAlignment(HorizontalAlignment.CENTER); | |||||
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
return titleStyle; | return titleStyle; | ||||
} | } | ||||
@Override | @Override | ||||
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { | ||||
CellStyle style = workbook.createCellStyle(); | CellStyle style = workbook.createCellStyle(); | ||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setAlignment(HorizontalAlignment.CENTER); | |||||
style.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
style.setDataFormat(STRING_FORMAT); | style.setDataFormat(STRING_FORMAT); | ||||
if (isWarp) { | if (isWarp) { | ||||
style.setWrapText(true); | style.setWrapText(true); | ||||
@@ -30,12 +30,7 @@ import java.util.Set; | |||||
import cn.afterturn.easypoi.util.*; | import cn.afterturn.easypoi.util.*; | ||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import org.apache.poi.ss.usermodel.Cell; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Drawing; | |||||
import org.apache.poi.ss.usermodel.Row; | |||||
import org.apache.poi.ss.usermodel.Sheet; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
import org.apache.poi.ss.usermodel.*; | |||||
import org.apache.poi.ss.util.CellRangeAddress; | import org.apache.poi.ss.util.CellRangeAddress; | ||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
@@ -348,8 +343,8 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService { | |||||
} | } | ||||
for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { | for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { | ||||
cell = row.getCell(i); | cell = row.getCell(i); | ||||
if (row.getCell(i) != null && (cell.getCellType() == Cell.CELL_TYPE_STRING | |||||
|| cell.getCellType() == Cell.CELL_TYPE_NUMERIC)) { | |||||
if (row.getCell(i) != null && (cell.getCellType() == CellType.STRING | |||||
|| cell.getCellType() == CellType.NUMERIC)) { | |||||
String text = PoiCellUtil.getCellValue(cell); | String text = PoiCellUtil.getCellValue(cell); | ||||
if (text.contains(FOREACH_COL) || text.contains(FOREACH_COL_VALUE)) { | if (text.contains(FOREACH_COL) || text.contains(FOREACH_COL_VALUE)) { | ||||
foreachCol(cell, map, text); | foreachCol(cell, map, text); | ||||
@@ -413,9 +408,9 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService { | |||||
} | } | ||||
for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { | for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { | ||||
cell = row.getCell(i); | cell = row.getCell(i); | ||||
if (row.getCell(i) != null && (cell.getCellType() == Cell.CELL_TYPE_STRING | |||||
|| cell.getCellType() == Cell.CELL_TYPE_NUMERIC)) { | |||||
cell.setCellType(Cell.CELL_TYPE_STRING); | |||||
if (row.getCell(i) != null && (cell.getCellType() == CellType.STRING | |||||
|| cell.getCellType() == CellType.NUMERIC)) { | |||||
cell.setCellType(CellType.STRING); | |||||
String text = cell.getStringCellValue(); | String text = cell.getStringCellValue(); | ||||
if (text.contains(IF_DELETE)) { | if (text.contains(IF_DELETE)) { | ||||
if (Boolean.valueOf( | if (Boolean.valueOf( | ||||
@@ -438,12 +433,12 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService { | |||||
* @param map | * @param map | ||||
*/ | */ | ||||
private void setValueForCellByMap(Cell cell, Map<String, Object> map) throws Exception { | private void setValueForCellByMap(Cell cell, Map<String, Object> map) throws Exception { | ||||
int cellType = cell.getCellType(); | |||||
if (cellType != Cell.CELL_TYPE_STRING && cellType != Cell.CELL_TYPE_NUMERIC) { | |||||
CellType cellType = cell.getCellType(); | |||||
if (cellType != CellType.STRING && cellType != CellType.NUMERIC) { | |||||
return; | return; | ||||
} | } | ||||
String oldString; | String oldString; | ||||
cell.setCellType(Cell.CELL_TYPE_STRING); | |||||
cell.setCellType(CellType.STRING); | |||||
oldString = cell.getStringCellValue(); | oldString = cell.getStringCellValue(); | ||||
if (oldString != null && oldString.indexOf(START_STR) != -1 | if (oldString != null && oldString.indexOf(START_STR) != -1 | ||||
&& !oldString.contains(FOREACH)) { | && !oldString.contains(FOREACH)) { | ||||
@@ -467,7 +462,7 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService { | |||||
createImageCell(cell,img.getHeight(),img.getUrl(),img.getData()); | createImageCell(cell,img.getHeight(),img.getUrl(),img.getData()); | ||||
}else if (isNumber && StringUtils.isNotBlank(obj.toString())) { | }else if (isNumber && StringUtils.isNotBlank(obj.toString())) { | ||||
cell.setCellValue(Double.parseDouble(obj.toString())); | cell.setCellValue(Double.parseDouble(obj.toString())); | ||||
cell.setCellType(Cell.CELL_TYPE_NUMERIC); | |||||
cell.setCellType(CellType.NUMERIC); | |||||
} else { | } else { | ||||
cell.setCellValue(obj.toString()); | cell.setCellValue(obj.toString()); | ||||
} | } | ||||
@@ -580,7 +575,7 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService { | |||||
createImageCell(row.getCell(ci),img.getHeight(),img.getUrl(),img.getData()); | createImageCell(row.getCell(ci),img.getHeight(),img.getUrl(),img.getData()); | ||||
}else if (isNumber && StringUtils.isNotEmpty(val)) { | }else if (isNumber && StringUtils.isNotEmpty(val)) { | ||||
row.getCell(ci).setCellValue(Double.parseDouble(val)); | row.getCell(ci).setCellValue(Double.parseDouble(val)); | ||||
row.getCell(ci).setCellType(Cell.CELL_TYPE_NUMERIC); | |||||
row.getCell(ci).setCellType(CellType.NUMERIC); | |||||
} else { | } else { | ||||
try { | try { | ||||
row.getCell(ci).setCellValue(val); | row.getCell(ci).setCellValue(val); | ||||
@@ -44,7 +44,7 @@ public class ExcelChartBuildService | |||||
/** | /** | ||||
* | * | ||||
* @param workbook | * @param workbook | ||||
* @param graph | |||||
* @param graphList | |||||
* @param build 通过实时数据行来重新计算图形定义 | * @param build 通过实时数据行来重新计算图形定义 | ||||
* @param append | * @param append | ||||
*/ | */ | ||||
@@ -78,7 +78,9 @@ public class ExcelChartBuildService | |||||
* @param graph | * @param graph | ||||
*/ | */ | ||||
private static void buildExcelChart(Drawing drawing,ClientAnchor anchor,Sheet dataSourceSheet,ExcelGraph graph){ | private static void buildExcelChart(Drawing drawing,ClientAnchor anchor,Sheet dataSourceSheet,ExcelGraph graph){ | ||||
Chart chart = drawing.createChart(anchor); | |||||
Chart chart = null; | |||||
// TODO 图表没有成功 | |||||
//drawing.createChart(anchor); | |||||
ChartLegend legend = chart.getOrCreateLegend(); | ChartLegend legend = chart.getOrCreateLegend(); | ||||
legend.setPosition(LegendPosition.TOP_RIGHT); | legend.setPosition(LegendPosition.TOP_RIGHT); | ||||
@@ -7,6 +7,8 @@ import cn.afterturn.easypoi.excel.html.css.ICssConvertToExcel; | |||||
import cn.afterturn.easypoi.excel.html.css.ICssConvertToHtml; | import cn.afterturn.easypoi.excel.html.css.ICssConvertToHtml; | ||||
import cn.afterturn.easypoi.excel.html.entity.HtmlCssConstant; | import cn.afterturn.easypoi.excel.html.entity.HtmlCssConstant; | ||||
import cn.afterturn.easypoi.excel.html.entity.style.CellStyleEntity; | import cn.afterturn.easypoi.excel.html.entity.style.CellStyleEntity; | ||||
import org.apache.poi.ss.usermodel.HorizontalAlignment; | |||||
import org.apache.poi.ss.usermodel.VerticalAlignment; | |||||
public class AlignCssConvertImpl implements ICssConvertToExcel, ICssConvertToHtml { | public class AlignCssConvertImpl implements ICssConvertToExcel, ICssConvertToHtml { | ||||
@@ -20,23 +22,23 @@ public class AlignCssConvertImpl implements ICssConvertToExcel, ICssConvertToHtm | |||||
public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { | public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { | ||||
// align | // align | ||||
if (HtmlCssConstant.RIGHT.equals(style.getAlign())) { | if (HtmlCssConstant.RIGHT.equals(style.getAlign())) { | ||||
cellStyle.setAlignment(CellStyle.ALIGN_RIGHT); | |||||
cellStyle.setAlignment(HorizontalAlignment.RIGHT); | |||||
} else if (HtmlCssConstant.CENTER.equals(style.getAlign())) { | } else if (HtmlCssConstant.CENTER.equals(style.getAlign())) { | ||||
cellStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
cellStyle.setAlignment(HorizontalAlignment.CENTER); | |||||
} else if (HtmlCssConstant.LEFT.equals(style.getAlign())) { | } else if (HtmlCssConstant.LEFT.equals(style.getAlign())) { | ||||
cellStyle.setAlignment(CellStyle.ALIGN_LEFT); | |||||
cellStyle.setAlignment(HorizontalAlignment.LEFT); | |||||
} else if (HtmlCssConstant.JUSTIFY.equals(style.getAlign())) { | } else if (HtmlCssConstant.JUSTIFY.equals(style.getAlign())) { | ||||
cellStyle.setAlignment(CellStyle.ALIGN_JUSTIFY); | |||||
cellStyle.setAlignment(HorizontalAlignment.JUSTIFY); | |||||
} | } | ||||
// vertical align | // vertical align | ||||
if (HtmlCssConstant.TOP.equals(style.getVetical())) { | if (HtmlCssConstant.TOP.equals(style.getVetical())) { | ||||
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); | |||||
cellStyle.setVerticalAlignment(VerticalAlignment.TOP); | |||||
} else if (HtmlCssConstant.CENTER.equals(style.getAlign())) { | } else if (HtmlCssConstant.CENTER.equals(style.getAlign())) { | ||||
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); | |||||
} else if (HtmlCssConstant.BOTTOM.equals(style.getAlign())) { | } else if (HtmlCssConstant.BOTTOM.equals(style.getAlign())) { | ||||
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); | |||||
cellStyle.setVerticalAlignment(VerticalAlignment.BOTTOM); | |||||
} else if (HtmlCssConstant.JUSTIFY.equals(style.getAlign())) { | } else if (HtmlCssConstant.JUSTIFY.equals(style.getAlign())) { | ||||
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_JUSTIFY); | |||||
cellStyle.setVerticalAlignment(VerticalAlignment.JUSTIFY); | |||||
} | } | ||||
} | } | ||||
@@ -5,6 +5,7 @@ import org.apache.poi.hssf.usermodel.HSSFCell; | |||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||||
import org.apache.poi.ss.usermodel.Cell; | import org.apache.poi.ss.usermodel.Cell; | ||||
import org.apache.poi.ss.usermodel.CellStyle; | import org.apache.poi.ss.usermodel.CellStyle; | ||||
import org.apache.poi.ss.usermodel.FillPatternType; | |||||
import org.apache.poi.xssf.usermodel.XSSFCell; | import org.apache.poi.xssf.usermodel.XSSFCell; | ||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle; | import org.apache.poi.xssf.usermodel.XSSFCellStyle; | ||||
@@ -26,7 +27,7 @@ public class BackgroundCssConvertImpl implements ICssConvertToExcel, ICssConvert | |||||
if (StringUtils.isEmpty(style.getBackground())) { | if (StringUtils.isEmpty(style.getBackground())) { | ||||
return; | return; | ||||
} | } | ||||
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); // 填充图案 | |||||
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // 填充图案 | |||||
if (cell instanceof XSSFCell) { | if (cell instanceof XSSFCell) { | ||||
((XSSFCellStyle) cellStyle) | ((XSSFCellStyle) cellStyle) | ||||
.setFillForegroundColor(PoiCssUtils.parseColor(style.getBackground())); | .setFillForegroundColor(PoiCssUtils.parseColor(style.getBackground())); | ||||
@@ -23,6 +23,7 @@ import org.apache.commons.lang3.reflect.MethodUtils; | |||||
import org.apache.poi.hssf.usermodel.HSSFCell; | import org.apache.poi.hssf.usermodel.HSSFCell; | ||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||||
import org.apache.poi.hssf.util.HSSFColor; | import org.apache.poi.hssf.util.HSSFColor; | ||||
import org.apache.poi.ss.usermodel.BorderStyle; | |||||
import org.apache.poi.ss.usermodel.Cell; | import org.apache.poi.ss.usermodel.Cell; | ||||
import org.apache.poi.ss.usermodel.CellStyle; | import org.apache.poi.ss.usermodel.CellStyle; | ||||
import org.apache.poi.xssf.usermodel.XSSFCell; | import org.apache.poi.xssf.usermodel.XSSFCell; | ||||
@@ -109,31 +110,31 @@ public class BorderCssConverImpl implements ICssConvertToExcel, ICssConvertToHtm | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
log.error("Set Border Style Error Caused.", e); | log.error("Set Border Style Error Caused.", e); | ||||
} | } | ||||
short shortValue = -1; | |||||
BorderStyle shortValue = BorderStyle.NONE; | |||||
// empty or solid | // empty or solid | ||||
if (StringUtils.isBlank(styleValue) || "solid".equals(styleValue)) { | if (StringUtils.isBlank(styleValue) || "solid".equals(styleValue)) { | ||||
if (width > 2) { | if (width > 2) { | ||||
shortValue = CellStyle.BORDER_THICK; | |||||
shortValue = BorderStyle.THICK; | |||||
} else if (width > 1) { | } else if (width > 1) { | ||||
shortValue = CellStyle.BORDER_MEDIUM; | |||||
shortValue = BorderStyle.MEDIUM; | |||||
} else { | } else { | ||||
shortValue = CellStyle.BORDER_THIN; | |||||
shortValue = BorderStyle.THIN; | |||||
} | } | ||||
} else if (ArrayUtils.contains(new String[] { NONE, HIDDEN }, styleValue)) { | } else if (ArrayUtils.contains(new String[] { NONE, HIDDEN }, styleValue)) { | ||||
shortValue = CellStyle.BORDER_NONE; | |||||
shortValue = BorderStyle.NONE; | |||||
} else if (DOUBLE.equals(styleValue)) { | } else if (DOUBLE.equals(styleValue)) { | ||||
shortValue = CellStyle.BORDER_DOUBLE; | |||||
shortValue = BorderStyle.DOUBLE; | |||||
} else if (DOTTED.equals(styleValue)) { | } else if (DOTTED.equals(styleValue)) { | ||||
shortValue = CellStyle.BORDER_DOTTED; | |||||
shortValue = BorderStyle.DOTTED; | |||||
} else if (DASHED.equals(styleValue)) { | } else if (DASHED.equals(styleValue)) { | ||||
if (width > 1) { | if (width > 1) { | ||||
shortValue = CellStyle.BORDER_MEDIUM_DASHED; | |||||
shortValue = BorderStyle.MEDIUM_DASHED; | |||||
} else { | } else { | ||||
shortValue = CellStyle.BORDER_DASHED; | |||||
shortValue = BorderStyle.DASHED; | |||||
} | } | ||||
} | } | ||||
// border style | // border style | ||||
if (shortValue != -1) { | |||||
if (shortValue != BorderStyle.NONE) { | |||||
try { | try { | ||||
MethodUtils.invokeMethod(cellStyle, "setBorder" + posName, shortValue); | MethodUtils.invokeMethod(cellStyle, "setBorder" + posName, shortValue); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
@@ -1,12 +1,12 @@ | |||||
package cn.afterturn.easypoi.excel.html.css.impl; | package cn.afterturn.easypoi.excel.html.css.impl; | ||||
import static cn.afterturn.easypoi.excel.html.entity.HtmlCssConstant.*; | import static cn.afterturn.easypoi.excel.html.entity.HtmlCssConstant.*; | ||||
import static org.apache.poi.ss.usermodel.IndexedColors.BLACK; | |||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import org.apache.poi.hssf.usermodel.HSSFFont; | import org.apache.poi.hssf.usermodel.HSSFFont; | ||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||||
import org.apache.poi.hssf.util.HSSFColor; | 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.Cell; | ||||
import org.apache.poi.ss.usermodel.CellStyle; | import org.apache.poi.ss.usermodel.CellStyle; | ||||
import org.apache.poi.ss.usermodel.Font; | import org.apache.poi.ss.usermodel.Font; | ||||
@@ -41,7 +41,7 @@ public class TextCssConvertImpl implements ICssConvertToExcel, ICssConvertToHtml | |||||
font.setFontHeightInPoints((short) fontSize); | font.setFontHeightInPoints((short) fontSize); | ||||
} | } | ||||
if (BOLD.equals(style.getFont().getWeight())) { | if (BOLD.equals(style.getFont().getWeight())) { | ||||
font.setBoldweight(Font.BOLDWEIGHT_BOLD); | |||||
font.setBold(true); | |||||
} | } | ||||
String fontFamily = style.getFont().getFamily(); | String fontFamily = style.getFont().getFamily(); | ||||
if (StringUtils.isNotBlank(fontFamily)) { | if (StringUtils.isNotBlank(fontFamily)) { | ||||
@@ -6,6 +6,7 @@ import java.util.Map; | |||||
import org.apache.poi.hssf.usermodel.HSSFRichTextString; | import org.apache.poi.hssf.usermodel.HSSFRichTextString; | ||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||||
import org.apache.poi.ss.usermodel.Cell; | import org.apache.poi.ss.usermodel.Cell; | ||||
import org.apache.poi.ss.usermodel.CellType; | |||||
import org.apache.poi.ss.usermodel.Font; | import org.apache.poi.ss.usermodel.Font; | ||||
import org.apache.poi.ss.usermodel.Workbook; | import org.apache.poi.ss.usermodel.Workbook; | ||||
import org.apache.poi.xssf.usermodel.XSSFFont; | import org.apache.poi.xssf.usermodel.XSSFFont; | ||||
@@ -49,7 +50,7 @@ public class CellValueHelper { | |||||
private void cacheFontInfo(Workbook wb) { | private void cacheFontInfo(Workbook wb) { | ||||
for (short i = 0, le = wb.getNumberOfFonts(); i < le; i++) { | for (short i = 0, le = wb.getNumberOfFonts(); i < le; i++) { | ||||
Font font = wb.getFontAt(i); | Font font = wb.getFontAt(i); | ||||
fontCache.put(font.getBoldweight() + "_" + font.getItalic() + "_" + font.getFontName() | |||||
fontCache.put(font.getBold() + "_" + font.getItalic() + "_" + font.getFontName() | |||||
+ "_" + font.getFontHeightInPoints() + "_" + font.getColor(), | + "_" + font.getFontHeightInPoints() + "_" + font.getColor(), | ||||
font.getIndex() + ""); | font.getIndex() + ""); | ||||
} | } | ||||
@@ -57,11 +58,11 @@ public class CellValueHelper { | |||||
} | } | ||||
public String getHtmlValue(Cell cell) { | public String getHtmlValue(Cell cell) { | ||||
if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType() | |||||
|| Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { | |||||
cell.setCellType(Cell.CELL_TYPE_STRING); | |||||
if (CellType.BOOLEAN == cell.getCellType() | |||||
|| CellType.NUMERIC == cell.getCellType()) { | |||||
cell.setCellType(CellType.STRING); | |||||
return cell.getStringCellValue(); | return cell.getStringCellValue(); | ||||
} else if (Cell.CELL_TYPE_STRING == cell.getCellType()) { | |||||
} else if (CellType.STRING == cell.getCellType()) { | |||||
if (cell.getRichStringCellValue().numFormattingRuns() == 0) { | if (cell.getRichStringCellValue().numFormattingRuns() == 0) { | ||||
return XmlEscapers.xmlContentEscaper().escape(cell.getStringCellValue()); | return XmlEscapers.xmlContentEscaper().escape(cell.getStringCellValue()); | ||||
} else if (is07) { | } else if (is07) { | ||||
@@ -135,7 +136,7 @@ public class CellValueHelper { | |||||
private String getFontIndex(XSSFFont font) { | private String getFontIndex(XSSFFont font) { | ||||
return fontCache | return fontCache | ||||
.get(font.getBoldweight() + "_" + font.getItalic() + "_" + font.getFontName() + "_" | |||||
.get(font.getBold() + "_" + font.getItalic() + "_" + font.getFontName() + "_" | |||||
+ font.getFontHeightInPoints() + "_" + font.getColor()); | + font.getFontHeightInPoints() + "_" + font.getColor()); | ||||
} | } | ||||
} | } |
@@ -1,15 +1,5 @@ | |||||
package cn.afterturn.easypoi.excel.html.helper; | package cn.afterturn.easypoi.excel.html.helper; | ||||
import static org.apache.poi.ss.usermodel.CellStyle.ALIGN_CENTER; | |||||
import static org.apache.poi.ss.usermodel.CellStyle.ALIGN_CENTER_SELECTION; | |||||
import static org.apache.poi.ss.usermodel.CellStyle.ALIGN_FILL; | |||||
import static org.apache.poi.ss.usermodel.CellStyle.ALIGN_JUSTIFY; | |||||
import static org.apache.poi.ss.usermodel.CellStyle.ALIGN_LEFT; | |||||
import static org.apache.poi.ss.usermodel.CellStyle.ALIGN_RIGHT; | |||||
import static org.apache.poi.ss.usermodel.CellStyle.VERTICAL_BOTTOM; | |||||
import static org.apache.poi.ss.usermodel.CellStyle.VERTICAL_CENTER; | |||||
import static org.apache.poi.ss.usermodel.CellStyle.VERTICAL_TOP; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||
@@ -23,13 +13,7 @@ import org.apache.poi.hssf.usermodel.HSSFCellStyle; | |||||
import org.apache.poi.hssf.usermodel.HSSFPalette; | import org.apache.poi.hssf.usermodel.HSSFPalette; | ||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||||
import org.apache.poi.hssf.util.HSSFColor; | import org.apache.poi.hssf.util.HSSFColor; | ||||
import org.apache.poi.ss.usermodel.Cell; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Color; | |||||
import org.apache.poi.ss.usermodel.Font; | |||||
import org.apache.poi.ss.usermodel.Row; | |||||
import org.apache.poi.ss.usermodel.Sheet; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
import org.apache.poi.ss.usermodel.*; | |||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle; | import org.apache.poi.xssf.usermodel.XSSFCellStyle; | ||||
import org.apache.poi.xssf.usermodel.XSSFColor; | import org.apache.poi.xssf.usermodel.XSSFColor; | ||||
import org.apache.poi.xssf.usermodel.XSSFFont; | import org.apache.poi.xssf.usermodel.XSSFFont; | ||||
@@ -39,31 +23,34 @@ import cn.afterturn.easypoi.util.PoiPublicUtil; | |||||
/** | /** | ||||
* 样式帮助类 | * 样式帮助类 | ||||
* | |||||
* @author JueYue | * @author JueYue | ||||
* 2015年5月9日 下午4:04:24 | |||||
* 2015年5月9日 下午4:04:24 | |||||
*/ | */ | ||||
public class StylerHelper { | public class StylerHelper { | ||||
private static String DEFAULTS_CLASS_CSS = ".excelDefaults {background-color: white;color: black;text-decoration: none;direction: ltr;text-transform: none;text-indent: 0;letter-spacing: 0;word-spacing: 0;white-space: normal;unicode-bidi: normal;vertical-align: 0;text-shadow: none;padding: 0;margin: 0;border-collapse: collapse;white-space: pre-wrap;word-wrap: break-word;word-break: break-all;}.excelDefaults td {padding: 1px 5px;border: 1px solid silver;border-color: #000000;text-align: center;vertical-align: middle;font-size: 12pt;}.excelDefaults .colHeader {background-color: silver;font-weight: bold;border: 1px solid black;text-align: center;padding: 1px 5px;}.excelDefaults .rowHeader {background-color: silver;font-weight: bold;border: 1px solid black;text-align: right;padding: 1px 5px;}"; | |||||
private static String DEFAULTS_CLASS_CSS = ".excelDefaults {background-color: white;color: black;text-decoration: none;direction: ltr;text-transform: none;text-indent: 0;letter-spacing: 0;word-spacing: 0;white-space: normal;unicode-bidi: normal;vertical-align: 0;text-shadow: none;padding: 0;margin: 0;border-collapse: collapse;white-space: pre-wrap;word-wrap: break-word;word-break: break-all;}.excelDefaults td {padding: 1px 5px;border: 1px solid silver;border-color: #000000;text-align: center;vertical-align: middle;font-size: 12pt;}.excelDefaults .colHeader {background-color: silver;font-weight: bold;border: 1px solid black;text-align: center;padding: 1px 5px;}.excelDefaults .rowHeader {background-color: silver;font-weight: bold;border: 1px solid black;text-align: right;padding: 1px 5px;}"; | |||||
private static final String DEFAULTS_CLASS = "excelDefaults"; | |||||
private static final String DEFAULTS_CLASS = "excelDefaults"; | |||||
private static final Map<Short, String> ALIGN = PoiPublicUtil.mapFor(ALIGN_LEFT, | |||||
"left", ALIGN_CENTER, "center", ALIGN_RIGHT, "right", ALIGN_FILL, "left", ALIGN_JUSTIFY, | |||||
"left", ALIGN_CENTER_SELECTION, "center"); | |||||
private static final Map<HorizontalAlignment, String> ALIGN = PoiPublicUtil.mapFor(HorizontalAlignment.LEFT, | |||||
"left", HorizontalAlignment.CENTER, "center", HorizontalAlignment.RIGHT, "right", HorizontalAlignment.FILL, | |||||
"left", HorizontalAlignment.JUSTIFY, | |||||
"left", HorizontalAlignment.CENTER_SELECTION, "center"); | |||||
private static final Map<Short, String> VERTICAL_ALIGN = PoiPublicUtil | |||||
.mapFor(VERTICAL_BOTTOM, "bottom", VERTICAL_CENTER, "middle", VERTICAL_TOP, "top"); | |||||
private static final Map<VerticalAlignment, String> VERTICAL_ALIGN = PoiPublicUtil | |||||
.mapFor(VerticalAlignment.BOTTOM, "bottom", VerticalAlignment.CENTER, | |||||
"middle", VerticalAlignment.TOP, "top"); | |||||
private Formatter out; | |||||
private Formatter out; | |||||
private Sheet sheet; | |||||
private Sheet sheet; | |||||
private HtmlHelper helper; | |||||
private HtmlHelper helper; | |||||
private int sheetNum; | |||||
private int sheetNum; | |||||
private int cssRandom; | |||||
private int cssRandom; | |||||
public StylerHelper(Workbook wb, Formatter out, int sheetNum, int cssRandom) { | public StylerHelper(Workbook wb, Formatter out, int sheetNum, int cssRandom) { | ||||
this.out = out; | this.out = out; | ||||
@@ -123,7 +110,7 @@ public class StylerHelper { | |||||
Formatter formatter = new Formatter(sb); | Formatter formatter = new Formatter(sb); | ||||
try { | try { | ||||
in = new BufferedReader( | in = new BufferedReader( | ||||
new InputStreamReader(StylerHelper.class.getResourceAsStream("excelStyle.css"))); | |||||
new InputStreamReader(StylerHelper.class.getResourceAsStream("excelStyle.css"))); | |||||
String line; | String line; | ||||
while ((line = in.readLine()) != null) { | while ((line = in.readLine()) != null) { | ||||
formatter.format("%s%n", line); | formatter.format("%s%n", line); | ||||
@@ -150,15 +137,15 @@ public class StylerHelper { | |||||
} | } | ||||
private void styleContents(CellStyle style) { | private void styleContents(CellStyle style) { | ||||
if (style.getAlignment() != 2) { | |||||
if (style.getAlignment() != HorizontalAlignment.CENTER) { | |||||
styleOut("text-align", style.getAlignment(), ALIGN); | styleOut("text-align", style.getAlignment(), ALIGN); | ||||
styleOut("vertical-align", style.getAlignment(), VERTICAL_ALIGN); | |||||
styleOut("vertical-align", style.getVerticalAlignment(), VERTICAL_ALIGN); | |||||
} | } | ||||
helper.colorStyles(style, out); | helper.colorStyles(style, out); | ||||
} | } | ||||
private void fontStyle(Font font) { | private void fontStyle(Font font) { | ||||
if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD) { | |||||
if (font.getBold()) { | |||||
out.format(" font-weight: bold;%n"); | out.format(" font-weight: bold;%n"); | ||||
} | } | ||||
if (font.getItalic()) { | if (font.getItalic()) { | ||||
@@ -177,7 +164,7 @@ public class StylerHelper { | |||||
private Color getColor(Font font) { | private Color getColor(Font font) { | ||||
if (helper instanceof HSSFHtmlHelper) { | if (helper instanceof HSSFHtmlHelper) { | ||||
return ((HSSFWorkbook) sheet.getWorkbook()).getCustomPalette() | return ((HSSFWorkbook) sheet.getWorkbook()).getCustomPalette() | ||||
.getColor(font.getColor()); | |||||
.getColor(font.getColor()); | |||||
} else { | } else { | ||||
return ((XSSFFont) font).getXSSFColor(); | return ((XSSFFont) font).getXSSFColor(); | ||||
} | } | ||||
@@ -211,9 +198,9 @@ public class StylerHelper { | |||||
private class HSSFHtmlHelper implements HtmlHelper { | private class HSSFHtmlHelper implements HtmlHelper { | ||||
private final HSSFWorkbook wb; | private final HSSFWorkbook wb; | ||||
private final HSSFPalette colors; | |||||
private final HSSFPalette colors; | |||||
private HSSFColor hssfAuto = new HSSFColor.AUTOMATIC(); | |||||
private HSSFColor hssfAuto = HSSFColor.HSSFColorPredefined.AUTOMATIC.getColor(); | |||||
public HSSFHtmlHelper(HSSFWorkbook wb) { | public HSSFHtmlHelper(HSSFWorkbook wb) { | ||||
this.wb = wb; | this.wb = wb; | ||||
@@ -235,7 +222,7 @@ public class StylerHelper { | |||||
} else { | } else { | ||||
short[] rgb = color.getTriplet(); | short[] rgb = color.getTriplet(); | ||||
out.format(" %s: #%02x%02x%02x; /* index = %d */%n", attr, rgb[0], rgb[1], rgb[2], | out.format(" %s: #%02x%02x%02x; /* index = %d */%n", attr, rgb[0], rgb[1], rgb[2], | ||||
index); | |||||
index); | |||||
} | } | ||||
} | } | ||||
@@ -81,7 +81,7 @@ public class CellValueService { | |||||
result = getDateData(entity, cell.getStringCellValue()); | result = getDateData(entity, cell.getStringCellValue()); | ||||
}*/ | }*/ | ||||
//FIX: 单元格yyyyMMdd数字时候使用 cell.getDateCellValue() 解析出的日期错误 | //FIX: 单元格yyyyMMdd数字时候使用 cell.getDateCellValue() 解析出的日期错误 | ||||
if (Cell.CELL_TYPE_NUMERIC == cell.getCellType() && DateUtil.isCellDateFormatted(cell)) { | |||||
if (CellType.NUMERIC == cell.getCellType() && DateUtil.isCellDateFormatted(cell)) { | |||||
result = DateUtil.getJavaDate(cell.getNumericCellValue()); | result = DateUtil.getJavaDate(cell.getNumericCellValue()); | ||||
} else { | } else { | ||||
cell.setCellType(CellType.STRING); | cell.setCellType(CellType.STRING); | ||||
@@ -96,15 +96,15 @@ public class CellValueService { | |||||
if (("class java.sql.Timestamp").equals(classFullName)) { | if (("class java.sql.Timestamp").equals(classFullName)) { | ||||
result = new Timestamp(((Date) result).getTime()); | result = new Timestamp(((Date) result).getTime()); | ||||
} | } | ||||
} else if (Cell.CELL_TYPE_NUMERIC == cell.getCellType() && DateUtil.isCellDateFormatted(cell)) { | |||||
} else if (CellType.NUMERIC == cell.getCellType() && DateUtil.isCellDateFormatted(cell)) { | |||||
result = DateUtil.getJavaDate(cell.getNumericCellValue()); | result = DateUtil.getJavaDate(cell.getNumericCellValue()); | ||||
} else { | } else { | ||||
switch (cell.getCellType()) { | switch (cell.getCellType()) { | ||||
case Cell.CELL_TYPE_STRING: | |||||
case STRING: | |||||
result = cell.getRichStringCellValue() == null ? "" | result = cell.getRichStringCellValue() == null ? "" | ||||
: cell.getRichStringCellValue().getString(); | : cell.getRichStringCellValue().getString(); | ||||
break; | break; | ||||
case Cell.CELL_TYPE_NUMERIC: | |||||
case NUMERIC: | |||||
if (DateUtil.isCellDateFormatted(cell)) { | if (DateUtil.isCellDateFormatted(cell)) { | ||||
if ("class java.lang.String".equals(classFullName)) { | if ("class java.lang.String".equals(classFullName)) { | ||||
result = formateDate(entity, cell.getDateCellValue()); | result = formateDate(entity, cell.getDateCellValue()); | ||||
@@ -113,14 +113,14 @@ public class CellValueService { | |||||
result = readNumericCell(cell); | result = readNumericCell(cell); | ||||
} | } | ||||
break; | break; | ||||
case Cell.CELL_TYPE_BOOLEAN: | |||||
case BOOLEAN: | |||||
result = Boolean.toString(cell.getBooleanCellValue()); | result = Boolean.toString(cell.getBooleanCellValue()); | ||||
break; | break; | ||||
case Cell.CELL_TYPE_BLANK: | |||||
case BLANK: | |||||
break; | break; | ||||
case Cell.CELL_TYPE_ERROR: | |||||
case ERROR: | |||||
break; | break; | ||||
case Cell.CELL_TYPE_FORMULA: | |||||
case FORMULA: | |||||
try { | try { | ||||
result = readNumericCell(cell); | result = readNumericCell(cell); | ||||
} catch (Exception e1) { | } catch (Exception e1) { | ||||
@@ -18,10 +18,6 @@ import org.apache.commons.lang3.StringUtils; | |||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder; | import org.apache.commons.lang3.builder.ReflectionToStringBuilder; | ||||
import org.apache.poi.hssf.usermodel.HSSFSheet; | import org.apache.poi.hssf.usermodel.HSSFSheet; | ||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; | |||||
import org.apache.poi.openxml4j.opc.OPCPackage; | |||||
import org.apache.poi.poifs.filesystem.DocumentFactoryHelper; | |||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | |||||
import org.apache.poi.ss.formula.functions.T; | import org.apache.poi.ss.formula.functions.T; | ||||
import org.apache.poi.ss.usermodel.Cell; | import org.apache.poi.ss.usermodel.Cell; | ||||
import org.apache.poi.ss.usermodel.CellStyle; | import org.apache.poi.ss.usermodel.CellStyle; | ||||
@@ -4,6 +4,7 @@ | |||||
package cn.afterturn.easypoi.util; | package cn.afterturn.easypoi.util; | ||||
import org.apache.poi.ss.usermodel.Cell; | import org.apache.poi.ss.usermodel.Cell; | ||||
import org.apache.poi.ss.usermodel.CellType; | |||||
import org.apache.poi.ss.usermodel.Row; | import org.apache.poi.ss.usermodel.Row; | ||||
import org.apache.poi.ss.usermodel.Sheet; | import org.apache.poi.ss.usermodel.Sheet; | ||||
import org.apache.poi.ss.util.CellRangeAddress; | import org.apache.poi.ss.util.CellRangeAddress; | ||||
@@ -104,24 +105,24 @@ public class PoiCellUtil { | |||||
return ""; | return ""; | ||||
} | } | ||||
if (cell.getCellType() == Cell.CELL_TYPE_STRING) { | |||||
if (cell.getCellType() == CellType.STRING) { | |||||
return cell.getStringCellValue(); | return cell.getStringCellValue(); | ||||
} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { | |||||
} else if (cell.getCellType() == CellType.BOOLEAN) { | |||||
return String.valueOf(cell.getBooleanCellValue()); | return String.valueOf(cell.getBooleanCellValue()); | ||||
} else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { | |||||
} else if (cell.getCellType() == CellType.FORMULA) { | |||||
return cell.getStringCellValue(); | return cell.getStringCellValue(); | ||||
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { | |||||
} else if (cell.getCellType() == CellType.NUMERIC) { | |||||
return String.valueOf(cell.getNumericCellValue()); | return String.valueOf(cell.getNumericCellValue()); | ||||
} else { | } else { | ||||
cell.setCellType(Cell.CELL_TYPE_STRING); | |||||
cell.setCellType(CellType.STRING); | |||||
return cell.getStringCellValue(); | return cell.getStringCellValue(); | ||||
} | } | ||||
} | } | ||||
@@ -40,17 +40,17 @@ public class PoiCssUtils { | |||||
colors.put(colorName(color.getValue().getClass()), color.getValue()); | colors.put(colorName(color.getValue().getClass()), color.getValue()); | ||||
} | } | ||||
// light gray | // light gray | ||||
HSSFColor color = colors.get(colorName(HSSFColor.GREY_25_PERCENT.class)); | |||||
HSSFColor color = colors.get(colorName(HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getColor().getClass())); | |||||
colors.put("lightgray", color); | colors.put("lightgray", color); | ||||
colors.put("lightgrey", color); | colors.put("lightgrey", color); | ||||
// silver | // silver | ||||
colors.put("silver", colors.get(colorName(HSSFColor.GREY_40_PERCENT.class))); | |||||
colors.put("silver", colors.get(colorName(HSSFColor.HSSFColorPredefined.GREY_40_PERCENT.getColor().getClass()))); | |||||
// darkgray | // darkgray | ||||
color = colors.get(colorName(HSSFColor.GREY_50_PERCENT.class)); | |||||
color = colors.get(colorName(HSSFColor.HSSFColorPredefined.GREY_50_PERCENT.getColor().getClass())); | |||||
colors.put("darkgray", color); | colors.put("darkgray", color); | ||||
colors.put("darkgrey", color); | colors.put("darkgrey", color); | ||||
// gray | // gray | ||||
color = colors.get(colorName(HSSFColor.GREY_80_PERCENT.class)); | |||||
color = colors.get(colorName(HSSFColor.HSSFColorPredefined.GREY_80_PERCENT.getColor().getClass())); | |||||
colors.put("gray", color); | colors.put("gray", color); | ||||
colors.put("grey", color); | colors.put("grey", color); | ||||
} | } | ||||
@@ -165,7 +165,7 @@ public class PoiCssUtils { | |||||
if (StringUtils.isNotBlank(color)) { | if (StringUtils.isNotBlank(color)) { | ||||
Color awtColor = Color.decode(color); | Color awtColor = Color.decode(color); | ||||
if (awtColor != null) { | if (awtColor != null) { | ||||
poiColor = new XSSFColor(awtColor); | |||||
poiColor = new XSSFColor(awtColor,null); | |||||
} | } | ||||
} | } | ||||
return poiColor; | return poiColor; | ||||
@@ -33,13 +33,13 @@ import java.util.Map; | |||||
import javax.imageio.ImageIO; | import javax.imageio.ImageIO; | ||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import org.apache.poi.POIXMLDocumentPart; | |||||
import org.apache.poi.hssf.usermodel.HSSFClientAnchor; | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; | ||||
import org.apache.poi.hssf.usermodel.HSSFPicture; | import org.apache.poi.hssf.usermodel.HSSFPicture; | ||||
import org.apache.poi.hssf.usermodel.HSSFPictureData; | import org.apache.poi.hssf.usermodel.HSSFPictureData; | ||||
import org.apache.poi.hssf.usermodel.HSSFShape; | import org.apache.poi.hssf.usermodel.HSSFShape; | ||||
import org.apache.poi.hssf.usermodel.HSSFSheet; | import org.apache.poi.hssf.usermodel.HSSFSheet; | ||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||||
import org.apache.poi.ooxml.POIXMLDocumentPart; | |||||
import org.apache.poi.ss.usermodel.PictureData; | import org.apache.poi.ss.usermodel.PictureData; | ||||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor; | import org.apache.poi.xssf.usermodel.XSSFClientAnchor; | ||||
import org.apache.poi.xssf.usermodel.XSSFDrawing; | import org.apache.poi.xssf.usermodel.XSSFDrawing; | ||||
@@ -83,23 +83,23 @@ public class PoiSheetUtil { | |||||
cNew.setCellStyle(cOld.getCellStyle()); | cNew.setCellStyle(cOld.getCellStyle()); | ||||
switch (cNew.getCellType()) { | switch (cNew.getCellType()) { | ||||
case Cell.CELL_TYPE_BOOLEAN: { | |||||
case BOOLEAN: { | |||||
cNew.setCellValue(cOld.getBooleanCellValue()); | cNew.setCellValue(cOld.getBooleanCellValue()); | ||||
break; | break; | ||||
} | } | ||||
case Cell.CELL_TYPE_NUMERIC: { | |||||
case NUMERIC: { | |||||
cNew.setCellValue(cOld.getNumericCellValue()); | cNew.setCellValue(cOld.getNumericCellValue()); | ||||
break; | break; | ||||
} | } | ||||
case Cell.CELL_TYPE_STRING: { | |||||
case STRING: { | |||||
cNew.setCellValue(cOld.getStringCellValue()); | cNew.setCellValue(cOld.getStringCellValue()); | ||||
break; | break; | ||||
} | } | ||||
case Cell.CELL_TYPE_ERROR: { | |||||
case ERROR: { | |||||
cNew.setCellValue(cOld.getErrorCellValue()); | cNew.setCellValue(cOld.getErrorCellValue()); | ||||
break; | break; | ||||
} | } | ||||
case Cell.CELL_TYPE_FORMULA: { | |||||
case FORMULA: { | |||||
cNew.setCellFormula(cOld.getCellFormula()); | cNew.setCellFormula(cOld.getCellFormula()); | ||||
break; | break; | ||||
} | } | ||||
@@ -4,7 +4,7 @@ | |||||
<parent> | <parent> | ||||
<groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
<artifactId>easypoi</artifactId> | <artifactId>easypoi</artifactId> | ||||
<version>3.3.0</version> | |||||
<version>4.0.0-SNAPSHOT</version> | |||||
</parent> | </parent> | ||||
<artifactId>easypoi-web</artifactId> | <artifactId>easypoi-web</artifactId> | ||||
<dependencies> | <dependencies> | ||||
@@ -3,7 +3,7 @@ | |||||
<modelVersion>4.0.0</modelVersion> | <modelVersion>4.0.0</modelVersion> | ||||
<groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
<artifactId>easypoi</artifactId> | <artifactId>easypoi</artifactId> | ||||
<version>3.3.0</version> | |||||
<version>4.0.0-SNAPSHOT</version> | |||||
<packaging>pom</packaging> | <packaging>pom</packaging> | ||||
<name>easypoi</name> | <name>easypoi</name> | ||||
<modules> | <modules> | ||||
@@ -45,13 +45,13 @@ | |||||
</organization> | </organization> | ||||
<properties> | <properties> | ||||
<sub.version>3.3.0</sub.version> | |||||
<poi.version>3.15</poi.version> | |||||
<sub.version>4.0.0-SNAPSHOT</sub.version> | |||||
<poi.version>4.0.0</poi.version> | |||||
<xerces.version>2.9.1</xerces.version> | <xerces.version>2.9.1</xerces.version> | ||||
<guava.version>16.0.1</guava.version> | <guava.version>16.0.1</guava.version> | ||||
<commons-lang.version>3.2.1</commons-lang.version> | <commons-lang.version>3.2.1</commons-lang.version> | ||||
<slf4j.version>1.6.1</slf4j.version> | <slf4j.version>1.6.1</slf4j.version> | ||||
<spring.version>4.3.8.RELEASE</spring.version> | |||||
<spring.version>5.0.6.RELEASE</spring.version> | |||||
</properties> | </properties> | ||||
<dependencyManagement> | <dependencyManagement> | ||||
<dependencies> | <dependencies> | ||||
@@ -94,8 +94,8 @@ | |||||
<!-- Word 使用--> | <!-- Word 使用--> | ||||
<dependency> | <dependency> | ||||
<groupId>org.apache.poi</groupId> | <groupId>org.apache.poi</groupId> | ||||
<artifactId>ooxml-schemas</artifactId> | |||||
<version>1.3</version> | |||||
<artifactId>poi-ooxml-schemas</artifactId> | |||||
<version>${poi.version}</version> | |||||
<optional>true</optional> | <optional>true</optional> | ||||
</dependency> | </dependency> | ||||
@@ -244,8 +244,8 @@ | |||||
<artifactId>maven-compiler-plugin</artifactId> | <artifactId>maven-compiler-plugin</artifactId> | ||||
<version>3.0</version> | <version>3.0</version> | ||||
<configuration> | <configuration> | ||||
<source>1.6</source> | |||||
<target>1.6</target> | |||||
<source>1.8</source> | |||||
<target>1.8</target> | |||||
<encoding>UTF-8</encoding> | <encoding>UTF-8</encoding> | ||||
</configuration> | </configuration> | ||||
</plugin> | </plugin> | ||||