parent
58a837d81c
commit
d011846d84
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>xyx.wbsite</groupId>
|
||||||
|
<artifactId>wexcel</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-validator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-validator</artifactId>
|
||||||
|
<version>5.1.2.Final</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>3.8</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.wb.excel.api.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优先通过target来判断枚举的值
|
||||||
|
* Created on 2014/9/26.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version v1.0.0.0
|
||||||
|
*/
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface Enum {
|
||||||
|
public Class target();
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com)
|
||||||
|
* <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,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.wb.excel.api.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Excel 导入校验
|
||||||
|
*
|
||||||
|
* @author JueYue
|
||||||
|
* @date 2014年6月23日 下午10:46:26
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
public @interface ExcelVerify {
|
||||||
|
/**
|
||||||
|
* 接口校验
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean interHandler() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是电子邮件
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isEmail() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是13位移动电话
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isMobile() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是座机号码
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isTel() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大长度
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int maxLength() default -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最小长度
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int minLength() default -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许空
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean notNull() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正在表达式
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String regex() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正在表达式,错误提示信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String regexTip() default "数据不符合规范";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.wb.excel.api.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/9/24.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version v1.0.0.0
|
||||||
|
*/
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface HeaderDescription {
|
||||||
|
String value() default "";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.wb.excel.api.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为字段、方法或类注解名称。<br/>
|
||||||
|
* Created on 2014/9/24.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version v1.0.0.0
|
||||||
|
*/
|
||||||
|
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface HeaderName {
|
||||||
|
String value();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String orderNum() default "0";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期格式化
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String dateFormat() default "yyyy-MM-dd";
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.wb.excel.api.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/9/24.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version v1.0.0.0
|
||||||
|
*/
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface NoRepeat {
|
||||||
|
String value() default "";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.wb.excel.api.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/5/28.
|
||||||
|
*
|
||||||
|
* @author 金洋
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface ParentFirst {
|
||||||
|
boolean value() default true;
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.wb.excel.api.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/9/26.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version v1.0.0.0
|
||||||
|
*/
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface Split {
|
||||||
|
/**
|
||||||
|
* 分隔字符
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String reg() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取分隔后的结果的下标。从0开始。
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int index() default 0;
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.wb.excel.api.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/9/26.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version v1.0.0.0
|
||||||
|
*/
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface Substring {
|
||||||
|
int start() default 0;
|
||||||
|
|
||||||
|
int end() default 0;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.wb.excel.api.annotation;
|
||||||
|
|
||||||
|
|
||||||
|
import com.wb.excel.api.enumeration.DataType;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/9/24.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version v1.0.0.0
|
||||||
|
*/
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface Type {
|
||||||
|
public DataType value() default DataType.STRING;
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.wb.excel.api.datatable;
|
||||||
|
|
||||||
|
|
||||||
|
import com.wb.excel.api.enumeration.Status;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单元格.
|
||||||
|
* Created on 2014/9/23.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 0.1.0
|
||||||
|
*/
|
||||||
|
public class Cell implements Serializable {
|
||||||
|
/**
|
||||||
|
* 单元格的状态
|
||||||
|
*/
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单元格的值
|
||||||
|
*/
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认无参构造方法.会将单元格的状态设为通过.
|
||||||
|
*/
|
||||||
|
public Cell() {
|
||||||
|
this.status = Status.PASS;
|
||||||
|
this.value = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传入默认单元格值的构造方法.
|
||||||
|
*
|
||||||
|
* @param value 单元格的值.
|
||||||
|
*/
|
||||||
|
public Cell(String value) {
|
||||||
|
this.value = value;
|
||||||
|
this.status = Status.PASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Status getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Status status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.wb.excel.api.datatable;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DataTable中的行对象.
|
||||||
|
* Created on 2014/09/19.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 0.1.0
|
||||||
|
*/
|
||||||
|
public class DataRow extends HashMap<String, Cell> implements Serializable {
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,141 @@
|
|||||||
|
package com.wb.excel.api.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Excel 校验对象
|
||||||
|
*/
|
||||||
|
public class ExcelVerifyEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口校验
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean interHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许空
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean notNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是13位移动电话
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isMobile;
|
||||||
|
/**
|
||||||
|
* 是座机号码
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isTel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是电子邮件
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isEmail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最小长度
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int minLength;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大长度
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int maxLength;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正在表达式
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String regex;
|
||||||
|
/**
|
||||||
|
* 正在表达式,错误提示信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String regexTip;
|
||||||
|
|
||||||
|
public int getMaxLength() {
|
||||||
|
return maxLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinLength() {
|
||||||
|
return minLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRegex() {
|
||||||
|
return regex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRegexTip() {
|
||||||
|
return regexTip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmail() {
|
||||||
|
return isEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInterHandler() {
|
||||||
|
return interHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMobile() {
|
||||||
|
return isMobile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNotNull() {
|
||||||
|
return notNull;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTel() {
|
||||||
|
return isTel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(boolean isEmail) {
|
||||||
|
this.isEmail = isEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInterHandler(boolean interHandler) {
|
||||||
|
this.interHandler = interHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxLength(int maxLength) {
|
||||||
|
this.maxLength = maxLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinLength(int minLength) {
|
||||||
|
this.minLength = minLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMobile(boolean isMobile) {
|
||||||
|
this.isMobile = isMobile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotNull(boolean notNull) {
|
||||||
|
this.notNull = notNull;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegex(String regex) {
|
||||||
|
this.regex = regex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegexTip(String regexTip) {
|
||||||
|
this.regexTip = regexTip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTel(boolean isTel) {
|
||||||
|
this.isTel = isTel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.wb.excel.api.enumeration;
|
||||||
|
|
||||||
|
import com.wb.excel.api.annotation.EnumValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/9/26.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version 0.1.0
|
||||||
|
*/
|
||||||
|
public enum Gender {
|
||||||
|
@EnumValue({"男", "male", "m"})
|
||||||
|
M,
|
||||||
|
@EnumValue({"女", "female", "f"})
|
||||||
|
F,
|
||||||
|
@EnumValue({"未知", "其它", "其他", "u"})
|
||||||
|
U
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.wb.excel.api.enumeration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/9/23.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version v1.0.0.0
|
||||||
|
*/
|
||||||
|
public enum Status {
|
||||||
|
/**
|
||||||
|
* 数据库中已存在
|
||||||
|
*/
|
||||||
|
EXIST,
|
||||||
|
/**
|
||||||
|
* 数据库中不存在
|
||||||
|
*/
|
||||||
|
NOTEXIST,
|
||||||
|
/**
|
||||||
|
* 不符合的枚举值
|
||||||
|
*/
|
||||||
|
ERROR_VALUE,
|
||||||
|
/**
|
||||||
|
* 验证通过
|
||||||
|
*/
|
||||||
|
PASS,
|
||||||
|
/**
|
||||||
|
* 不允许重复的列发生了重复
|
||||||
|
*/
|
||||||
|
REPEAT,
|
||||||
|
/**
|
||||||
|
* 格式不正确
|
||||||
|
*/
|
||||||
|
FORMAT,
|
||||||
|
/**
|
||||||
|
* 长度不符合要求
|
||||||
|
*/
|
||||||
|
LENGTH,
|
||||||
|
/**
|
||||||
|
* 不允许为空的列出现了空
|
||||||
|
*/
|
||||||
|
EMPTY,
|
||||||
|
/**
|
||||||
|
* 数字类型的值过小
|
||||||
|
*/
|
||||||
|
TOO_SMALL,
|
||||||
|
/**
|
||||||
|
* 数字类型的值过大
|
||||||
|
*/
|
||||||
|
TOO_BIG
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.wb.excel.api.enumeration;
|
||||||
|
|
||||||
|
import com.wb.excel.api.annotation.EnumValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于判断Boolean型的值。仅供DataTable判断Boolean类型时使用。<br/><br/>
|
||||||
|
* <b>不建议使用。</b><br/><br/>
|
||||||
|
* Created on 2014/9/27.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version 0.1.0
|
||||||
|
*/
|
||||||
|
public enum YesNo {
|
||||||
|
@EnumValue({"是", "yes", "y", "true"})
|
||||||
|
Y,
|
||||||
|
@EnumValue({"否", "no", "n", "false"})
|
||||||
|
N
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.wb.excel.api.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/10/12.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version 0.1.0
|
||||||
|
*/
|
||||||
|
public class ColumnNameNotExistException extends RuntimeException {
|
||||||
|
private static final long serialVersionUID = 234122996006212387L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with {@code null} as its
|
||||||
|
* detail message. The cause is not initialized, and may subsequently be
|
||||||
|
* initialized by a call to {@link #initCause}.
|
||||||
|
*/
|
||||||
|
public ColumnNameNotExistException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified detail message.
|
||||||
|
* The cause is not initialized, and may subsequently be initialized by a
|
||||||
|
* call to {@link #initCause}.
|
||||||
|
*
|
||||||
|
* @param message the detail message. The detail message is saved for
|
||||||
|
* later retrieval by the {@link #getMessage()} method.
|
||||||
|
*/
|
||||||
|
public ColumnNameNotExistException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.wb.excel.api.exception;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Error implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3L;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private ErrorType type;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public Error() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Error(String code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Error(ErrorType type, String message) {
|
||||||
|
this.type = type;
|
||||||
|
this.code = type.toString();
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(ErrorType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.wb.excel.api.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/10/12.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version 0.1.0
|
||||||
|
*/
|
||||||
|
public class ExistedColumnNameException extends RuntimeException {
|
||||||
|
private static final long serialVersionUID = 234122996006212387L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with {@code null} as its
|
||||||
|
* detail message. The cause is not initialized, and may subsequently be
|
||||||
|
* initialized by a call to {@link #initCause}.
|
||||||
|
*/
|
||||||
|
public ExistedColumnNameException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified detail message.
|
||||||
|
* The cause is not initialized, and may subsequently be initialized by a
|
||||||
|
* call to {@link #initCause}.
|
||||||
|
*
|
||||||
|
* @param message the detail message. The detail message is saved for
|
||||||
|
* later retrieval by the {@link #getMessage()} method.
|
||||||
|
*/
|
||||||
|
public ExistedColumnNameException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.wb.excel.api.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/10/12.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version 0.1.0
|
||||||
|
*/
|
||||||
|
public class IllegalParameterException extends RuntimeException {
|
||||||
|
private static final long serialVersionUID = 234122996006212387L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with {@code null} as its
|
||||||
|
* detail message. The cause is not initialized, and may subsequently be
|
||||||
|
* initialized by a call to {@link #initCause}.
|
||||||
|
*/
|
||||||
|
public IllegalParameterException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified detail message.
|
||||||
|
* The cause is not initialized, and may subsequently be initialized by a
|
||||||
|
* call to {@link #initCause}.
|
||||||
|
*
|
||||||
|
* @param message the detail message. The detail message is saved for
|
||||||
|
* later retrieval by the {@link #getMessage()} method.
|
||||||
|
*/
|
||||||
|
public IllegalParameterException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.wb.excel.api.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/10/12.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version 0.1.0
|
||||||
|
*/
|
||||||
|
public class TemplateNotMatchException extends Exception {
|
||||||
|
/**
|
||||||
|
* Constructs a new exception with {@code null} as its detail message.
|
||||||
|
* The cause is not initialized, and may subsequently be initialized by a
|
||||||
|
* call to {@link #initCause}.
|
||||||
|
*/
|
||||||
|
public TemplateNotMatchException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new exception with the specified detail message. The
|
||||||
|
* cause is not initialized, and may subsequently be initialized by
|
||||||
|
* a call to {@link #initCause}.
|
||||||
|
*
|
||||||
|
* @param message the detail message. The detail message is saved for
|
||||||
|
* later retrieval by the {@link #getMessage()} method.
|
||||||
|
*/
|
||||||
|
public TemplateNotMatchException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.wb.excel.api.interfaces;
|
||||||
|
|
||||||
|
import com.wb.excel.api.entity.DataVerifyResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入校验接口
|
||||||
|
*/
|
||||||
|
public interface IExcelVerifyHandler {
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 获取需要处理的字段,导入和导出统一处理了, 减少书写的字段
|
||||||
|
// *
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// public String[] getNeedVerifyFields();
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 获取需要处理的字段,导入和导出统一处理了, 减少书写的字段
|
||||||
|
// *
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// public void setNeedVerifyFields(String[] arr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据校验
|
||||||
|
*
|
||||||
|
* @param obj 当前对象
|
||||||
|
* @param name 当前字段名称
|
||||||
|
* @param value 当前值
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public DataVerifyResult verifyHandler(Object obj, String name, Object value);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class BaseCellStyle {
|
||||||
|
/**
|
||||||
|
* 样式
|
||||||
|
*/
|
||||||
|
protected CellStyle style;
|
||||||
|
|
||||||
|
public BaseCellStyle(Workbook workbook) {
|
||||||
|
style = workbook.createCellStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CellStyle getStyle() {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStyle(CellStyle style) {
|
||||||
|
this.style = style;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class BaseFont {
|
||||||
|
/**
|
||||||
|
* 字体
|
||||||
|
*/
|
||||||
|
protected Font font;
|
||||||
|
|
||||||
|
public BaseFont(Workbook workbook) {
|
||||||
|
font = workbook.createFont();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Font getFont() {
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFont(Font font) {
|
||||||
|
this.font = font;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class CheckFailureCellStyle extends BaseCellStyle {
|
||||||
|
public CheckFailureCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
Font font = workbook.createFont(); // 单元格的字体
|
||||||
|
font.setColor(HSSFColor.WHITE.index); // 字体颜色-白色
|
||||||
|
CellStyle style = workbook.createCellStyle(); // 单元格的样式
|
||||||
|
style.setFillForegroundColor(HSSFColor.RED.index); // 背景颜色-红色
|
||||||
|
style.setFillPattern(CellStyle.SOLID_FOREGROUND); // 设置单元格填充样式
|
||||||
|
style.setAlignment(CellStyle.ALIGN_CENTER); // 居中
|
||||||
|
style.setFont(font);
|
||||||
|
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //上下居中
|
||||||
|
|
||||||
|
//下边框
|
||||||
|
style.setBorderBottom(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//下边框颜色
|
||||||
|
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//左边框
|
||||||
|
style.setBorderLeft(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//左边框颜色
|
||||||
|
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//右边框
|
||||||
|
style.setBorderRight(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//右边框颜色
|
||||||
|
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//上边框
|
||||||
|
style.setBorderTop(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//上边框颜色
|
||||||
|
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class CheckMessageCellStyle extends BaseCellStyle {
|
||||||
|
public CheckMessageCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
Font font = workbook.createFont(); // 单元格的字体
|
||||||
|
font.setColor(HSSFColor.BLACK.index); // 字体颜色-黑色
|
||||||
|
CellStyle style = workbook.createCellStyle(); // 单元格的样式
|
||||||
|
style.setFillPattern(CellStyle.NO_FILL); // 设置单元格无填充
|
||||||
|
style.setFont(font);
|
||||||
|
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //上下居中
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class CheckSuccessCellStyle extends BaseCellStyle {
|
||||||
|
public CheckSuccessCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
style.setFillForegroundColor(HSSFColor.LIME.index); // 背景颜色-绿色
|
||||||
|
style.setFillPattern(CellStyle.SOLID_FOREGROUND); // 设置单元格填充样式
|
||||||
|
style.setAlignment(CellStyle.ALIGN_CENTER); // 居中
|
||||||
|
//style.setFont(font);
|
||||||
|
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //上下居中
|
||||||
|
|
||||||
|
//下边框
|
||||||
|
style.setBorderBottom(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//下边框颜色
|
||||||
|
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//左边框
|
||||||
|
style.setBorderLeft(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//左边框颜色
|
||||||
|
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//右边框
|
||||||
|
style.setBorderRight(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//右边框颜色
|
||||||
|
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//上边框
|
||||||
|
style.setBorderTop(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//上边框颜色
|
||||||
|
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class ErrorCellStyle extends BaseCellStyle {
|
||||||
|
public ErrorCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
style.setFillForegroundColor(HSSFColor.ORANGE.index); //背景颜色-紫罗兰色
|
||||||
|
style.setFillPattern(CellStyle.SOLID_FOREGROUND); //设置单元格填充样式
|
||||||
|
//style.setFont(font); //设置单元格字体
|
||||||
|
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//上下居中
|
||||||
|
|
||||||
|
//下边框
|
||||||
|
style.setBorderBottom(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//下边框颜色
|
||||||
|
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//左边框
|
||||||
|
style.setBorderLeft(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//左边框颜色
|
||||||
|
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//右边框
|
||||||
|
style.setBorderRight(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//右边框颜色
|
||||||
|
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//上边框
|
||||||
|
style.setBorderTop(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//上边框颜色
|
||||||
|
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class ErrorNumberCellStyle extends ErrorCellStyle {
|
||||||
|
public ErrorNumberCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
style.setAlignment(CellStyle.ALIGN_RIGHT);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class HeadCellStyle extends BaseCellStyle {
|
||||||
|
public HeadCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); //背景颜色-灰色
|
||||||
|
style.setFillPattern(CellStyle.SOLID_FOREGROUND); // 设置单元格填充样式
|
||||||
|
style.setAlignment(CellStyle.ALIGN_CENTER); // 居中
|
||||||
|
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//上下居中
|
||||||
|
|
||||||
|
//下边框
|
||||||
|
style.setBorderBottom(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//下边框颜色
|
||||||
|
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//左边框
|
||||||
|
style.setBorderLeft(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//左边框颜色
|
||||||
|
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//右边框
|
||||||
|
style.setBorderRight(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//右边框颜色
|
||||||
|
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//上边框
|
||||||
|
style.setBorderTop(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//上边框颜色
|
||||||
|
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class NormalCellStyle extends BaseCellStyle {
|
||||||
|
public NormalCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
style.setFillPattern(CellStyle.NO_FILL); //单元格不填充
|
||||||
|
//style.setFont(font); //设置单元格字体
|
||||||
|
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //上下居中
|
||||||
|
style.setBorderBottom(CellStyle.SOLID_FOREGROUND); //下边框
|
||||||
|
style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //下边框颜色
|
||||||
|
style.setBorderLeft(CellStyle.SOLID_FOREGROUND); //左边框
|
||||||
|
style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); //左边框颜色
|
||||||
|
style.setBorderRight(CellStyle.SOLID_FOREGROUND); //右边框
|
||||||
|
style.setRightBorderColor(IndexedColors.BLACK.getIndex()); //右边框颜色
|
||||||
|
style.setBorderTop(CellStyle.SOLID_FOREGROUND); //上边框
|
||||||
|
style.setTopBorderColor(IndexedColors.BLACK.getIndex()); //上边框颜色
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 普通字体.颜色黑
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class NormalFont extends BaseFont {
|
||||||
|
public NormalFont(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
font.setColor(HSSFColor.BLACK.index); //字体颜色-黑色
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class NormalNumberCellStyle extends NormalCellStyle {
|
||||||
|
public NormalNumberCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
style.setAlignment(CellStyle.ALIGN_RIGHT);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.wb.excel.api.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 普通字体.颜色黑
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class RedFont extends BaseFont {
|
||||||
|
public RedFont(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
font.setColor(HSSFColor.RED.index); //字体颜色-黑色
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,195 @@
|
|||||||
|
package com.wb.excel.api.util;
|
||||||
|
|
||||||
|
|
||||||
|
import com.wb.excel.api.annotation.ExcelCollection;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/5/28.
|
||||||
|
*
|
||||||
|
* @author 金洋
|
||||||
|
* @version 2.1.0
|
||||||
|
*/
|
||||||
|
public class ClassUtil {
|
||||||
|
|
||||||
|
public static Field[] getFields(Class clazz, boolean parentFirst) {
|
||||||
|
List<Field> returnList = new ArrayList<>();
|
||||||
|
Set<String> nameSet = new HashSet<>();
|
||||||
|
|
||||||
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
|
|
||||||
|
for (Field field : fields) {
|
||||||
|
returnList.add(field);
|
||||||
|
nameSet.add(field.getName());
|
||||||
|
}
|
||||||
|
List<Field> parentList = getParentFields(clazz.getSuperclass(), nameSet, parentFirst);
|
||||||
|
if (parentFirst) {
|
||||||
|
parentList.addAll(returnList);
|
||||||
|
returnList = parentList;
|
||||||
|
} else {
|
||||||
|
returnList.addAll(parentList);
|
||||||
|
}
|
||||||
|
|
||||||
|
fields = new Field[returnList.size()];
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
for (Field field : returnList) {
|
||||||
|
fields[index++] = field;
|
||||||
|
}
|
||||||
|
return fields;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取class的 包括父类的
|
||||||
|
*
|
||||||
|
* @param clazz
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Field[] getClassFields(Class<?> clazz) {
|
||||||
|
List<Field> list = new ArrayList<Field>();
|
||||||
|
Field[] fields;
|
||||||
|
do {
|
||||||
|
fields = clazz.getDeclaredFields();
|
||||||
|
for (int i = 0; i < fields.length; i++) {
|
||||||
|
list.add(fields[i]);
|
||||||
|
}
|
||||||
|
clazz = clazz.getSuperclass();
|
||||||
|
} while (clazz != Object.class && clazz != null);
|
||||||
|
return list.toArray(fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是不是集合的实现类
|
||||||
|
*
|
||||||
|
* @param clazz
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isCollection(Class<?> clazz) {
|
||||||
|
return Collection.class.isAssignableFrom(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取GET方法
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param pojoClass
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static Method getMethod(String name, Class<?> pojoClass) throws Exception {
|
||||||
|
StringBuffer getMethodName = new StringBuffer("get");
|
||||||
|
getMethodName.append(name.substring(0, 1).toUpperCase());
|
||||||
|
getMethodName.append(name.substring(1));
|
||||||
|
Method method = null;
|
||||||
|
try {
|
||||||
|
method = pojoClass.getMethod(getMethodName.toString(), new Class[]{});
|
||||||
|
} catch (Exception e) {
|
||||||
|
method = pojoClass.getMethod(
|
||||||
|
getMethodName.toString().replace("get", "is"),
|
||||||
|
new Class[]{});
|
||||||
|
}
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取SET方法
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param pojoClass
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static Method getMethod(String name, Class<?> pojoClass, Class<?> type) throws Exception {
|
||||||
|
StringBuffer getMethodName = new StringBuffer("set");
|
||||||
|
getMethodName.append(name.substring(0, 1).toUpperCase());
|
||||||
|
getMethodName.append(name.substring(1));
|
||||||
|
return pojoClass.getMethod(getMethodName.toString(), new Class[]{type});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是不是java基础类
|
||||||
|
*
|
||||||
|
* @param field
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isJavaClass(Field field) {
|
||||||
|
Class<?> fieldType = field.getType();
|
||||||
|
boolean isBaseClass = false;
|
||||||
|
if (fieldType.isArray()) {
|
||||||
|
isBaseClass = false;
|
||||||
|
} 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")) {
|
||||||
|
isBaseClass = true;
|
||||||
|
}
|
||||||
|
return isBaseClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过指定的类型获取所有的成员变量
|
||||||
|
*
|
||||||
|
* @param clazz
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Field[] getFields(Class clazz) {
|
||||||
|
return getFields(clazz, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Field> getParentFields(Class parentClazz, Set<String> nameSet, boolean parentFirst) {
|
||||||
|
List<Field> fieldList = new ArrayList<>();
|
||||||
|
|
||||||
|
if (parentClazz != null) {
|
||||||
|
Field[] parentList = parentClazz.getDeclaredFields();
|
||||||
|
int index = 0;
|
||||||
|
for (Field field : parentList) {
|
||||||
|
int beginSize = nameSet.size();
|
||||||
|
nameSet.add(field.getName());
|
||||||
|
int endSize = nameSet.size();
|
||||||
|
|
||||||
|
if (endSize > beginSize) {
|
||||||
|
if (parentFirst) {
|
||||||
|
fieldList.add(index++, field);
|
||||||
|
} else {
|
||||||
|
fieldList.add(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldList.addAll(getParentFields(parentClazz.getSuperclass(), nameSet, parentFirst));
|
||||||
|
}
|
||||||
|
return fieldList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object createObject(Class<?> clazz) {
|
||||||
|
Object obj = null;
|
||||||
|
Method setMethod;
|
||||||
|
try {
|
||||||
|
if (clazz.equals(Map.class)) {
|
||||||
|
return new HashMap<String, Object>();
|
||||||
|
}
|
||||||
|
obj = clazz.newInstance();
|
||||||
|
Field[] fields = getClassFields(clazz);
|
||||||
|
for (Field field : fields) {
|
||||||
|
if (isCollection(field.getType())) {
|
||||||
|
ExcelCollection collection = field.getAnnotation(ExcelCollection.class);
|
||||||
|
setMethod = getMethod(field.getName(), clazz, field.getType());
|
||||||
|
setMethod.invoke(obj, collection.type().newInstance());
|
||||||
|
} else if (!isJavaClass(field)) {
|
||||||
|
setMethod = getMethod(field.getName(), clazz, field.getType());
|
||||||
|
setMethod.invoke(obj, createObject(field.getType()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("创建对象异常");
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.wb.excel.api.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/10/12.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version 0.1.0
|
||||||
|
*/
|
||||||
|
public class DataTableUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试用方法。从本地文件读取字节数据。
|
||||||
|
*
|
||||||
|
* @param url 本地文件路径
|
||||||
|
* @return 读取文件的byte数组
|
||||||
|
* @throws java.io.IOException 读取文件中可能会抛出异常
|
||||||
|
*/
|
||||||
|
public static byte[] readFile(String url) throws IOException {
|
||||||
|
File file = new File(url);
|
||||||
|
InputStream is = new FileInputStream(file);
|
||||||
|
Long length = file.length();
|
||||||
|
if (length > Integer.MAX_VALUE) {
|
||||||
|
throw new IOException("文件过大,无法读取");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] bytes = new byte[length.intValue()];
|
||||||
|
int offset = 0;
|
||||||
|
int numRead;
|
||||||
|
while (offset < bytes.length
|
||||||
|
&& (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
|
||||||
|
offset += numRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果得到的字节长度和file实际的长度不一致就可能出错了
|
||||||
|
if (offset < bytes.length) {
|
||||||
|
System.out.println("文件长度不一致");
|
||||||
|
}
|
||||||
|
is.close();
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.wb.excel.api.util;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Excel工具类.
|
||||||
|
* Created on 2014/9/1.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 0.1.0
|
||||||
|
*/
|
||||||
|
public class ExcelUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单元格的值
|
||||||
|
*
|
||||||
|
* @param cell 要获取值的单元格
|
||||||
|
* @return 单元格的值
|
||||||
|
*/
|
||||||
|
public static String getValue(Cell cell) {
|
||||||
|
if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
|
||||||
|
// 返回布尔类型的值
|
||||||
|
return String.valueOf(cell.getBooleanCellValue());
|
||||||
|
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
|
||||||
|
// 返回数值类型的值
|
||||||
|
return String.valueOf(cell.getNumericCellValue());
|
||||||
|
} else {
|
||||||
|
// 返回字符串类型的值
|
||||||
|
return String.valueOf(cell.getStringCellValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
package com.wb.excel.api.util;
|
||||||
|
|
||||||
|
|
||||||
|
import com.wb.excel.api.enumeration.YesNo;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2014/9/27.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @version 0.1.0
|
||||||
|
*/
|
||||||
|
public class TransferUtil {
|
||||||
|
public static Date transferDate(String value) {
|
||||||
|
Date date = null;
|
||||||
|
try {
|
||||||
|
if (value.length() == 10) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
date = sdf.parse(value);
|
||||||
|
} else if (value.length() > 10) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
date = sdf.parse(value);
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Date transferDatetime(String value) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
Date date = null;
|
||||||
|
try {
|
||||||
|
date = sdf.parse(value);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Date transferDateminute(String value) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
|
Date date = null;
|
||||||
|
try {
|
||||||
|
date = sdf.parse(value);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer transferInteger(String value) {
|
||||||
|
try {
|
||||||
|
Double d = Double.parseDouble(value);
|
||||||
|
int i = d.intValue();
|
||||||
|
if (d != i) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Double transferDouble(String value) {
|
||||||
|
try {
|
||||||
|
return Double.parseDouble(value);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean transferBoolean(String value) {
|
||||||
|
String key = EnumUtil.getKey(YesNo.class, value);
|
||||||
|
if (key.equals("Y")) {
|
||||||
|
return true;
|
||||||
|
} else if (key.equals("N")) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long transferLong(String value) {
|
||||||
|
try {
|
||||||
|
Double d = Double.parseDouble(value);
|
||||||
|
long i = d.longValue();
|
||||||
|
if (d != i) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
import com.wb.excel.api.annotation.Enum;
|
||||||
|
import com.wb.excel.api.annotation.EnumValue;
|
||||||
|
import com.wb.excel.api.enumeration.YesNo;
|
||||||
|
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String password;
|
||||||
|
private String qq;
|
||||||
|
|
||||||
|
@Enum(target = YesNo.class)
|
||||||
|
private YesNo sex;
|
||||||
|
|
||||||
|
public User() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public User(String name, String password, String qq) {
|
||||||
|
this.name = name;
|
||||||
|
this.password = password;
|
||||||
|
this.qq = qq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public YesNo getSex() {
|
||||||
|
return sex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSex(YesNo sex) {
|
||||||
|
this.sex = sex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQq() {
|
||||||
|
return qq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQq(String qq) {
|
||||||
|
this.qq = qq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue