master
wangbing 5 years ago
parent 6314510243
commit a2d0f6184c

@ -1,50 +0,0 @@
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
}

@ -1,32 +0,0 @@
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);
}
}

@ -1,52 +0,0 @@
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;
}
}

@ -1,38 +0,0 @@
package com.wb.excel.api.exception;
/**
* Created on 2014/10/15.
*
* @author
* @version 0.1.0
*/
public class ErrorType {
/**
*
*/
public static String UNIQUENESS_ERROR = "UNIQUENESS_ERROR";
/**
*
*/
public static String EXPECTATION_NULL = "EXPECTATION_NULL";
/**
*
*/
public static String BUSINESS_ERROR = "BUSINESS_ERROR";
/**
* JDBC
*/
public static String SYSTEM_ERROR = "SYSTEM_ERROR";
/**
*
*/
public static String INVALID_PARAMETER = "INVALID_PARAMETER";
/**
*
*/
public static String OTHER = "OTHER";
/**
* Dump
*/
public static String STACK_DUMP = "STACK_DUMP";
}

@ -1,32 +0,0 @@
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);
}
}

@ -1,32 +0,0 @@
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);
}
}

@ -1,29 +0,0 @@
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);
}
}

@ -1,135 +0,0 @@
package com.wb.excel.api.util;
import com.wb.excel.api.entity.DataVerifyResult;
import java.util.regex.Pattern;
/**
* ***************************************************************
* <p/>
* <pre>
* Copyright (c) 2014
* ColumnDescription:
* ***************************************************************
* </pre>
*/
public class BaseVerifyUtil {
private static String NOT_NULL = "不允许为空";
private static String IS_MOBILE = "不是手机号";
private static String IS_TEL = "不是电话号码";
private static String IS_EMAIL = "不是邮箱地址";
private static String MIN_LENGHT = "小于规定长度";
private static String MAX_LENGHT = "超过规定长度";
private static Pattern mobilePattern = Pattern.compile("^[1][3,4,5,8,7][0-9]{9}$");
private static Pattern telPattern = Pattern.compile("^([0][1-9]{2,3}-)?[0-9]{5,10}$");
private static Pattern emailPattern = Pattern
.compile("^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$");
/**
* email
*
* @param name
* @param val
* @return
*/
public static DataVerifyResult isEmail(String name, Object val) {
if (!emailPattern.matcher(String.valueOf(val)).matches()) {
return new DataVerifyResult(false, name + IS_EMAIL);
}
return new DataVerifyResult(true);
}
/**
*
*
* @param name
* @param val
* @return
*/
public static DataVerifyResult isMobile(String name, Object val) {
if (!mobilePattern.matcher(String.valueOf(val)).matches()) {
return new DataVerifyResult(false, name + IS_MOBILE);
}
return new DataVerifyResult(true);
}
/**
*
*
* @param name
* @param val
* @return
*/
public static DataVerifyResult isTel(String name, Object val) {
if (!telPattern.matcher(String.valueOf(val)).matches()) {
return new DataVerifyResult(false, name + IS_TEL);
}
return new DataVerifyResult(true);
}
/**
*
*
* @param name
* @param val
* @return
*/
public static DataVerifyResult maxLength(String name, Object val, int maxLength) {
if (notNull(name, val).isSuccess() && String.valueOf(val).length() > maxLength) {
return new DataVerifyResult(false, name + MAX_LENGHT);
}
return new DataVerifyResult(true);
}
/**
*
*
* @param name
* @param val
* @param minLength
* @return
*/
public static DataVerifyResult minLength(String name, Object val, int minLength) {
if (notNull(name, val).isSuccess() && String.valueOf(val).length() < minLength) {
return new DataVerifyResult(false, name + MIN_LENGHT);
}
return new DataVerifyResult(true);
}
/**
*
*
* @param name
* @param val
* @return
*/
public static DataVerifyResult notNull(String name, Object val) {
if (val == null || val.toString().equals("")) {
return new DataVerifyResult(false, name + NOT_NULL);
}
return new DataVerifyResult(true);
}
/**
*
*
* @param name
* @param val
* @param regex
* @param regexTip
* @return
*/
public static DataVerifyResult regex(String name, Object val, String regex,
String regexTip) {
Pattern pattern = Pattern.compile(regex);
if (!pattern.matcher(String.valueOf(val)).matches()) {
return new DataVerifyResult(false, name + regexTip);
}
return new DataVerifyResult(true);
}
}

@ -1,46 +0,0 @@
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;
}
}

@ -1,98 +0,0 @@
package com.wb.excel.api.util;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class StringUtil {
public static int getByteLength(String str) {
int length = str.replaceAll("[^\\x00-\\xff]", "**").length();
return length;
}
public static String upperFirstWord(String str) {
String temp = str.substring(0, 1);
return temp.toUpperCase() + str.substring(1);
}
/**
* TODO
*
* @param str
* @param reg
* @param index
* @return
*/
public static String split(String str, String reg, int index) {
if (reg.length() == 0) {
return str;
}
String[] strings = str.split(reg);
if (index < 0) {
index = 0;
}
if (index >= strings.length) {
index = strings.length - 1;
}
return strings[index];
}
public static String substring(String str, int start, int end) {
if (0 >= start || start >= str.length()) {
end = str.length() - 1;
}
if (0 >= end || end >= str.length()) {
end = str.length() - 1;
}
return str.substring(start, end);
}
public static String transferDate(String value) {
Double d = TransferUtil.transferDouble(value);
Date date = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if (d == null) {
try {
date = sdf.parse(value);
} catch (ParseException e) {
e.printStackTrace();
}
} else {
date = HSSFDateUtil.getJavaDate(d);
}
return sdf.format(date);
}
public static String transferDatetime(String value) {
Double d = TransferUtil.transferDouble(value);
Date date = null;
List<String> sdfList = new ArrayList<>();
sdfList.add("yyyy-MM-dd HH:mm:ss");
sdfList.add("yyyy-MM-dd hh:mm:ss");
sdfList.add("yyyy/MM/dd HH:mm:ss");
sdfList.add("yyyy/MM/dd hh:mm:ss");
SimpleDateFormat stdFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (d == null) {
for (String sdfValue : sdfList) {
SimpleDateFormat sdf = new SimpleDateFormat(sdfValue);
try {
date = sdf.parse(value);
break;
} catch (ParseException ignored) {
}
}
} else {
date = HSSFDateUtil.getJavaDate(d);
}
return stdFormat.format(date);
}
}

@ -1,145 +0,0 @@
package com.wb.excel.api.util;
/**
* ***************************************************************
* <p>
* <pre>
* Copyright (c) 2014
* ColumnDescription:
* ***************************************************************
* </pre>
*/
public class StringUtils {
private StringUtils() {
}
/**
*
* <ul>
* <li>SysUtils.isEmpty(null) = true</li>
* <li>SysUtils.isEmpty("") = true</li>
* <li>SysUtils.isEmpty(" ") = true</li>
* <li>SysUtils.isEmpty("abc") = false</li>
* </ul>
*
* @param value
* @return true/false
*/
public static boolean isEmpty(String value) {
int strLen;
if (value == null || (strLen = value.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if ((Character.isWhitespace(value.charAt(i)) == false)) {
return false;
}
}
return true;
}
public static boolean isNotEmpty(String value) {
int strLen;
if (value == null || (strLen = value.length()) == 0) {
return false;
}
for (int i = 0; i < strLen; i++) {
if ((Character.isWhitespace(value.charAt(i)) == false)) {
return true;
}
}
return false;
}
/**
* ,
*/
public static boolean isNumeric(Object obj) {
if (obj == null) {
return false;
}
char[] chars = obj.toString().toCharArray();
int length = chars.length;
if (length < 1)
return false;
int i = 0;
if (length > 1 && chars[0] == '-')
i = 1;
for (; i < length; i++) {
if (!Character.isDigit(chars[i])) {
return false;
}
}
return true;
}
/**
*
*/
public static boolean areNotEmpty(String... values) {
boolean result = true;
if (values == null || values.length == 0) {
result = false;
} else {
for (String value : values) {
result &= !isEmpty(value);
}
}
return result;
}
/**
*
*/
public static String unicodeToChinese(String unicode) {
StringBuilder out = new StringBuilder();
if (!isEmpty(unicode)) {
for (int i = 0; i < unicode.length(); i++) {
out.append(unicode.charAt(i));
}
}
return out.toString();
}
public static String toUnderlineStyle(String name) {
StringBuilder newName = new StringBuilder();
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
if (Character.isUpperCase(c)) {
if (i > 0) {
newName.append("_");
}
newName.append(Character.toLowerCase(c));
} else {
newName.append(c);
}
}
return newName.toString();
}
//
// public static String convertString(byte[] data, int offset, int length) {
// if(data == null) {
// return null;
// } else {
// try {
// return new String(data, offset, length, Constants.CHARSET_UTF8);
// } catch(Exception e) {
// throw new RuntimeException(e);
// }
// }
// }
//
// public static byte[] convertBytes(String data) {
// if(data == null) {
// return null;
// } else {
// try {
// return data.getBytes(Constants.CHARSET_UTF8);
// } catch(Exception e) {
// throw new RuntimeException(e);
// }
// }
// }
}

@ -1,76 +0,0 @@
package com.wb.excel.api.util;
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) {
if (value == null) {
return null;
}
Date date = null;
try {
value = value.trim();
if (value.matches("[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.parse(value);
} else if (value.matches("[0-9]{4}/[0-9]{1,2}/[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.parse(value);
} else if (value.matches("[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
date = sdf.parse(value);
} else if (value.matches("[0-9]{4}年[0-9]{1,2}月[0-9]{1,2}日 [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
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 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;
}
}
}

@ -1,4 +1,4 @@
package com.wb.excel.api; package xyz.wbsite.excel;
import java.io.Serializable; import java.io.Serializable;

@ -1,8 +1,8 @@
package com.wb.excel.api; package xyz.wbsite.excel;
import com.wb.excel.api.converter.Converter; import xyz.wbsite.excel.converter.Converter;
import com.wb.excel.api.util.StringUtil; import xyz.wbsite.excel.util.StringUtil;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Field; import java.lang.reflect.Field;

@ -1,4 +1,4 @@
package com.wb.excel.api; package xyz.wbsite.excel;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;

@ -1,18 +1,19 @@
package com.wb.excel.api; package xyz.wbsite.excel;
import com.wb.excel.api.annotation.*; import xyz.wbsite.excel.style.DataCellStyle;
import com.wb.excel.api.converter.*; import xyz.wbsite.excel.style.ErrorCellStyle;
import com.wb.excel.api.converter.Converter; import xyz.wbsite.excel.style.HeadCellStyle;
import com.wb.excel.api.exception.IllegalParameterException; import xyz.wbsite.excel.style.RedFont;
import com.wb.excel.api.exception.TemplateNotMatchException; import xyz.wbsite.excel.util.ClassUtil;
import com.wb.excel.api.style.*; import xyz.wbsite.excel.util.StringUtil;
import com.wb.excel.api.util.ClassUtil; import xyz.wbsite.excel.util.ValidationUtil;
import com.wb.excel.api.util.StringUtil;
import com.wb.excel.api.util.ValidationUtil;
import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*; import org.apache.poi.xssf.usermodel.*;
import xyz.wbsite.excel.annotation.*;
import xyz.wbsite.excel.annotation.Converter;
import xyz.wbsite.excel.converter.*;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.*; import java.io.*;
@ -102,11 +103,11 @@ public class WSheet<T> implements Serializable, Cloneable {
} }
//获取列类型 //获取列类型
if (field.isAnnotationPresent(com.wb.excel.api.annotation.Converter.class)) { if (field.isAnnotationPresent(Converter.class)) {
com.wb.excel.api.annotation.Converter converter = field.getAnnotation(com.wb.excel.api.annotation.Converter.class); Converter converter = field.getAnnotation(Converter.class);
Class target = converter.target(); Class target = converter.target();
try { try {
WColumn.setConverter((Converter) target.newInstance()); WColumn.setConverter((xyz.wbsite.excel.converter.Converter) target.newInstance());
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -164,7 +165,7 @@ public class WSheet<T> implements Serializable, Cloneable {
*/ */
public WSheet(List<T> list) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { public WSheet(List<T> list) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
if (list == null || list.size() == 0) { if (list == null || list.size() == 0) {
throw new IllegalParameterException("不允许传入空的列表"); throw new RuntimeException("不允许传入空的列表");
} }
if (list.size() > 0) { if (list.size() > 0) {
List<WColumn> wColumns = initColumns(list.get(0).getClass()); List<WColumn> wColumns = initColumns(list.get(0).getClass());
@ -206,10 +207,8 @@ public class WSheet<T> implements Serializable, Cloneable {
* @param clazz * @param clazz
* @throws IOException <br/>1:Excel - bytes <br/> * @throws IOException <br/>1:Excel - bytes <br/>
* 2:<br/> * 2:<br/>
* @throws TemplateNotMatchException <br/>1:Excel - Excel<br/>
* 2: - <br/>
*/ */
public WSheet(byte[] bytes, Class<T> clazz) throws IOException, TemplateNotMatchException { public WSheet(byte[] bytes, Class<T> clazz) throws IOException {
Workbook workbook = null; Workbook workbook = null;
InputStream is = null; InputStream is = null;
boolean flag; boolean flag;
@ -233,7 +232,7 @@ public class WSheet<T> implements Serializable, Cloneable {
is.close(); is.close();
} }
if (!flag) { if (!flag) {
throw new TemplateNotMatchException("不支持的文件类型"); throw new RuntimeException("不支持的文件类型");
} }
//第一张Sheet表 //第一张Sheet表
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
@ -253,7 +252,7 @@ public class WSheet<T> implements Serializable, Cloneable {
//检查列数量 //检查列数量
List<WColumn> list = initColumns(clazz); List<WColumn> list = initColumns(clazz);
if (list.size() != columnSum) { if (list.size() != columnSum) {
throw new TemplateNotMatchException("与模板列数量不同。"); throw new RuntimeException("与模板列数量不同。");
} else { } else {
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
WColumn wColumn = list.get(i); WColumn wColumn = list.get(i);
@ -263,7 +262,7 @@ public class WSheet<T> implements Serializable, Cloneable {
headValue = headValue.replace(" ", ""); headValue = headValue.replace(" ", "");
if (!wColumn.getName().equals(headValue)) { if (!wColumn.getName().equals(headValue)) {
throw new TemplateNotMatchException("第" + (i + 1) + "项,不匹配的列名," + wColumn.getName() + "和" + headValue); throw new RuntimeException("第" + (i + 1) + "项,不匹配的列名," + wColumn.getName() + "和" + headValue);
} }
} }
} }
@ -351,7 +350,7 @@ public class WSheet<T> implements Serializable, Cloneable {
String value = WCell.getValue(); String value = WCell.getValue();
Method method = clazz.getMethod("set" + att, field.getType()); Method method = clazz.getMethod("set" + att, field.getType());
//获取转换器 //获取转换器
Converter converter = column.getConverter(); xyz.wbsite.excel.converter.Converter converter = column.getConverter();
method.invoke(object, converter.convert(value)); method.invoke(object, converter.convert(value));
} }
break; break;

@ -1,4 +1,4 @@
package com.wb.excel.api.annotation; package xyz.wbsite.excel.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;

@ -1,4 +1,4 @@
package com.wb.excel.api.annotation; package xyz.wbsite.excel.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;

@ -1,4 +1,4 @@
package com.wb.excel.api.annotation; package xyz.wbsite.excel.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;

@ -1,4 +1,4 @@
package com.wb.excel.api.annotation; package xyz.wbsite.excel.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;

@ -1,4 +1,4 @@
package com.wb.excel.api.annotation; package xyz.wbsite.excel.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;

@ -1,4 +1,4 @@
package com.wb.excel.api.annotation; package xyz.wbsite.excel.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
public class BooleanConverter implements Converter<Boolean> { public class BooleanConverter implements Converter<Boolean> {

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
public class ByteConverter implements Converter<Byte> { public class ByteConverter implements Converter<Byte> {

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
public class CharacterConverter implements Converter<Character> { public class CharacterConverter implements Converter<Character> {

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
public interface Converter<T> { public interface Converter<T> {

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
public class DoubleConverter implements Converter<Double> { public class DoubleConverter implements Converter<Double> {

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
public class FloatConverter implements Converter<Float> { public class FloatConverter implements Converter<Float> {

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
public class IntegerConverter implements Converter<Integer> { public class IntegerConverter implements Converter<Integer> {

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
import java.util.regex.Matcher; import java.util.regex.Matcher;

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
public class ShortConverter implements Converter<Short> { public class ShortConverter implements Converter<Short> {

@ -1,4 +1,4 @@
package com.wb.excel.api.converter; package xyz.wbsite.excel.converter;
public class StringConverter implements Converter<String> { public class StringConverter implements Converter<String> {

@ -1,4 +1,4 @@
package com.wb.excel.api.entity; package xyz.wbsite.excel.entity;
import java.io.Serializable; import java.io.Serializable;

@ -1,4 +1,4 @@
package com.wb.excel.api.entity; package xyz.wbsite.excel.entity;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;

@ -1,6 +1,5 @@
package com.wb.excel.api.style; package xyz.wbsite.excel.style;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;

@ -1,4 +1,4 @@
package com.wb.excel.api.style; package xyz.wbsite.excel.style;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;

@ -1,4 +1,4 @@
package com.wb.excel.api.style; package xyz.wbsite.excel.style;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;

@ -1,4 +1,4 @@
package com.wb.excel.api.style; package xyz.wbsite.excel.style;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;

@ -1,8 +1,7 @@
package com.wb.excel.api.style; package xyz.wbsite.excel.style;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
public class HeadCellStyle extends BaseCellStyle { public class HeadCellStyle extends BaseCellStyle {

@ -1,4 +1,4 @@
package com.wb.excel.api.style; package xyz.wbsite.excel.style;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;

@ -1,4 +1,4 @@
package com.wb.excel.api.style; package xyz.wbsite.excel.style;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;

@ -1,4 +1,4 @@
package com.wb.excel.api.util; package xyz.wbsite.excel.util;
import java.lang.reflect.Field; import java.lang.reflect.Field;

@ -0,0 +1,87 @@
package xyz.wbsite.excel.util;
public class StringUtil {
public static int getByteLength(String str) {
int length = str.replaceAll("[^\\x00-\\xff]", "**").length();
return length;
}
public static String upperFirstWord(String str) {
String temp = str.substring(0, 1);
return temp.toUpperCase() + str.substring(1);
}
public static boolean isEmpty(String value) {
int strLen;
if (value == null || (strLen = value.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if ((Character.isWhitespace(value.charAt(i)) == false)) {
return false;
}
}
return true;
}
public static boolean isNotEmpty(String value) {
return !isEmpty(value);
}
/**
* ,
*/
public static boolean isNumeric(Object obj) {
if (obj == null) {
return false;
}
char[] chars = obj.toString().toCharArray();
int length = chars.length;
if (length < 1)
return false;
int i = 0;
if (length > 1 && chars[0] == '-')
i = 1;
for (; i < length; i++) {
if (!Character.isDigit(chars[i])) {
return false;
}
}
return true;
}
/**
*
*/
public static String unicodeToChinese(String unicode) {
StringBuilder out = new StringBuilder();
if (!isEmpty(unicode)) {
for (int i = 0; i < unicode.length(); i++) {
out.append(unicode.charAt(i));
}
}
return out.toString();
}
public static String toUnderlineStyle(String name) {
StringBuilder newName = new StringBuilder();
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
if (Character.isUpperCase(c)) {
if (i > 0) {
newName.append("_");
}
newName.append(Character.toLowerCase(c));
} else {
newName.append(c);
}
}
return newName.toString();
}
}

@ -1,4 +1,4 @@
package com.wb.excel.api.util; package xyz.wbsite.excel.util;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.Validation; import javax.validation.Validation;

@ -1,6 +1,4 @@
import com.wb.excel.api.WSheet; import xyz.wbsite.excel.WSheet;
import com.wb.excel.api.exception.TemplateNotMatchException;
import java.io.*; import java.io.*;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
@ -91,18 +89,16 @@ public class ExampleTest {
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
} catch (TemplateNotMatchException e) { } catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} }
} }

@ -1,6 +1,6 @@
import com.wb.excel.api.annotation.ColumnDescription; import xyz.wbsite.excel.annotation.ColumnDescription;
import com.wb.excel.api.annotation.ColumnName; import xyz.wbsite.excel.annotation.ColumnName;
import com.wb.excel.api.annotation.SheetName; import xyz.wbsite.excel.annotation.SheetName;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import java.util.Date; import java.util.Date;

Loading…
Cancel
Save

Powered by TurnKey Linux.