Browse Source

用阿里巴巴的代码规范插件,修复了一版

4.1.3.A
jueyue 7 years ago
parent
commit
c7e80a9edf
33 changed files with 162 additions and 119 deletions
  1. +1
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoaderImpl.java
  2. +4
    -2
      easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/POICacheManager.java
  3. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelBaseEntity.java
  4. +10
    -5
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java
  5. +3
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/vo/BaseEntityTypeConstants.java
  6. +2
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelBatchExportServer.java
  7. +5
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportServer.java
  8. +12
    -14
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportServer.java
  9. +4
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java
  10. +2
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/TemplateSumHanlder.java
  11. +7
    -7
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/builder/ExcelChartBuildService.java
  12. +2
    -2
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/constant/ExcelGraphElementType.java
  13. +2
    -2
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/constant/ExcelGraphType.java
  14. +11
    -6
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraphDefined.java
  15. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraphElement.java
  16. +9
    -5
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/ExcelToHtmlServer.java
  17. +5
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/css/CssParseServer.java
  18. +5
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/helper/CellValueHelper.java
  19. +19
    -10
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/helper/StylerHelper.java
  20. +8
    -7
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java
  21. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java
  22. +2
    -2
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/SheetHandler.java
  23. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/parse/SaxRowRead.java
  24. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/pdf/export/PdfExportServer.java
  25. +2
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCellUtil.java
  26. +8
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCssUtils.java
  27. +3
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiFunctionUtil.java
  28. +9
    -9
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiPublicUtil.java
  29. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiReflectorUtil.java
  30. +10
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiSheetUtility.java
  31. +4
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.java
  32. +6
    -6
      easypoi-base/src/main/java/cn/afterturn/easypoi/word/entity/MyXWPFDocument.java
  33. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/word/parse/excel/ExcelEntityParse.java

+ 1
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoaderImpl.java View File

@@ -37,6 +37,7 @@ public class FileLoaderImpl implements IFileLoader {


private static final Logger LOGGER = LoggerFactory.getLogger(FileLoaderImpl.class); private static final Logger LOGGER = LoggerFactory.getLogger(FileLoaderImpl.class);


@Override
public byte[] getFile(String url) { public byte[] getFile(String url) {
InputStream fileis = null; InputStream fileis = null;
ByteArrayOutputStream baos = null; ByteArrayOutputStream baos = null;


+ 4
- 2
easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/POICacheManager.java View File

@@ -52,8 +52,9 @@ public final class POICacheManager {
.build(new CacheLoader<String, byte[]>() { .build(new CacheLoader<String, byte[]>() {
@Override @Override
public byte[] load(String url) throws Exception { public byte[] load(String url) throws Exception {
if (LOCAL_FILELOADER.get() != null)
if (LOCAL_FILELOADER.get() != null) {
return LOCAL_FILELOADER.get().getFile(url); return LOCAL_FILELOADER.get().getFile(url);
}
return fileLoder.getFile(url); return fileLoder.getFile(url);
} }
}); });
@@ -81,8 +82,9 @@ public final class POICacheManager {
* @param fileLoder * @param fileLoder
*/ */
public static void setFileLoderOnce(IFileLoader fileLoder) { public static void setFileLoderOnce(IFileLoader fileLoder) {
if (fileLoder != null)
if (fileLoder != null) {
LOCAL_FILELOADER.set(fileLoder); LOCAL_FILELOADER.set(fileLoder);
}
} }
public static void setLoadingCache(LoadingCache<String, byte[]> loadingCache) { public static void setLoadingCache(LoadingCache<String, byte[]> loadingCache) {


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelBaseEntity.java View File

@@ -37,7 +37,7 @@ public class ExcelBaseEntity {
/** /**
* 对应type * 对应type
*/ */
private int type = BaseEntityTypeConstants.StringType;
private int type = BaseEntityTypeConstants.STRING_TYPE;
/** /**
* 数据库格式 * 数据库格式
*/ */


+ 10
- 5
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java View File

@@ -212,18 +212,23 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable<Exc
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true; return true;
if (obj == null)
}
if (obj == null) {
return false; return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false; return false;
}
ExcelExportEntity other = (ExcelExportEntity) obj; ExcelExportEntity other = (ExcelExportEntity) obj;
if (key == null) { if (key == null) {
if (other.key != null)
if (other.key != null) {
return false; return false;
} else if (!key.equals(other.key))
}
} else if (!key.equals(other.key)) {
return false; return false;
}
return true; return true;
} }
} }

+ 3
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/vo/BaseEntityTypeConstants.java View File

@@ -11,7 +11,7 @@ package cn.afterturn.easypoi.excel.entity.vo;
* *
*/ */
public interface BaseEntityTypeConstants { public interface BaseEntityTypeConstants {
public final static Integer StringType = 1;
public final static Integer DoubleType = 10;
public final static Integer ImageType = 3;
public final static Integer STRING_TYPE = 1;
public final static Integer DOUBLE_TYPE = 10;
public final static Integer IMAGE_TYPE = 3;
} }

+ 2
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelBatchExportServer.java View File

@@ -68,7 +68,7 @@ public class ExcelBatchExportServer extends ExcelExportServer {
excelParams.add(indexExcelEntity(entity)); excelParams.add(indexExcelEntity(entity));
} }
// 得到所有字段 // 得到所有字段
Field fileds[] = PoiPublicUtil.getClassFields(pojoClass);
Field[] fileds = PoiPublicUtil.getClassFields(pojoClass);
ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
String targetId = etarget == null ? null : etarget.value(); String targetId = etarget == null ? null : etarget.value();
getAllExcelField(entity.getExclusions(), targetId, fileds, excelParams, pojoClass, getAllExcelField(entity.getExclusions(), targetId, fileds, excelParams, pojoClass,
@@ -104,6 +104,7 @@ public class ExcelBatchExportServer extends ExcelExportServer {
return workbook; return workbook;
} }
@Override
protected void insertDataToSheet(Workbook workbook, ExportParams entity, protected void insertDataToSheet(Workbook workbook, ExportParams entity,
List<ExcelExportEntity> entityList, Collection<?> dataSet, List<ExcelExportEntity> entityList, Collection<?> dataSet,
Sheet sheet) { Sheet sheet) {


+ 5
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportServer.java View File

@@ -34,7 +34,7 @@ import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.export.base.ExportBaseServer;
import cn.afterturn.easypoi.excel.export.base.BaseExportServer;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler; import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
import cn.afterturn.easypoi.exception.excel.ExcelExportException; import cn.afterturn.easypoi.exception.excel.ExcelExportException;
import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum; import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum;
@@ -46,10 +46,10 @@ import cn.afterturn.easypoi.util.PoiPublicUtil;
* *
* @author JueYue 2014年6月17日 下午5:30:54 * @author JueYue 2014年6月17日 下午5:30:54
*/ */
public class ExcelExportServer extends ExportBaseServer {
public class ExcelExportServer extends BaseExportServer {
// 最大行数,超过自动多Sheet // 最大行数,超过自动多Sheet
private int MAX_NUM = 60000;
private static int MAX_NUM = 60000;
protected int createHeaderAndTitle(ExportParams entity, Sheet sheet, Workbook workbook, protected int createHeaderAndTitle(ExportParams entity, Sheet sheet, Workbook workbook,
List<ExcelExportEntity> excelParams) { List<ExcelExportEntity> excelParams) {
@@ -175,8 +175,9 @@ public class ExcelExportServer extends ExportBaseServer {
Object t = its.next(); Object t = its.next();
index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight); index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight);
tempList.add(t); tempList.add(t);
if (index >= MAX_NUM)
if (index >= MAX_NUM) {
break; break;
}
} }
if (entity.getFreezeCol() != 0) { if (entity.getFreezeCol() != 0) {
sheet.createFreezePane(entity.getFreezeCol(), 0, entity.getFreezeCol(), 0); sheet.createFreezePane(entity.getFreezeCol(), 0, entity.getFreezeCol(), 0);


easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportBaseServer.java → easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportServer.java View File

@@ -28,8 +28,6 @@ import org.apache.poi.ss.usermodel.Workbook;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Collection; import java.util.Collection;
@@ -56,7 +54,7 @@ import cn.afterturn.easypoi.util.PoiPublicUtil;
* @author JueYue 2014年6月17日 下午6:15:13 * @author JueYue 2014年6月17日 下午6:15:13
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public abstract class ExportBaseServer extends ExportCommonServer {
public abstract class BaseExportServer extends ExportCommonServer {


private int currentIndex = 0; private int currentIndex = 0;


@@ -100,7 +98,7 @@ public abstract class ExportBaseServer extends ExportCommonServer {
} else { } else {
Object value = getCellValue(entity, t); Object value = getCellValue(entity, t);


if (entity.getType() == BaseEntityTypeConstants.StringType) {
if (entity.getType() == BaseEntityTypeConstants.STRING_TYPE) {
createStringCell(row, cellNum++, value == null ? "" : value.toString(), createStringCell(row, cellNum++, value == null ? "" : value.toString(),
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity),
entity); entity);
@@ -110,7 +108,7 @@ public abstract class ExportBaseServer extends ExportCommonServer {
row.getSheet().getWorkbook().getCreationHelper(), t, row.getSheet().getWorkbook().getCreationHelper(), t,
entity.getName(), value)); entity.getName(), value));
} }
} else if (entity.getType() == BaseEntityTypeConstants.DoubleType) {
} else if (entity.getType() == BaseEntityTypeConstants.DOUBLE_TYPE) {
createDoubleCell(row, cellNum++, value == null ? "" : value.toString(), createDoubleCell(row, cellNum++, value == null ? "" : value.toString(),
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity),
entity); entity);
@@ -193,7 +191,7 @@ public abstract class ExportBaseServer extends ExportCommonServer {
} }


private int createIndexCell(Row row, int index, ExcelExportEntity excelExportEntity) { private int createIndexCell(Row row, int index, ExcelExportEntity excelExportEntity) {
if (excelExportEntity.getName() != null && excelExportEntity.getName().equals("序号") && excelExportEntity.getFormat() != null
if (excelExportEntity.getName() != null && "序号".equals(excelExportEntity.getName()) && excelExportEntity.getFormat() != null
&& excelExportEntity.getFormat().equals(PoiBaseConstants.IS_ADD_INDEX)) { && excelExportEntity.getFormat().equals(PoiBaseConstants.IS_ADD_INDEX)) {
createStringCell(row, 0, currentIndex + "", createStringCell(row, 0, currentIndex + "",
index % 2 == 0 ? getStyles(false, null) : getStyles(true, null), null); index % 2 == 0 ? getStyles(false, null) : getStyles(true, null), null);
@@ -221,7 +219,7 @@ public abstract class ExportBaseServer extends ExportCommonServer {
for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) { for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) {
entity = excelParams.get(k); entity = excelParams.get(k);
Object value = getCellValue(entity, obj); Object value = getCellValue(entity, obj);
if (entity.getType() == BaseEntityTypeConstants.StringType) {
if (entity.getType() == BaseEntityTypeConstants.STRING_TYPE) {
createStringCell(row, cellNum++, value == null ? "" : value.toString(), createStringCell(row, cellNum++, value == null ? "" : value.toString(),
row.getRowNum() % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), row.getRowNum() % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity),
entity); entity);
@@ -231,7 +229,7 @@ public abstract class ExportBaseServer extends ExportCommonServer {
row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(), row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(),
value)); value));
} }
} else if (entity.getType() == BaseEntityTypeConstants.DoubleType) {
} else if (entity.getType() == BaseEntityTypeConstants.DOUBLE_TYPE) {
createDoubleCell(row, cellNum++, value == null ? "" : value.toString(), createDoubleCell(row, cellNum++, value == null ? "" : value.toString(),
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity); index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity);
if (entity.isHyperlink()) { if (entity.isHyperlink()) {
@@ -257,13 +255,13 @@ public abstract class ExportBaseServer extends ExportCommonServer {
cell.setCellValue(Double.parseDouble(text)); cell.setCellValue(Double.parseDouble(text));
cell.setCellType(Cell.CELL_TYPE_NUMERIC); cell.setCellType(Cell.CELL_TYPE_NUMERIC);
} else { } else {
RichTextString Rtext;
RichTextString rtext;
if (type.equals(ExcelType.HSSF)) { if (type.equals(ExcelType.HSSF)) {
Rtext = new HSSFRichTextString(text);
rtext = new HSSFRichTextString(text);
} else { } else {
Rtext = new XSSFRichTextString(text);
rtext = new XSSFRichTextString(text);
} }
cell.setCellValue(Rtext);
cell.setCellValue(rtext);
} }
if (style != null) { if (style != null) {
cell.setCellStyle(style); cell.setCellStyle(style);
@@ -330,9 +328,9 @@ public abstract class ExportBaseServer extends ExportCommonServer {
*/ */
public int getImageType(byte[] value) { public int getImageType(byte[] value) {
String type = PoiPublicUtil.getFileExtendName(value); String type = PoiPublicUtil.getFileExtendName(value);
if (type.equalsIgnoreCase("JPG")) {
if ("JPG".equalsIgnoreCase(type)) {
return Workbook.PICTURE_TYPE_JPEG; return Workbook.PICTURE_TYPE_JPEG;
} else if (type.equalsIgnoreCase("PNG")) {
} else if ("PNG".equalsIgnoreCase(type)) {
return Workbook.PICTURE_TYPE_PNG; return Workbook.PICTURE_TYPE_PNG;
} }



+ 4
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java View File

@@ -47,7 +47,7 @@ import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams; import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams;
import cn.afterturn.easypoi.excel.export.base.ExportBaseServer;
import cn.afterturn.easypoi.excel.export.base.BaseExportServer;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler; import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
import cn.afterturn.easypoi.excel.export.template.TemplateSumHanlder.TemplateSumEntity; import cn.afterturn.easypoi.excel.export.template.TemplateSumHanlder.TemplateSumEntity;
import cn.afterturn.easypoi.excel.html.helper.MergedRegionHelper; import cn.afterturn.easypoi.excel.html.helper.MergedRegionHelper;
@@ -64,7 +64,7 @@ import cn.afterturn.easypoi.util.PoiSheetUtility;
* 2013-10-17 * 2013-10-17
* @version 1.0 * @version 1.0
*/ */
public final class ExcelExportOfTemplateUtil extends ExportBaseServer {
public final class ExcelExportOfTemplateUtil extends BaseExportServer {
private static final Logger LOGGER = LoggerFactory private static final Logger LOGGER = LoggerFactory
.getLogger(ExcelExportOfTemplateUtil.class); .getLogger(ExcelExportOfTemplateUtil.class);
@@ -517,8 +517,9 @@ public final class ExcelExportOfTemplateUtil extends ExportBaseServer {
: getStyles(true, : getStyles(true,
size >= j - columnIndex ? null : columns.get(j - columnIndex)); size >= j - columnIndex ? null : columns.get(j - columnIndex));
//返回的styler不为空时才使用,否则使用Excel设置的,更加推荐Excel设置的样式 //返回的styler不为空时才使用,否则使用Excel设置的,更加推荐Excel设置的样式
if (style != null)
if (style != null) {
row.getCell(j).setCellStyle(style); row.getCell(j).setCellStyle(style);
}
} }
} }


+ 2
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/TemplateSumHanlder.java View File

@@ -78,8 +78,9 @@ public class TemplateSumHanlder {
} }
public void addValueOfKey(String key, String val) { public void addValueOfKey(String key, String val) {
if (StringUtils.isNoneEmpty(key))
if (StringUtils.isNoneEmpty(key)) {
sumMap.get(key).setValue(sumMap.get(key).getValue() + Double.valueOf(val)); sumMap.get(key).setValue(sumMap.get(key).getValue() + Double.valueOf(val));
}
} }
public List<TemplateSumEntity> getDataList() { public List<TemplateSumEntity> getDataList() {


+ 7
- 7
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/builder/ExcelChartBuildService.java View File

@@ -88,7 +88,7 @@ public class ExcelChartBuildService
ExcelGraphElement categoryElement=graph.getCategory(); ExcelGraphElement categoryElement=graph.getCategory();
ChartDataSource categoryChart; ChartDataSource categoryChart;
if(categoryElement!=null&&categoryElement.getElementType()==ExcelGraphElementType.StringType){
if(categoryElement!=null&& categoryElement.getElementType().equals(ExcelGraphElementType.STRING_TYPE)){
categoryChart=DataSources.fromStringCellRange(dataSourceSheet, new CellRangeAddress(categoryElement.getStartRowNum(),categoryElement.getEndRowNum(),categoryElement.getStartColNum(),categoryElement.getEndColNum())); categoryChart=DataSources.fromStringCellRange(dataSourceSheet, new CellRangeAddress(categoryElement.getStartRowNum(),categoryElement.getEndRowNum(),categoryElement.getStartColNum(),categoryElement.getEndColNum()));
}else{ }else{
categoryChart=DataSources.fromNumericCellRange(dataSourceSheet, new CellRangeAddress(categoryElement.getStartRowNum(),categoryElement.getEndRowNum(),categoryElement.getStartColNum(),categoryElement.getEndColNum())); categoryChart=DataSources.fromNumericCellRange(dataSourceSheet, new CellRangeAddress(categoryElement.getStartRowNum(),categoryElement.getEndRowNum(),categoryElement.getStartColNum(),categoryElement.getEndColNum()));
@@ -103,7 +103,7 @@ public class ExcelChartBuildService
} }
} }
if(graph.getGraphType()==ExcelGraphType.LineChart){
if(graph.getGraphType().equals(ExcelGraphType.LINE_CHART)){
LineChartData data = chart.getChartDataFactory().createLineChartData(); LineChartData data = chart.getChartDataFactory().createLineChartData();
buildLineChartData(data, categoryChart, chartValueList, graph.getTitle()); buildLineChartData(data, categoryChart, chartValueList, graph.getTitle());
chart.plot(data, bottomAxis, leftAxis); chart.plot(data, bottomAxis, leftAxis);
@@ -220,8 +220,8 @@ public class ExcelChartBuildService
{ {
int i=0; int i=0;
for(ChartDataSource<Number> source:chartValueList){ for(ChartDataSource<Number> source:chartValueList){
String _title=title.get(i);
if(StringUtils.isNotBlank(_title)){
String temp_title=title.get(i);
if(StringUtils.isNotBlank(temp_title)){
//data.addSerie(categoryChart, source).setTitle(_title); //data.addSerie(categoryChart, source).setTitle(_title);
}else{ }else{
//data.addSerie(categoryChart, source); //data.addSerie(categoryChart, source);
@@ -249,9 +249,9 @@ public class ExcelChartBuildService
{ {
int i=0; int i=0;
for(ChartDataSource<Number> source:chartValueList){ for(ChartDataSource<Number> source:chartValueList){
String _title=title.get(i);
if(StringUtils.isNotBlank(_title)){
data.addSerie(categoryChart, source).setTitle(_title);
String temp_title=title.get(i);
if(StringUtils.isNotBlank(temp_title)){
data.addSerie(categoryChart, source).setTitle(temp_title);
}else{ }else{
data.addSerie(categoryChart, source); data.addSerie(categoryChart, source);
} }


+ 2
- 2
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/constant/ExcelGraphElementType.java View File

@@ -11,6 +11,6 @@ package cn.afterturn.easypoi.excel.graph.constant;
*/ */
public interface ExcelGraphElementType public interface ExcelGraphElementType
{ {
public static final Integer StringType=1;
public static final Integer NumericType=2;
public static final Integer STRING_TYPE =1;
public static final Integer NUMERIC_TYPE =2;
} }

+ 2
- 2
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/constant/ExcelGraphType.java View File

@@ -11,7 +11,7 @@ package cn.afterturn.easypoi.excel.graph.constant;
*/ */
public interface ExcelGraphType public interface ExcelGraphType
{ {
public static final Integer LineChart=1;
public static final Integer ScatterChart=2;
public static final Integer LINE_CHART =1;
public static final Integer SCATTER_CHART =2;
} }

+ 11
- 6
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraphDefined.java View File

@@ -20,10 +20,11 @@ public class ExcelGraphDefined implements ExcelGraph
private ExcelGraphElement category; private ExcelGraphElement category;
public List<ExcelGraphElement> valueList=Lists.newArrayList(); public List<ExcelGraphElement> valueList=Lists.newArrayList();
public List<ExcelTitleCell> titleCell=Lists.newArrayList(); public List<ExcelTitleCell> titleCell=Lists.newArrayList();
private Integer graphType=ExcelGraphType.LineChart;
private Integer graphType=ExcelGraphType.LINE_CHART;
public List<String> title=Lists.newArrayList(); public List<String> title=Lists.newArrayList();
public ExcelGraphElement getCategory()
@Override
public ExcelGraphElement getCategory()
{ {
return category; return category;
} }
@@ -31,7 +32,8 @@ public class ExcelGraphDefined implements ExcelGraph
{ {
this.category = category; this.category = category;
} }
public List<ExcelGraphElement> getValueList()
@Override
public List<ExcelGraphElement> getValueList()
{ {
return valueList; return valueList;
} }
@@ -40,7 +42,8 @@ public class ExcelGraphDefined implements ExcelGraph
this.valueList = valueList; this.valueList = valueList;
} }


public Integer getGraphType()
@Override
public Integer getGraphType()
{ {
return graphType; return graphType;
} }
@@ -48,7 +51,8 @@ public class ExcelGraphDefined implements ExcelGraph
{ {
this.graphType = graphType; this.graphType = graphType;
} }
public List<ExcelTitleCell> getTitleCell()
@Override
public List<ExcelTitleCell> getTitleCell()
{ {
return titleCell; return titleCell;
} }
@@ -56,7 +60,8 @@ public class ExcelGraphDefined implements ExcelGraph
{ {
this.titleCell = titleCell; this.titleCell = titleCell;
} }
public List<String> getTitle()
@Override
public List<String> getTitle()
{ {
return title; return title;
} }


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraphElement.java View File

@@ -18,7 +18,7 @@ public class ExcelGraphElement
private Integer endRowNum; private Integer endRowNum;
private Integer startColNum; private Integer startColNum;
private Integer endColNum; private Integer endColNum;
private Integer elementType=ExcelGraphElementType.StringType;
private Integer elementType=ExcelGraphElementType.STRING_TYPE;
public Integer getStartRowNum() public Integer getStartRowNum()


+ 9
- 5
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/ExcelToHtmlServer.java View File

@@ -71,7 +71,7 @@ public class ExcelToHtmlServer {
this.sheetNum = params.getSheetNum(); this.sheetNum = params.getSheetNum();
cssRandom = (int) Math.ceil(Math.random() * 1000); cssRandom = (int) Math.ceil(Math.random() * 1000);
this.imageCachePath = params.getPath(); this.imageCachePath = params.getPath();
today = DATE_FORMAT.format(new Date());
today = new SimpleDateFormat("yyyy_MM_dd").format(new Date());
} }
public String printPage() { public String printPage() {
@@ -101,8 +101,9 @@ public class ExcelToHtmlServer {
} catch (Exception e) { } catch (Exception e) {
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);
} finally { } finally {
if (out != null)
if (out != null) {
out.close(); out.close();
}
} }
return null; return null;
} }
@@ -125,8 +126,9 @@ public class ExcelToHtmlServer {
} }
private void ensureOut() { private void ensureOut() {
if (out == null)
if (out == null) {
out = new Formatter(new StringBuilder()); out = new Formatter(new StringBuilder());
}
} }
private void printSheets() { private void printSheets() {
@@ -159,8 +161,9 @@ public class ExcelToHtmlServer {
} }
private void ensureColumnBounds(Sheet sheet) { private void ensureColumnBounds(Sheet sheet) {
if (gotBounds)
if (gotBounds) {
return; return;
}
Iterator<Row> iter = sheet.rowIterator(); Iterator<Row> iter = sheet.rowIterator();
firstColumn = (iter.hasNext() ? Integer.MAX_VALUE : 0); firstColumn = (iter.hasNext() ? Integer.MAX_VALUE : 0);
@@ -301,8 +304,9 @@ public class ExcelToHtmlServer {
} }
private String styleName(CellStyle style) { private String styleName(CellStyle style) {
if (style == null)
if (style == null) {
return ""; return "";
}
return String.format("style_%02x_%s font_%s_%s", style.getIndex(), cssRandom, return String.format("style_%02x_%s font_%s_%s", style.getIndex(), cssRandom,
style.getFontIndex(), cssRandom); style.getFontIndex(), cssRandom);
} }


+ 5
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/css/CssParseServer.java View File

@@ -28,6 +28,9 @@ public class CssParseServer {
private static final Logger log = LoggerFactory.getLogger(CssParseServer.class); private static final Logger log = LoggerFactory.getLogger(CssParseServer.class);
private static final Pattern STYLE_PATTERN = Pattern.compile("(?:^|\\s+)(italic|oblique)(?:\\s+|$)");
private static final Pattern WEIGHT_PATTERN = Pattern.compile("(?:^|\\s+)(bold(?:er)?|[7-9]00)(?:\\s+|$)");
@SuppressWarnings("serial") @SuppressWarnings("serial")
private final static Set<String> BORDER_STYLES = new HashSet<String>() { private final static Set<String> BORDER_STYLES = new HashSet<String>() {
{ {
@@ -193,8 +196,7 @@ public class CssParseServer {
font.replaceAll("^|\\s*" + StringUtils.join(ignoreStyles, "|") + "\\s+|$", " ")); font.replaceAll("^|\\s*" + StringUtils.join(ignoreStyles, "|") + "\\s+|$", " "));
log.debug("Font Attr [{}] After Process Ingore.", sbFont); log.debug("Font Attr [{}] After Process Ingore.", sbFont);
// style // style
Matcher m = Pattern.compile("(?:^|\\s+)(italic|oblique)(?:\\s+|$)")
.matcher(sbFont.toString());
Matcher m = STYLE_PATTERN.matcher(sbFont.toString());
if (m.find()) { if (m.find()) {
sbFont.setLength(0); sbFont.setLength(0);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@@ -205,8 +207,7 @@ public class CssParseServer {
m.appendTail(sbFont); m.appendTail(sbFont);
} }
// weight // weight
m = Pattern.compile("(?:^|\\s+)(bold(?:er)?|[7-9]00)(?:\\s+|$)")
.matcher(sbFont.toString());
m = WEIGHT_PATTERN.matcher(sbFont.toString());
if (m.find()) { if (m.find()) {
sbFont.setLength(0); sbFont.setLength(0);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {


+ 5
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/helper/CellValueHelper.java View File

@@ -31,14 +31,15 @@ public class CellValueHelper {
public CellValueHelper(Workbook wb, int cssRandom) { public CellValueHelper(Workbook wb, int cssRandom) {
this.cssRandom = cssRandom; this.cssRandom = cssRandom;
if (wb instanceof HSSFWorkbook)
if (wb instanceof HSSFWorkbook) {
is07 = false; is07 = false;
else if (wb instanceof XSSFWorkbook) {
}else if (wb instanceof XSSFWorkbook) {
is07 = true; is07 = true;
cacheFontInfo(wb); cacheFontInfo(wb);
} else
} else {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"unknown workbook type: " + wb.getClass().getSimpleName());
"unknown workbook type: " + wb.getClass().getSimpleName());
}
} }
/** /**


+ 19
- 10
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/helper/StylerHelper.java View File

@@ -69,13 +69,14 @@ public class StylerHelper {
this.out = out; this.out = out;
this.sheetNum = sheetNum; this.sheetNum = sheetNum;
this.cssRandom = cssRandom; this.cssRandom = cssRandom;
if (wb instanceof HSSFWorkbook)
if (wb instanceof HSSFWorkbook) {
helper = new HSSFHtmlHelper((HSSFWorkbook) wb); helper = new HSSFHtmlHelper((HSSFWorkbook) wb);
else if (wb instanceof XSSFWorkbook)
} else if (wb instanceof XSSFWorkbook) {
helper = new XSSFHtmlHelper((XSSFWorkbook) wb); helper = new XSSFHtmlHelper((XSSFWorkbook) wb);
else
} else {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"unknown workbook type: " + wb.getClass().getSimpleName());
"unknown workbook type: " + wb.getClass().getSimpleName());
}
printInlineStyle(wb); printInlineStyle(wb);
} }
@@ -157,10 +158,12 @@ public class StylerHelper {
} }
private void fontStyle(Font font) { private void fontStyle(Font font) {
if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD)
if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD) {
out.format(" font-weight: bold;%n"); out.format(" font-weight: bold;%n");
if (font.getItalic())
}
if (font.getItalic()) {
out.format(" font-style: italic;%n"); out.format(" font-style: italic;%n");
}
out.format(" font-family: %s;%n", font.getFontName()); out.format(" font-family: %s;%n", font.getFontName());
int fontheight = font.getFontHeightInPoints(); int fontheight = font.getFontHeightInPoints();
@@ -181,8 +184,9 @@ public class StylerHelper {
} }
private String styleName(CellStyle style) { private String styleName(CellStyle style) {
if (style == null)
if (style == null) {
return ""; return "";
}
return String.format("style_%02x_%s", style.getIndex(), cssRandom); return String.format("style_%02x_%s", style.getIndex(), cssRandom);
} }
@@ -209,13 +213,14 @@ public class StylerHelper {
private final HSSFWorkbook wb; private final HSSFWorkbook wb;
private final HSSFPalette colors; private final HSSFPalette colors;
private HSSFColor HSSF_AUTO = new HSSFColor.AUTOMATIC();
private HSSFColor hssfAuto = new HSSFColor.AUTOMATIC();
public HSSFHtmlHelper(HSSFWorkbook wb) { public HSSFHtmlHelper(HSSFWorkbook wb) {
this.wb = wb; this.wb = wb;
colors = wb.getCustomPalette(); colors = wb.getCustomPalette();
} }
@Override
public void colorStyles(CellStyle style, Formatter out) { public void colorStyles(CellStyle style, Formatter out) {
HSSFCellStyle cs = (HSSFCellStyle) style; HSSFCellStyle cs = (HSSFCellStyle) style;
out.format(" /* fill pattern = %d */%n", cs.getFillPattern()); out.format(" /* fill pattern = %d */%n", cs.getFillPattern());
@@ -225,7 +230,7 @@ public class StylerHelper {
private void styleColor(Formatter out, String attr, short index) { private void styleColor(Formatter out, String attr, short index) {
HSSFColor color = colors.getColor(index); HSSFColor color = colors.getColor(index);
if (index == HSSF_AUTO.getIndex() || color == null) {
if (index == hssfAuto.getIndex() || color == null) {
out.format(" /* %s: index = %d */%n", attr, index); out.format(" /* %s: index = %d */%n", attr, index);
} else { } else {
short[] rgb = color.getTriplet(); short[] rgb = color.getTriplet();
@@ -234,6 +239,7 @@ public class StylerHelper {
} }
} }
@Override
public void styleColor(Formatter out, String attr, Color color) { public void styleColor(Formatter out, String attr, Color color) {
if (color == null) { if (color == null) {
return; return;
@@ -254,16 +260,19 @@ public class StylerHelper {
public XSSFHtmlHelper(XSSFWorkbook wb) { public XSSFHtmlHelper(XSSFWorkbook wb) {
} }
@Override
public void colorStyles(CellStyle style, Formatter out) { public void colorStyles(CellStyle style, Formatter out) {
XSSFCellStyle cs = (XSSFCellStyle) style; XSSFCellStyle cs = (XSSFCellStyle) style;
styleColor(out, "background-color", cs.getFillForegroundXSSFColor()); styleColor(out, "background-color", cs.getFillForegroundXSSFColor());
styleColor(out, "color", cs.getFont().getXSSFColor()); styleColor(out, "color", cs.getFont().getXSSFColor());
} }
@Override
public void styleColor(Formatter out, String attr, Color color) { public void styleColor(Formatter out, String attr, Color color) {
XSSFColor xSSFColor = (XSSFColor) color; XSSFColor xSSFColor = (XSSFColor) color;
if (color == null || xSSFColor.isAuto())
if (color == null || xSSFColor.isAuto()) {
return; return;
}
byte[] rgb = xSSFColor.getRGB(); byte[] rgb = xSSFColor.getRGB();
if (rgb == null) { if (rgb == null) {


+ 8
- 7
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java View File

@@ -142,7 +142,7 @@ public class ExcelImportServer extends ImportBaseService {
*/ */
private String getSaveUrl(ExcelImportEntity excelImportEntity, Object object) throws Exception { private String getSaveUrl(ExcelImportEntity excelImportEntity, Object object) throws Exception {
String url = ""; String url = "";
if (excelImportEntity.getSaveUrl().equals("upload")) {
if ("upload".equals(excelImportEntity.getSaveUrl())) {
if (excelImportEntity.getMethods() != null if (excelImportEntity.getMethods() != null
&& excelImportEntity.getMethods().size() > 0) { && excelImportEntity.getMethods().size() > 0) {
object = getFieldBySomeMethod(excelImportEntity.getMethods(), object); object = getFieldBySomeMethod(excelImportEntity.getMethods(), object);
@@ -162,7 +162,7 @@ public class ExcelImportServer extends ImportBaseService {
List<ExcelCollectionParams> excelCollection = new ArrayList<ExcelCollectionParams>(); List<ExcelCollectionParams> excelCollection = new ArrayList<ExcelCollectionParams>();
String targetId = null; String targetId = null;
if (!Map.class.equals(pojoClass)) { if (!Map.class.equals(pojoClass)) {
Field fileds[] = PoiPublicUtil.getClassFields(pojoClass);
Field[] fileds = PoiPublicUtil.getClassFields(pojoClass);
ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
if (etarget != null) { if (etarget != null) {
targetId = etarget.value(); targetId = etarget.value();
@@ -267,8 +267,9 @@ public class ExcelImportServer extends ImportBaseService {
if (params.getVerifyHanlder() != null) { if (params.getVerifyHanlder() != null) {
ExcelVerifyHanlderResult result = params.getVerifyHanlder().verifyHandler(object); ExcelVerifyHanlderResult result = params.getVerifyHanlder().verifyHandler(object);
if (!result.isSuccess()) { if (!result.isSuccess()) {
if (cell == null)
if (cell == null) {
cell = row.createCell(row.getLastCellNum()); cell = row.createCell(row.getLastCellNum());
}
cell.setCellValue((StringUtils.isNoneBlank(cell.getStringCellValue()) cell.setCellValue((StringUtils.isNoneBlank(cell.getStringCellValue())
? cell.getStringCellValue() + "," : "") + result.getMsg()); ? cell.getStringCellValue() + "," : "") + result.getMsg());
if (object instanceof IExcelModel) { if (object instanceof IExcelModel) {
@@ -372,7 +373,7 @@ public class ExcelImportServer extends ImportBaseService {
for (int i = params.getStartSheetIndex(); i < params.getStartSheetIndex() for (int i = params.getStartSheetIndex(); i < params.getStartSheetIndex()
+ params.getSheetNum(); i++) { + params.getSheetNum(); i++) {
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" start to read excel by is ,startTime is {}", new Date().getTime());
LOGGER.debug(" start to read excel by is ,startTime is {}", System.currentTimeMillis());
} }
if (isXSSFWorkbook) { if (isXSSFWorkbook) {
pictures = PoiPublicUtil.getSheetPictrues07((XSSFSheet) book.getSheetAt(i), pictures = PoiPublicUtil.getSheetPictrues07((XSSFSheet) book.getSheetAt(i),
@@ -382,16 +383,16 @@ public class ExcelImportServer extends ImportBaseService {
(HSSFWorkbook) book); (HSSFWorkbook) book);
} }
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" end to read excel by is ,endTime is {}", new Date().getTime());
LOGGER.debug(" end to read excel by is ,endTime is {}", System.currentTimeMillis());
} }
result.addAll(importExcel(result, book.getSheetAt(i), pojoClass, params, pictures)); result.addAll(importExcel(result, book.getSheetAt(i), pojoClass, params, pictures));
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" end to read excel list by pos ,endTime is {}", new Date().getTime());
LOGGER.debug(" end to read excel list by pos ,endTime is {}", System.currentTimeMillis());
} }
if (params.isReadSingleCell()) { if (params.isReadSingleCell()) {
readSingleCell(importResult, book.getSheetAt(i), params); readSingleCell(importResult, book.getSheetAt(i), params);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" read Key-Value ,endTime is {}", new Date().getTime());
LOGGER.debug(" read Key-Value ,endTime is {}", System.currentTimeMillis());
} }
} }
} }


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java View File

@@ -222,7 +222,7 @@ public class ImportBaseService {
*/ */
public String getSaveExcelUrl(ImportParams params, Class<?> pojoClass) throws Exception { public String getSaveExcelUrl(ImportParams params, Class<?> pojoClass) throws Exception {
String url = ""; String url = "";
if (params.getSaveUrl().equals("upload/excelUpload")) {
if ("upload/excelUpload".equals(params.getSaveUrl())) {
url = pojoClass.getName().split("\\.")[pojoClass.getName().split("\\.").length - 1]; url = pojoClass.getName().split("\\.")[pojoClass.getName().split("\\.").length - 1];
return params.getSaveUrl() + "/" + url; return params.getSaveUrl() + "/" + url;
} }


+ 2
- 2
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/SheetHandler.java View File

@@ -108,7 +108,7 @@ public class SheetHandler extends DefaultHandler {
// 将单元格内容加入rowlist中,在这之前先去掉字符串前后的空白符 // 将单元格内容加入rowlist中,在这之前先去掉字符串前后的空白符
} else if ("v".equals(name)) { } else if ("v".equals(name)) {
String value = lastContents.trim(); String value = lastContents.trim();
value = value.equals("") ? " " : value;
value = "".equals(value) ? " " : value;
if (CellValueType.Date.equals(type)) { if (CellValueType.Date.equals(type)) {
Date date = HSSFDateUtil.getJavaDate(Double.valueOf(value)); Date date = HSSFDateUtil.getJavaDate(Double.valueOf(value));
rowlist.add(curCol, new SaxReadCellEntity(CellValueType.Date, date)); rowlist.add(curCol, new SaxReadCellEntity(CellValueType.Date, date));
@@ -119,7 +119,7 @@ public class SheetHandler extends DefaultHandler {
rowlist.add(curCol, new SaxReadCellEntity(CellValueType.String, value)); rowlist.add(curCol, new SaxReadCellEntity(CellValueType.String, value));
} }
curCol++; curCol++;
} else if (name.equals("row")) {//如果标签名称为 row ,这说明已到行尾,调用 optRows() 方法
} else if ("row".equals(name)) {//如果标签名称为 row ,这说明已到行尾,调用 optRows() 方法
read.parse(curRow, rowlist); read.parse(curRow, rowlist);
rowlist.clear(); rowlist.clear();
curRow++; curRow++;


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/parse/SaxRowRead.java View File

@@ -83,7 +83,7 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead {
private void initParams(Class<?> pojoClass, ImportParams params) { private void initParams(Class<?> pojoClass, ImportParams params) {
try { try {
Field fileds[] = PoiPublicUtil.getClassFields(pojoClass);
Field[] fileds = PoiPublicUtil.getClassFields(pojoClass);
ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
if (etarget != null) { if (etarget != null) {
targetId = etarget.value(); targetId = etarget.value();


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/pdf/export/PdfExportServer.java View File

@@ -87,7 +87,7 @@ public class PdfExportServer extends ExportCommonServer {
//excelParams.add(indexExcelEntity(entity)); //excelParams.add(indexExcelEntity(entity));
} }
// 得到所有字段 // 得到所有字段
Field fileds[] = PoiPublicUtil.getClassFields(pojoClass);
Field[] fileds = PoiPublicUtil.getClassFields(pojoClass);
ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
String targetId = etarget == null ? null : etarget.value(); String targetId = etarget == null ? null : etarget.value();
getAllExcelField(entity.getExclusions(), targetId, fileds, excelParams, pojoClass, getAllExcelField(entity.getExclusions(), targetId, fileds, excelParams, pojoClass,


+ 2
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCellUtil.java View File

@@ -100,8 +100,9 @@ public class PoiCellUtil {
* @return * @return
*/ */
public static String getCellValue(Cell cell) { public static String getCellValue(Cell cell) {
if (cell == null)
if (cell == null) {
return ""; return "";
}


if (cell.getCellType() == Cell.CELL_TYPE_STRING) { if (cell.getCellType() == Cell.CELL_TYPE_STRING) {




+ 8
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCssUtils.java View File

@@ -27,6 +27,11 @@ public class PoiCssUtils {
private static final String COLOR_PATTERN_VALUE_LONG = "^(#(?:[a-f]|\\d{2}){3})$"; private static final String COLOR_PATTERN_VALUE_LONG = "^(#(?:[a-f]|\\d{2}){3})$";
// matches #rgb(r, g, b) // matches #rgb(r, g, b)
private static final String COLOR_PATTERN_RGB = "^(rgb\\s*\\(\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*\\))$"; private static final String COLOR_PATTERN_RGB = "^(rgb\\s*\\(\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*\\))$";

private static final Pattern COLOR_PATTERN_VALUE_SHORT_PATTERN = Pattern.compile("([a-f]|\\d)");
private static final Pattern INT_PATTERN = Pattern.compile("^(\\d+)(?:\\w+|%)?$");
private static final Pattern INT_AND_PER_PATTERN = Pattern.compile("^(\\d*\\.?\\d+)\\s*(%)?$");

// color name -> POI Color // color name -> POI Color
private static Map<String, HSSFColor> colors = new HashMap<String, HSSFColor>(); private static Map<String, HSSFColor> colors = new HashMap<String, HSSFColor>();
// static init // static init
@@ -67,7 +72,7 @@ public class PoiCssUtils {
public static int getInt(String strValue) { public static int getInt(String strValue) {
int value = 0; int value = 0;
if (StringUtils.isNotBlank(strValue)) { if (StringUtils.isNotBlank(strValue)) {
Matcher m = Pattern.compile("^(\\d+)(?:\\w+|%)?$").matcher(strValue);
Matcher m = INT_PATTERN.matcher(strValue);
if (m.find()) { if (m.find()) {
value = Integer.parseInt(m.group(1)); value = Integer.parseInt(m.group(1));
} }
@@ -98,7 +103,7 @@ public class PoiCssUtils {
if (color.matches(COLOR_PATTERN_VALUE_SHORT)) { if (color.matches(COLOR_PATTERN_VALUE_SHORT)) {
log.debug("Short Hex Color [{}] Found.", color); log.debug("Short Hex Color [{}] Found.", color);
StringBuffer sbColor = new StringBuffer(); StringBuffer sbColor = new StringBuffer();
Matcher m = Pattern.compile("([a-f]|\\d)").matcher(color);
Matcher m = COLOR_PATTERN_VALUE_SHORT_PATTERN.matcher(color);
while (m.find()) { while (m.find()) {
m.appendReplacement(sbColor, "$1$1"); m.appendReplacement(sbColor, "$1$1");
} }
@@ -180,7 +185,7 @@ public class PoiCssUtils {
public static int calcColorValue(String color) { public static int calcColorValue(String color) {
int rtn = 0; int rtn = 0;
// matches 64 or 64% // matches 64 or 64%
Matcher m = Pattern.compile("^(\\d*\\.?\\d+)\\s*(%)?$").matcher(color);
Matcher m = INT_AND_PER_PATTERN.matcher(color);
if (m.matches()) { if (m.matches()) {
// % not found // % not found
if (m.group(2) == null) { if (m.group(2) == null) {


+ 3
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiFunctionUtil.java View File

@@ -103,11 +103,11 @@ public final class PoiFunctionUtil {
} }
SimpleDateFormat dateFormat = null; SimpleDateFormat dateFormat = null;
if (DAY_STR.equals(format)) { if (DAY_STR.equals(format)) {
dateFormat = DAY_FORMAT;
dateFormat = new SimpleDateFormat(DAY_STR);
} else if (TIME_STR.equals(format)) { } else if (TIME_STR.equals(format)) {
dateFormat = TIME_FORMAT;
dateFormat = new SimpleDateFormat(TIME_STR);
} else if (TIME__NO_S_STR.equals(format)) { } else if (TIME__NO_S_STR.equals(format)) {
dateFormat = TIME__NO_S_FORMAT;
dateFormat = new SimpleDateFormat(TIME__NO_S_STR);
} else { } else {
dateFormat = new SimpleDateFormat(format); dateFormat = new SimpleDateFormat(format);
} }


+ 9
- 9
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiPublicUtil.java View File

@@ -251,10 +251,10 @@ public final class PoiPublicUtil {
if (fieldType.isArray()) { if (fieldType.isArray()) {
isBaseClass = false; isBaseClass = false;
} else if (fieldType.isPrimitive() || fieldType.getPackage() == null } else if (fieldType.isPrimitive() || fieldType.getPackage() == null
|| fieldType.getPackage().getName().equals("java.lang")
|| fieldType.getPackage().getName().equals("java.math")
|| fieldType.getPackage().getName().equals("java.sql")
|| fieldType.getPackage().getName().equals("java.util")) {
|| "java.lang".equals(fieldType.getPackage().getName())
|| "java.math".equals(fieldType.getPackage().getName())
|| "java.sql".equals(fieldType.getPackage().getName())
|| "java.util".equals(fieldType.getPackage().getName())) {
isBaseClass = true; isBaseClass = true;
} }
return isBaseClass; return isBaseClass;
@@ -300,21 +300,21 @@ public final class PoiPublicUtil {
* @return * @return
*/ */
private static boolean isUseInThis(String exportName, String targetId) { private static boolean isUseInThis(String exportName, String targetId) {
return targetId == null || exportName.equals("") || exportName.indexOf("_") < 0
return targetId == null || "".equals(exportName) || exportName.indexOf("_") < 0
|| exportName.indexOf(targetId) != -1; || exportName.indexOf(targetId) != -1;
} }
private static Integer getImageType(String type) { private static Integer getImageType(String type) {
if (type.equalsIgnoreCase("JPG") || type.equalsIgnoreCase("JPEG")) {
if ("JPG".equalsIgnoreCase(type) || "JPEG".equalsIgnoreCase(type)) {
return XWPFDocument.PICTURE_TYPE_JPEG; return XWPFDocument.PICTURE_TYPE_JPEG;
} }
if (type.equalsIgnoreCase("GIF")) {
if ("GIF".equalsIgnoreCase(type)) {
return XWPFDocument.PICTURE_TYPE_GIF; return XWPFDocument.PICTURE_TYPE_GIF;
} }
if (type.equalsIgnoreCase("BMP")) {
if ("BMP".equalsIgnoreCase(type)) {
return XWPFDocument.PICTURE_TYPE_GIF; return XWPFDocument.PICTURE_TYPE_GIF;
} }
if (type.equalsIgnoreCase("PNG")) {
if ("PNG".equalsIgnoreCase(type)) {
return XWPFDocument.PICTURE_TYPE_PNG; return XWPFDocument.PICTURE_TYPE_PNG;
} }
return XWPFDocument.PICTURE_TYPE_JPEG; return XWPFDocument.PICTURE_TYPE_JPEG;


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiReflectorUtil.java View File

@@ -196,7 +196,7 @@ public final class PoiReflectorUtil {
// Ignored. This is only a final precaution, nothing we can do. // Ignored. This is only a final precaution, nothing we can do.
} }
} }
if (field.isAccessible() && !field.getName().equalsIgnoreCase("serialVersionUID")) {
if (field.isAccessible() && !"serialVersionUID".equalsIgnoreCase(field.getName())) {
this.fieldList.add(field); this.fieldList.add(field);
} }
} }


+ 10
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiSheetUtility.java View File

@@ -40,21 +40,25 @@ public class PoiSheetUtility extends Object {
Row row = sheet.getRow(r); Row row = sheet.getRow(r);
// if no row exists here; then nothing to do; next! // if no row exists here; then nothing to do; next!
if (row == null)
if (row == null) {
continue; continue;
}
// if the row doesn't have this many columns then we are good; next! // if the row doesn't have this many columns then we are good; next!
int lastColumn = row.getLastCellNum(); int lastColumn = row.getLastCellNum();
if (lastColumn > maxColumn)
if (lastColumn > maxColumn) {
maxColumn = lastColumn; maxColumn = lastColumn;
}
if (lastColumn < columnToDelete)
if (lastColumn < columnToDelete) {
continue; continue;
}
for (int x = columnToDelete + 1; x < lastColumn + 1; x++) { for (int x = columnToDelete + 1; x < lastColumn + 1; x++) {
Cell oldCell = row.getCell(x - 1); Cell oldCell = row.getCell(x - 1);
if (oldCell != null)
if (oldCell != null) {
row.removeCell(oldCell); row.removeCell(oldCell);
}
Cell nextCell = row.getCell(x); Cell nextCell = row.getCell(x);
if (nextCell != null) { if (nextCell != null) {
@@ -99,6 +103,8 @@ public class PoiSheetUtility extends Object {
cNew.setCellFormula(cOld.getCellFormula()); cNew.setCellFormula(cOld.getCellFormula());
break; break;
} }
default:
cNew.setCellValue(cOld.getStringCellValue());
} }
} }

+ 4
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.java View File

@@ -29,19 +29,19 @@ import javax.validation.ValidatorFactory;
*/ */
public class PoiValidationUtil { public class PoiValidationUtil {
private final static Validator validator;
private final static Validator VALIDATOR;
static { static {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
VALIDATOR = factory.getValidator();
} }
public static String validation(Object obj, Class[] verfiyGroup) { public static String validation(Object obj, Class[] verfiyGroup) {
Set<ConstraintViolation<Object>> set = null; Set<ConstraintViolation<Object>> set = null;
if(verfiyGroup != null){ if(verfiyGroup != null){
set = validator.validate(obj,verfiyGroup);
set = VALIDATOR.validate(obj,verfiyGroup);
}else{ }else{
set = validator.validate(obj);
set = VALIDATOR.validate(obj);
} }
if (set!= null && set.size() > 0) { if (set!= null && set.size() > 0) {
return getValidateErrMsg(set); return getValidateErrMsg(set);


+ 6
- 6
easypoi-base/src/main/java/cn/afterturn/easypoi/word/entity/MyXWPFDocument.java View File

@@ -73,9 +73,9 @@ public class MyXWPFDocument extends XWPFDocument {
} }
public void createPicture(String blipId, int id, int width, int height) { public void createPicture(String blipId, int id, int width, int height) {
final int EMU = 9525;
width *= EMU;
height *= EMU;
final int emu = 9525;
width *= emu;
height *= emu;
CTInline inline = createParagraph().createRun().getCTR().addNewDrawing().addNewInline(); CTInline inline = createParagraph().createRun().getCTR().addNewDrawing().addNewInline();
String picXml = String.format(PICXML, id, blipId, width, height); String picXml = String.format(PICXML, id, blipId, width, height);
XmlToken xmlToken = null; XmlToken xmlToken = null;
@@ -102,9 +102,9 @@ public class MyXWPFDocument extends XWPFDocument {
} }
public void createPicture(XWPFRun run, String blipId, int id, int width, int height) { public void createPicture(XWPFRun run, String blipId, int id, int width, int height) {
final int EMU = 9525;
width *= EMU;
height *= EMU;
final int emu = 9525;
width *= emu;
height *= emu;
CTInline inline = run.getCTR().addNewDrawing().addNewInline(); CTInline inline = run.getCTR().addNewDrawing().addNewInline();
String picXml = String.format(PICXML, id, blipId, width, height); String picXml = String.format(PICXML, id, blipId, width, height);
XmlToken xmlToken = null; XmlToken xmlToken = null;


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/word/parse/excel/ExcelEntityParse.java View File

@@ -171,7 +171,7 @@ public class ExcelEntityParse extends ExportCommonServer {
Map<String, Integer> titlemap = getTitleMap(table, index, entity.getHeadRows()); Map<String, Integer> titlemap = getTitleMap(table, index, entity.getHeadRows());
try { try {
// 得到所有字段 // 得到所有字段
Field fileds[] = PoiPublicUtil.getClassFields(entity.getClazz());
Field[] fileds = PoiPublicUtil.getClassFields(entity.getClazz());
ExcelTarget etarget = entity.getClazz().getAnnotation(ExcelTarget.class); ExcelTarget etarget = entity.getClazz().getAnnotation(ExcelTarget.class);
String targetId = null; String targetId = null;
if (etarget != null) { if (etarget != null) {


Loading…
Cancel
Save