|
|
|
@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.dsideal.QingLong.Collect.Const.DataTypeConst;
|
|
|
|
|
import com.dsideal.QingLong.Util.ChineseCharacterUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.CommonUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.PoiUtil;
|
|
|
|
|
import com.jfinal.kit.Kv;
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
@ -485,11 +486,11 @@ public class CollectModel {
|
|
|
|
|
String colName = _map.get(j).getStr("column_name");
|
|
|
|
|
|
|
|
|
|
//cell可能是被合并的单元格
|
|
|
|
|
if (isMerged(sheet, cell)) {
|
|
|
|
|
String value = getValue(cell).toString();
|
|
|
|
|
if (PoiUtil.isMerged(sheet, cell)) {
|
|
|
|
|
String value = PoiUtil.getValue(cell).toString();
|
|
|
|
|
if (StrKit.isBlank(value)) {
|
|
|
|
|
for (int k = i - 1; ; k--) {
|
|
|
|
|
String prev = getValue(sheet.getRow(k).getCell(j)).toString();
|
|
|
|
|
String prev = PoiUtil.getValue(sheet.getRow(k).getCell(j)).toString();
|
|
|
|
|
if (!StrKit.isBlank(prev)) {
|
|
|
|
|
value = prev;
|
|
|
|
|
break;
|
|
|
|
@ -499,13 +500,13 @@ public class CollectModel {
|
|
|
|
|
writeRecord.set(colName, value);
|
|
|
|
|
} else {
|
|
|
|
|
if (colType.equals("Integer"))
|
|
|
|
|
writeRecord.set(colName, (int) Double.parseDouble(getValue(cell).toString()));
|
|
|
|
|
writeRecord.set(colName, (int) Double.parseDouble(PoiUtil.getValue(cell).toString()));
|
|
|
|
|
else if (colType.equals("String"))
|
|
|
|
|
writeRecord.set(colName, getValue(cell).toString());
|
|
|
|
|
writeRecord.set(colName, PoiUtil.getValue(cell).toString());
|
|
|
|
|
else if (colType.equals("Double"))
|
|
|
|
|
writeRecord.set(colName, Double.parseDouble(getValue(cell).toString()));
|
|
|
|
|
writeRecord.set(colName, Double.parseDouble(PoiUtil.getValue(cell).toString()));
|
|
|
|
|
else if (colType.equals("Date")) {
|
|
|
|
|
String dateString = getValue(cell).toString();
|
|
|
|
|
String dateString = PoiUtil.getValue(cell).toString();
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
Date date = dateFormat.parse(dateString);
|
|
|
|
|
writeRecord.set(colName, date);
|
|
|
|
@ -703,212 +704,6 @@ public class CollectModel {
|
|
|
|
|
return Db.findFirst(sql, job_id, bureau_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:对于指定Cell中文字进行加红色(*)提醒
|
|
|
|
|
*
|
|
|
|
|
* @param wb
|
|
|
|
|
* @param cell
|
|
|
|
|
*/
|
|
|
|
|
public void addStar(XSSFWorkbook wb, XSSFCell cell) {
|
|
|
|
|
XSSFFont fontRed = wb.createFont();//第一种字体
|
|
|
|
|
fontRed.setBold(true);
|
|
|
|
|
fontRed.setColor(IndexedColors.RED.getIndex());
|
|
|
|
|
fontRed.setFontHeightInPoints((short) 14);
|
|
|
|
|
fontRed.setFontName("黑体");
|
|
|
|
|
|
|
|
|
|
XSSFFont fontBlack = wb.createFont();//第二种字体
|
|
|
|
|
fontBlack.setColor(IndexedColors.BLACK.getIndex());
|
|
|
|
|
fontBlack.setFontName("宋体");
|
|
|
|
|
fontRed.setBold(true);
|
|
|
|
|
fontBlack.setFontHeightInPoints((short) 12);
|
|
|
|
|
String txt = cell.getStringCellValue();
|
|
|
|
|
|
|
|
|
|
int len = txt.length();
|
|
|
|
|
if (len == 0) {
|
|
|
|
|
System.out.println(cell.getSheet().getSheetName());
|
|
|
|
|
System.out.println(cell.getRowIndex() + " " + cell.getColumnIndex());
|
|
|
|
|
System.out.println(cell.getStringCellValue());
|
|
|
|
|
System.out.println("发现问题:" + txt);
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
txt += "(*)";
|
|
|
|
|
XSSFRichTextString richText = new XSSFRichTextString(txt);//全部文字
|
|
|
|
|
|
|
|
|
|
richText.applyFont(0, len - 1, fontBlack); // 从第0个字符到第2个字符应用font1
|
|
|
|
|
richText.applyFont(len, len + 3, fontRed); // 从第2个字符到第4个字符应用font2
|
|
|
|
|
cell.setCellValue(richText);//设置文字
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:给指定单元格加边框
|
|
|
|
|
*
|
|
|
|
|
* @param wb
|
|
|
|
|
* @param cell
|
|
|
|
|
*/
|
|
|
|
|
public void fillColor(Workbook wb, Cell cell, short colorIdx) {
|
|
|
|
|
// 创建单元格样式
|
|
|
|
|
CellStyle style = wb.createCellStyle();
|
|
|
|
|
style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
|
style.setBorderTop(BorderStyle.THIN);
|
|
|
|
|
style.setBorderBottom(BorderStyle.THIN);
|
|
|
|
|
style.setBorderLeft(BorderStyle.THIN);
|
|
|
|
|
style.setBorderRight(BorderStyle.THIN);
|
|
|
|
|
// 创建字体样式
|
|
|
|
|
Font font = wb.createFont();
|
|
|
|
|
font.setFontName("宋体");//字体
|
|
|
|
|
font.setBold(true);//加粗
|
|
|
|
|
font.setFontHeightInPoints((short) 12);//字号
|
|
|
|
|
style.setFont(font);
|
|
|
|
|
// 设置背景颜色
|
|
|
|
|
style.setFillForegroundColor(colorIdx);
|
|
|
|
|
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
|
// 应用样式到单元格
|
|
|
|
|
cell.setCellStyle(style);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:移除所有批注信息
|
|
|
|
|
*
|
|
|
|
|
* @param sheet
|
|
|
|
|
*/
|
|
|
|
|
public void RemoveAllComment(XSSFSheet sheet) {
|
|
|
|
|
// 遍历所有行和单元格,移除批注
|
|
|
|
|
for (Row row : sheet) {
|
|
|
|
|
for (Cell cell : row) {
|
|
|
|
|
if (cell.getCellComment() != null) {
|
|
|
|
|
cell.removeCellComment();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:将指定Sheet表中所有数据区域进行样式还原
|
|
|
|
|
*
|
|
|
|
|
* @param wb
|
|
|
|
|
* @param sheet
|
|
|
|
|
*/
|
|
|
|
|
public void resetStyle(XSSFWorkbook wb, XSSFSheet sheet, int dataStartRow) {
|
|
|
|
|
// 遍历所有行和单元格,移除批注
|
|
|
|
|
for (int row = dataStartRow; row <= sheet.getLastRowNum(); row++) {
|
|
|
|
|
for (int col = 0; col < sheet.getRow(row).getLastCellNum(); col++) {
|
|
|
|
|
Cell cell = sheet.getRow(row).getCell(col);
|
|
|
|
|
fillColor(wb, cell, IndexedColors.WHITE.getIndex());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:修改指定单元格的样式
|
|
|
|
|
*
|
|
|
|
|
* @param wb
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public void addComment(Workbook wb, Cell cell, String str) {
|
|
|
|
|
Sheet sheet = cell.getSheet();
|
|
|
|
|
// 判断单元格上是否存在批注
|
|
|
|
|
if (cell.getCellComment() != null) {
|
|
|
|
|
// 如果存在批注,先删除
|
|
|
|
|
cell.removeCellComment();
|
|
|
|
|
}
|
|
|
|
|
// 创建批注
|
|
|
|
|
Drawing<?> drawing = sheet.createDrawingPatriarch();
|
|
|
|
|
CreationHelper factory = wb.getCreationHelper();
|
|
|
|
|
ClientAnchor anchor = factory.createClientAnchor();
|
|
|
|
|
anchor.setCol1(cell.getColumnIndex());
|
|
|
|
|
anchor.setCol2(cell.getColumnIndex() + 2);
|
|
|
|
|
anchor.setRow1(cell.getRow().getRowNum());
|
|
|
|
|
anchor.setRow2(cell.getRow().getRowNum() + 3);
|
|
|
|
|
Comment comment = drawing.createCellComment(anchor);
|
|
|
|
|
comment.setString(factory.createRichTextString(str));
|
|
|
|
|
// 将批注添加到单元格
|
|
|
|
|
cell.setCellComment(comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:在EXCEL的指定范围内添加上下拉框,内容通过String[]提供
|
|
|
|
|
*
|
|
|
|
|
* @param workbook
|
|
|
|
|
* @param sheetIdx
|
|
|
|
|
* @param firstRow
|
|
|
|
|
* @param lastRow
|
|
|
|
|
* @param firstCol
|
|
|
|
|
* @param lastCol
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public void addValidation(Workbook workbook, int sheetIdx, String options, int firstRow, int lastRow, int firstCol, int lastCol) {
|
|
|
|
|
String[] optionArray = options.split(",");
|
|
|
|
|
Sheet sheet = workbook.getSheetAt(sheetIdx);
|
|
|
|
|
|
|
|
|
|
// 删除已有的校验
|
|
|
|
|
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
|
|
|
|
|
DataValidationConstraint dvConstraint = dvHelper.createCustomConstraint("DELETE_ALL");
|
|
|
|
|
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0); // 设置一个范围,例如整个表格范围
|
|
|
|
|
DataValidation validation = dvHelper.createValidation(dvConstraint, addressList);
|
|
|
|
|
validation.setSuppressDropDownArrow(true);
|
|
|
|
|
sheet.addValidationData(validation);
|
|
|
|
|
|
|
|
|
|
// 创建数据验证对象
|
|
|
|
|
DataValidationHelper validationHelper = sheet.getDataValidationHelper();
|
|
|
|
|
DataValidationConstraint constraint = validationHelper.createExplicitListConstraint(optionArray);
|
|
|
|
|
addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol); // 指定单元格范围
|
|
|
|
|
validation = validationHelper.createValidation(constraint, addressList);
|
|
|
|
|
// 应用数据验证到单元格
|
|
|
|
|
sheet.addValidationData(validation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取指定Cell的内容值
|
|
|
|
|
*
|
|
|
|
|
* @param cell
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Object getValue(XSSFCell cell) {
|
|
|
|
|
switch (cell.getCellType()) {
|
|
|
|
|
case CellType.STRING:
|
|
|
|
|
String cellValueString = cell.getStringCellValue();
|
|
|
|
|
return cellValueString;
|
|
|
|
|
case CellType.NUMERIC:
|
|
|
|
|
//日期格式
|
|
|
|
|
if (DateUtil.isCellDateFormatted(cell)) {
|
|
|
|
|
Date dateValue = cell.getDateCellValue();
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
String formattedDate = sdf.format(dateValue);
|
|
|
|
|
return formattedDate;
|
|
|
|
|
}
|
|
|
|
|
double cellValueNumeric = cell.getNumericCellValue();
|
|
|
|
|
return cellValueNumeric;
|
|
|
|
|
case CellType.BOOLEAN:
|
|
|
|
|
boolean cellValueBoolean = cell.getBooleanCellValue();
|
|
|
|
|
return cellValueBoolean;
|
|
|
|
|
case CellType.BLANK:
|
|
|
|
|
cellValueString = cell.getStringCellValue();
|
|
|
|
|
return cellValueString;
|
|
|
|
|
// 其他类型的处理
|
|
|
|
|
default:
|
|
|
|
|
cellValueString = cell.getStringCellValue();
|
|
|
|
|
return cellValueString;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:判断一个单元格是不是被合并了
|
|
|
|
|
*
|
|
|
|
|
* @param sheet
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean isMerged(XSSFSheet sheet, XSSFCell cell) {
|
|
|
|
|
// 判断单元格是否被合并
|
|
|
|
|
for (CellRangeAddress range : sheet.getMergedRegions()) {
|
|
|
|
|
if (cell.getRowIndex() >= range.getFirstRow() && cell.getRowIndex() <= range.getLastRow()
|
|
|
|
|
&& cell.getColumnIndex() >= range.getFirstColumn() && cell.getColumnIndex() <= range.getLastColumn()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取任务列表,支持关键字查询
|
|
|
|
|