|
|
@ -3,12 +3,12 @@ package com.wb.excel.api;
|
|
|
|
import com.wb.excel.api.annotation.*;
|
|
|
|
import com.wb.excel.api.annotation.*;
|
|
|
|
import com.wb.excel.api.converter.*;
|
|
|
|
import com.wb.excel.api.converter.*;
|
|
|
|
import com.wb.excel.api.converter.Converter;
|
|
|
|
import com.wb.excel.api.converter.Converter;
|
|
|
|
import com.wb.excel.api.enumeration.Status;
|
|
|
|
|
|
|
|
import com.wb.excel.api.exception.IllegalParameterException;
|
|
|
|
import com.wb.excel.api.exception.IllegalParameterException;
|
|
|
|
import com.wb.excel.api.exception.TemplateNotMatchException;
|
|
|
|
import com.wb.excel.api.exception.TemplateNotMatchException;
|
|
|
|
import com.wb.excel.api.style.*;
|
|
|
|
import com.wb.excel.api.style.*;
|
|
|
|
import com.wb.excel.api.util.ClassUtil;
|
|
|
|
import com.wb.excel.api.util.ClassUtil;
|
|
|
|
import com.wb.excel.api.util.StringUtil;
|
|
|
|
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.*;
|
|
|
@ -108,24 +108,34 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (field.getType() == boolean.class || field.getType() == Boolean.class) {
|
|
|
|
if (field.getType() == boolean.class || field.getType() == Boolean.class) {
|
|
|
|
WColumn.setConverter(new BooleanConverter());
|
|
|
|
WColumn.setConverter(new BooleanConverter());
|
|
|
|
|
|
|
|
WColumn.setCellType(Cell.CELL_TYPE_BOOLEAN);
|
|
|
|
} else if (field.getType() == byte.class || field.getType() == Byte.class) {
|
|
|
|
} else if (field.getType() == byte.class || field.getType() == Byte.class) {
|
|
|
|
WColumn.setConverter(new ByteConverter());
|
|
|
|
WColumn.setConverter(new ByteConverter());
|
|
|
|
|
|
|
|
WColumn.setCellType(Cell.CELL_TYPE_NUMERIC);
|
|
|
|
} else if (field.getType() == char.class || field.getType() == Character.class) {
|
|
|
|
} else if (field.getType() == char.class || field.getType() == Character.class) {
|
|
|
|
WColumn.setConverter(new CharacterConverter());
|
|
|
|
WColumn.setConverter(new CharacterConverter());
|
|
|
|
|
|
|
|
WColumn.setCellType(Cell.CELL_TYPE_STRING);
|
|
|
|
} else if (field.getType() == short.class || field.getType() == Short.class) {
|
|
|
|
} else if (field.getType() == short.class || field.getType() == Short.class) {
|
|
|
|
WColumn.setConverter(new ShortConverter());
|
|
|
|
WColumn.setConverter(new ShortConverter());
|
|
|
|
|
|
|
|
WColumn.setCellType(Cell.CELL_TYPE_NUMERIC);
|
|
|
|
} else if (field.getType() == int.class || field.getType() == Integer.class) {
|
|
|
|
} else if (field.getType() == int.class || field.getType() == Integer.class) {
|
|
|
|
WColumn.setConverter(new IntegerConverter());
|
|
|
|
WColumn.setConverter(new IntegerConverter());
|
|
|
|
|
|
|
|
WColumn.setCellType(Cell.CELL_TYPE_NUMERIC);
|
|
|
|
} else if (field.getType() == long.class || field.getType() == Long.class) {
|
|
|
|
} else if (field.getType() == long.class || field.getType() == Long.class) {
|
|
|
|
WColumn.setConverter(new LongConverter());
|
|
|
|
WColumn.setConverter(new LongConverter());
|
|
|
|
|
|
|
|
WColumn.setCellType(Cell.CELL_TYPE_NUMERIC);
|
|
|
|
} else if (field.getType() == float.class || field.getType() == Float.class) {
|
|
|
|
} else if (field.getType() == float.class || field.getType() == Float.class) {
|
|
|
|
WColumn.setConverter(new FloatConverter());
|
|
|
|
WColumn.setConverter(new FloatConverter());
|
|
|
|
|
|
|
|
WColumn.setCellType(Cell.CELL_TYPE_NUMERIC);
|
|
|
|
} else if (field.getType() == double.class || field.getType() == Double.class) {
|
|
|
|
} else if (field.getType() == double.class || field.getType() == Double.class) {
|
|
|
|
WColumn.setConverter(new DoubleConverter());
|
|
|
|
WColumn.setConverter(new DoubleConverter());
|
|
|
|
|
|
|
|
WColumn.setCellType(Cell.CELL_TYPE_NUMERIC);
|
|
|
|
} else if (field.getType() == Date.class) {
|
|
|
|
} else if (field.getType() == Date.class) {
|
|
|
|
WColumn.setConverter(new DateConverter());
|
|
|
|
WColumn.setConverter(new DateConverter());
|
|
|
|
|
|
|
|
WColumn.setCellType(Cell.CELL_TYPE_NUMERIC);
|
|
|
|
} else if (field.getType() == String.class) {
|
|
|
|
} else if (field.getType() == String.class) {
|
|
|
|
WColumn.setConverter(new StringConverter());
|
|
|
|
WColumn.setConverter(new StringConverter());
|
|
|
|
|
|
|
|
WColumn.setCellType(Cell.CELL_TYPE_STRING);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new RuntimeException("Can not find Converter");
|
|
|
|
throw new RuntimeException("Can not find Converter");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -172,7 +182,8 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
if (null == value) {
|
|
|
|
if (null == value) {
|
|
|
|
row.put(column.getName(), new WCell());
|
|
|
|
row.put(column.getName(), new WCell());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
row.put(column.getName(), new WCell(column.getConverter().string(value)));
|
|
|
|
column.getConverter().string(value);
|
|
|
|
|
|
|
|
row.put(column.getName(), new WCell());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.rowList.add(row);
|
|
|
|
this.rowList.add(row);
|
|
|
@ -231,8 +242,6 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
Row headRow = sheet.getRow(0);
|
|
|
|
Row headRow = sheet.getRow(0);
|
|
|
|
//获取Excel列的总数
|
|
|
|
//获取Excel列的总数
|
|
|
|
int columnSum = headRow.getPhysicalNumberOfCells();
|
|
|
|
int columnSum = headRow.getPhysicalNumberOfCells();
|
|
|
|
//匹配列的数量。用于判断Excel是否包含所有必须列。
|
|
|
|
|
|
|
|
int columnMatchNumber = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//检查列数量
|
|
|
|
//检查列数量
|
|
|
|
List<WColumn> list = initColumns(clazz);
|
|
|
|
List<WColumn> list = initColumns(clazz);
|
|
|
@ -253,7 +262,7 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int maxRowNumber = sheet.getLastRowNum(); //Excel文件的总行数
|
|
|
|
int maxRowNumber = sheet.getLastRowNum(); //Excel文件的总行数
|
|
|
|
/* 逐行读取导入文件的数据 */
|
|
|
|
// 逐行读取导入文件的数据
|
|
|
|
for (int i = 0; i < maxRowNumber; i++) {
|
|
|
|
for (int i = 0; i < maxRowNumber; i++) {
|
|
|
|
Row inputRow = sheet.getRow(i + 1); //Excel中的一行数据,第0行为表头,所以要加1
|
|
|
|
Row inputRow = sheet.getRow(i + 1); //Excel中的一行数据,第0行为表头,所以要加1
|
|
|
|
WRow row = new WRow();
|
|
|
|
WRow row = new WRow();
|
|
|
@ -275,54 +284,22 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
value = value.trim();
|
|
|
|
value = value.trim();
|
|
|
|
|
|
|
|
|
|
|
|
WCell.setValue(value);
|
|
|
|
WCell.setValue(value);
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否必须项
|
|
|
|
|
|
|
|
if (wcolumn.isRequired()) {
|
|
|
|
|
|
|
|
if (value.length() == 0) {
|
|
|
|
|
|
|
|
WCell.setStatus(Status.EMPTY);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查长度是否合法
|
|
|
|
try {
|
|
|
|
// if (wcolumn) {
|
|
|
|
T t = transferOneObject(clazz, i);
|
|
|
|
// if (value.length() > lengths[j].max() || value.length() < lengths[j].min()) {
|
|
|
|
List<String> validate = ValidationUtil.validate(t);
|
|
|
|
// this.setStatus(i, j, Status.LENGTH);
|
|
|
|
if (validate.size() > 0) {
|
|
|
|
// cellFlag = false;
|
|
|
|
for (String s : validate) {
|
|
|
|
// }
|
|
|
|
row.addError(s);
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查字符是否符合正则表达式
|
|
|
|
|
|
|
|
// if (cellFlag && null != columnTypes[j] && !columnTypes[j].value().equals(DataType.STRING)) {
|
|
|
|
|
|
|
|
// if (!DataType.check(columnTypes[j].value(), WCell, value)) {
|
|
|
|
|
|
|
|
// this.setStatus(i, j, Status.FORMAT);
|
|
|
|
|
|
|
|
// cellFlag = false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
row.addError("数据检查错误");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
|
|
|
// * 能过列名取得列下标。
|
|
|
|
|
|
|
|
// *
|
|
|
|
|
|
|
|
// * @param columnName 列名
|
|
|
|
|
|
|
|
// * @return 该列对应的下标
|
|
|
|
|
|
|
|
// * @throws ColumnNameNotExistException
|
|
|
|
|
|
|
|
// */
|
|
|
|
|
|
|
|
// private int getColumnIndex(String columnName) throws ColumnNameNotExistException {
|
|
|
|
|
|
|
|
// int columnIndex = -1;
|
|
|
|
|
|
|
|
// for (int i = 0; i < this.getColumnIndex(); i++) {
|
|
|
|
|
|
|
|
// if (this.columnList.get(i).getName().equals(columnName)) {
|
|
|
|
|
|
|
|
// columnIndex = i;
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (columnIndex == -1) {
|
|
|
|
|
|
|
|
// throw new ColumnNameNotExistException("不存在的列名:" + columnName);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return columnIndex;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 转换某行为一个对象
|
|
|
|
* 转换某行为一个对象
|
|
|
@ -335,8 +312,7 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public T transferOneObject(Class<T> clazz, int rowIndex)
|
|
|
|
public T transferOneObject(Class<T> clazz, int rowIndex) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
|
|
|
|
throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
|
|
|
|
|
|
|
|
T object = clazz.newInstance();
|
|
|
|
T object = clazz.newInstance();
|
|
|
|
ParentFirst parentFirstAnnotation = clazz.getAnnotation(ParentFirst.class);
|
|
|
|
ParentFirst parentFirstAnnotation = clazz.getAnnotation(ParentFirst.class);
|
|
|
|
boolean parentFirst = parentFirstAnnotation != null && parentFirstAnnotation.value();
|
|
|
|
boolean parentFirst = parentFirstAnnotation != null && parentFirstAnnotation.value();
|
|
|
@ -428,9 +404,9 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
// for (int i = 0; i < this.getRowIndex(); i++) {
|
|
|
|
// for (int i = 0; i < this.getRowIndex(); i++) {
|
|
|
|
// for (int j = 0; j < this.getColumnIndex(); j++) {
|
|
|
|
// for (int j = 0; j < this.getColumnIndex(); j++) {
|
|
|
|
// WCell WCell = this.getCell(i, j);
|
|
|
|
// WCell WCell = this.getCell(i, j);
|
|
|
|
// if (this.columnList.get(j).getDataType().equals(DataType.STRING)
|
|
|
|
// if (this.columnList.get(j).getExcelType().equals(ExcelType.STRING)
|
|
|
|
// || this.columnList.get(j).getDataType().equals(DataType.DATE)
|
|
|
|
// || this.columnList.get(j).getExcelType().equals(ExcelType.DATE)
|
|
|
|
// || this.columnList.get(j).getDataType().equals(DataType.DATETIME)) {
|
|
|
|
// || this.columnList.get(j).getExcelType().equals(ExcelType.DATETIME)) {
|
|
|
|
// sb.append("\"\t").append(WCell.getValue()).append("\",");
|
|
|
|
// sb.append("\"\t").append(WCell.getValue()).append("\",");
|
|
|
|
// } else {
|
|
|
|
// } else {
|
|
|
|
// sb.append(WCell.getValue()).append(",");
|
|
|
|
// sb.append(WCell.getValue()).append(",");
|
|
|
@ -449,17 +425,10 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public final boolean hasError() {
|
|
|
|
public final boolean hasError() {
|
|
|
|
for (WRow wRow : rowList) {
|
|
|
|
for (WRow wRow : rowList) {
|
|
|
|
Iterator<WCell> iterator = wRow.values().iterator();
|
|
|
|
if (wRow.hasError()) {
|
|
|
|
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
|
|
|
|
WCell next = iterator.next();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (next.getStatus().name() != Status.PASS.name()) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -479,62 +448,55 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public XSSFWorkbook getExcel(boolean flag) {
|
|
|
|
public byte[] getBytes(boolean checkResult) throws IOException {
|
|
|
|
|
|
|
|
XSSFWorkbook workbook = getExcel(checkResult);
|
|
|
|
|
|
|
|
if (workbook != null) {
|
|
|
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
workbook.write(outputStream);
|
|
|
|
|
|
|
|
return outputStream.toByteArray();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public XSSFWorkbook getExcel(boolean checkResult) {
|
|
|
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
|
|
|
|
|
|
|
|
|
//---------- 创建样式 ------------------
|
|
|
|
//---------- 创建样式 ------------------
|
|
|
|
CellStyle headCellStyle = new HeadCellStyle(workbook).getStyle();
|
|
|
|
CellStyle headCellStyle = new HeadCellStyle(workbook).getStyle();
|
|
|
|
CellStyle errorCellStyle = new ErrorCellStyle(workbook).getStyle();
|
|
|
|
CellStyle alignRightCellStyle = new AlignRightCellStyle(workbook).getStyle();
|
|
|
|
CellStyle errorNumberCellStyle = new ErrorNumberCellStyle(workbook).getStyle();
|
|
|
|
|
|
|
|
CellStyle normalCellStyle = new NormalCellStyle(workbook).getStyle();
|
|
|
|
|
|
|
|
CellStyle normalNumberCellStyle = new NormalNumberCellStyle(workbook).getStyle();
|
|
|
|
|
|
|
|
CellStyle checkMessageCellStyle = new CheckMessageCellStyle(workbook).getStyle();
|
|
|
|
|
|
|
|
CellStyle checkFailureCellStyle = new CheckFailureCellStyle(workbook).getStyle();
|
|
|
|
|
|
|
|
CellStyle checkSuccessCellStyle = new CheckSuccessCellStyle(workbook).getStyle();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----------- 创建字体 ----------------
|
|
|
|
//----------- 创建字体 ----------------
|
|
|
|
|
|
|
|
Font headFont = new HeadFont(workbook).getFont();
|
|
|
|
Font normalFont = new NormalFont(workbook).getFont();
|
|
|
|
Font normalFont = new NormalFont(workbook).getFont();
|
|
|
|
Font redFont = new RedFont(workbook).getFont();
|
|
|
|
Font redFont = new RedFont(workbook).getFont();
|
|
|
|
|
|
|
|
|
|
|
|
//创建一个Sheet表
|
|
|
|
//创建一个Sheet表
|
|
|
|
XSSFSheet sheet = workbook.createSheet(name);
|
|
|
|
XSSFSheet sheet = workbook.createSheet(name);
|
|
|
|
sheet.setDefaultRowHeightInPoints(20);
|
|
|
|
sheet.setDefaultRowHeightInPoints(18);
|
|
|
|
Row firstRow = sheet.createRow(0); // 下标为0的行开始
|
|
|
|
Row firstRow = sheet.createRow(0); // 下标为0的行开始
|
|
|
|
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
|
|
|
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
|
|
|
|
|
|
|
|
|
|
|
//----------------表头--------------------
|
|
|
|
// 错误表头
|
|
|
|
// if (flag) {
|
|
|
|
// if (checkResult) {
|
|
|
|
// // 检查结果栏
|
|
|
|
// // 检查结果栏
|
|
|
|
// org.apache.poi.ss.usermodel.Cell firstCell = firstRow.createCell(0);
|
|
|
|
// Cell firstCell = firstRow.createCell(this.columnList.size());
|
|
|
|
// String columnName = WSheet.CHECK_STATUS_NAME;
|
|
|
|
|
|
|
|
// firstCell.setCellStyle(headCellStyle);
|
|
|
|
// firstCell.setCellStyle(headCellStyle);
|
|
|
|
// firstCell.setCellValue(new XSSFRichTextString(columnName));
|
|
|
|
// firstCell.setCellValue(new XSSFRichTextString("检查结果"));
|
|
|
|
// sheet.setColumnWidth(0, (4 + 8) * 256);
|
|
|
|
// sheet.setColumnWidth(0, (4 + 8) * 256);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// 数据栏
|
|
|
|
|
|
|
|
int hiddenNumber = 0;
|
|
|
|
|
|
|
|
for (int j = 0; j < this.columnList.size(); j++) {
|
|
|
|
for (int j = 0; j < this.columnList.size(); j++) {
|
|
|
|
WColumn column = this.columnList.get(j);
|
|
|
|
WColumn column = this.columnList.get(j);
|
|
|
|
Field field = column.getField();
|
|
|
|
Field field = column.getField();
|
|
|
|
|
|
|
|
Cell firstCell = firstRow.createCell(j);
|
|
|
|
if (column.isHidden()) {
|
|
|
|
|
|
|
|
hiddenNumber++;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int k = j - hiddenNumber;
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
|
|
k++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
org.apache.poi.ss.usermodel.Cell firstCell = firstRow.createCell(k);
|
|
|
|
|
|
|
|
String columnName = column.getName();
|
|
|
|
String columnName = column.getName();
|
|
|
|
XSSFRichTextString textString;
|
|
|
|
XSSFRichTextString textString;
|
|
|
|
if (column.isRequired()) {
|
|
|
|
if (column.isRequired()) {
|
|
|
|
textString = new XSSFRichTextString("*" + columnName);
|
|
|
|
textString = new XSSFRichTextString("*" + columnName);
|
|
|
|
textString.applyFont(0, 1, redFont);
|
|
|
|
textString.applyFont(0, 1, redFont);
|
|
|
|
textString.applyFont(1, textString.length(), normalFont);
|
|
|
|
textString.applyFont(1, textString.length(), headFont);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
textString = new XSSFRichTextString(columnName);
|
|
|
|
textString = new XSSFRichTextString(columnName);
|
|
|
|
textString.applyFont(normalFont);
|
|
|
|
textString.applyFont(headFont);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append(column.getDescription()).append("\n");
|
|
|
|
sb.append(column.getDescription()).append("\n");
|
|
|
@ -555,82 +517,47 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
firstCell.setCellValue(textString);
|
|
|
|
firstCell.setCellValue(textString);
|
|
|
|
firstCell.setCellStyle(headCellStyle);
|
|
|
|
firstCell.setCellStyle(headCellStyle);
|
|
|
|
sheet.setColumnWidth(k, (4 + column.getCellWidth()) * 256);
|
|
|
|
sheet.setColumnWidth(j, (4 + column.getCellWidth()) * 256);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 错误消息栏
|
|
|
|
// 错误消息栏
|
|
|
|
// if (flag) {
|
|
|
|
// if (checkResult) {
|
|
|
|
// org.apache.poi.ss.usermodel.Cell firstCell = firstRow.createCell(table.getColumnIndex() + 1 - hiddenNumber);
|
|
|
|
// Cell firstCell = firstRow.createCell(this.columnList.size());
|
|
|
|
// String columnName = WSheet.CHECK_STATUS_RESULT;
|
|
|
|
|
|
|
|
// firstCell.setCellStyle(headCellStyle);
|
|
|
|
// firstCell.setCellStyle(headCellStyle);
|
|
|
|
// firstCell.setCellValue(new XSSFRichTextString(columnName));
|
|
|
|
// firstCell.setCellValue(new XSSFRichTextString("======================"));
|
|
|
|
// sheet.setColumnWidth(table.getColumnIndex() + 1, (4 + 10) * 256);
|
|
|
|
// sheet.setColumnWidth(this.columnList.size() + 1, (4 + 10) * 256);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// 冻结第一行
|
|
|
|
// 冻结第一行
|
|
|
|
//sheet.createFreezePane(255,1);
|
|
|
|
// sheet.createFreezePane(255,1);
|
|
|
|
|
|
|
|
|
|
|
|
//------------------数据--------------------
|
|
|
|
// 填充数据
|
|
|
|
for (int i = 0; i < this.rowList.size(); i++) {
|
|
|
|
for (int i = 0; i < this.rowList.size(); i++) {
|
|
|
|
|
|
|
|
boolean flag = this.rowList.get(i).;
|
|
|
|
|
|
|
|
WRow wRow = this.rowList.get(i);
|
|
|
|
Row row = sheet.createRow(i + 1);
|
|
|
|
Row row = sheet.createRow(i + 1);
|
|
|
|
boolean rowFlag = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果该行有错误
|
|
|
|
|
|
|
|
// if (flag) {
|
|
|
|
|
|
|
|
// org.apache.poi.ss.usermodel.Cell xssfCell = row.createCell(0);
|
|
|
|
|
|
|
|
// if (table.getRowError(i) != null) {
|
|
|
|
|
|
|
|
// rowFlag = false;
|
|
|
|
|
|
|
|
// xssfCell.setCellValue("不通过");
|
|
|
|
|
|
|
|
// xssfCell.setCellStyle(checkFailureCellStyle);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// xssfCell.setCellValue("通过");
|
|
|
|
|
|
|
|
// xssfCell.setCellStyle(checkSuccessCellStyle);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int j = 0;
|
|
|
|
for (int j = 0; j < this.columnList.size(); j++) {
|
|
|
|
hiddenNumber = 0;
|
|
|
|
|
|
|
|
for (; j < this.columnList.size(); j++) {
|
|
|
|
|
|
|
|
WColumn column = this.columnList.get(j);
|
|
|
|
WColumn column = this.columnList.get(j);
|
|
|
|
if (column.isHidden()) {
|
|
|
|
|
|
|
|
hiddenNumber++;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int k = j - hiddenNumber;
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
|
|
k++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
org.apache.poi.ss.usermodel.Cell xssfCell = row.createCell(k);
|
|
|
|
Cell xssfCell = row.createCell(j);
|
|
|
|
WCell WCell = this.rowList.get(i).get(column.getName());
|
|
|
|
WCell WCell = this.rowList.get(i).get(column.getName());
|
|
|
|
if (null == WCell) {
|
|
|
|
if (null == WCell) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String value = WCell.getValue();
|
|
|
|
String value = WCell.getValue();
|
|
|
|
xssfCell.setCellValue(value);
|
|
|
|
List<String> errorList = wRow.getErrorList();
|
|
|
|
|
|
|
|
xssfCell.setCellType(column.getCellType());
|
|
|
|
|
|
|
|
if (column.getCellType() == Cell.CELL_TYPE_NUMERIC || column.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
|
|
|
|
|
|
|
|
xssfCell.setCellStyle(new AlignRightCellStyle(workbook, wRow.hasError()).getStyle());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
xssfCell.setCellStyle(new NormalCellStyle(workbook, flag).getStyle());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果该列是数字类型,则靠右
|
|
|
|
xssfCell.setCellValue(value);
|
|
|
|
// if (table.getWColumns()[j].getDataType() == DataType.DECIMAL
|
|
|
|
|
|
|
|
// || table.getWColumns()[j].getDataType() == DataType.NUMBER) {
|
|
|
|
|
|
|
|
// if (flag && !WCell.getStatus().equals(Status.PASS)) {
|
|
|
|
|
|
|
|
// xssfCell.setCellStyle(errorNumberCellStyle);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// xssfCell.setCellStyle(normalNumberCellStyle);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// if (flag && !WCell.getStatus().equals(Status.PASS)) {
|
|
|
|
|
|
|
|
// xssfCell.setCellStyle(errorCellStyle);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// xssfCell.setCellStyle(normalCellStyle);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if (flag && !rowFlag) {
|
|
|
|
if (flag)
|
|
|
|
// Cell xssfCell = row.createCell(j + 1 - hiddenNumber);
|
|
|
|
|
|
|
|
// xssfCell.setCellValue(table.getRowError(i));
|
|
|
|
|
|
|
|
// xssfCell.setCellStyle(checkMessageCellStyle);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return workbook;
|
|
|
|
return workbook;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -652,7 +579,9 @@ public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
Date value = cell.getDateCellValue();
|
|
|
|
Date value = cell.getDateCellValue();
|
|
|
|
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(value);
|
|
|
|
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(value);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return String.valueOf(cell.getNumericCellValue());
|
|
|
|
double numericCellValue = cell.getNumericCellValue();
|
|
|
|
|
|
|
|
String s = String.valueOf(numericCellValue);
|
|
|
|
|
|
|
|
return s.replaceAll("\\.0$", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return cell.getStringCellValue();
|
|
|
|
return cell.getStringCellValue();
|
|
|
|