kgdxpr 2 years ago
commit 16d44e93ea

@ -13,6 +13,6 @@ public class TestMergeExcel {
list.add(path); list.add(path);
} }
String fileName = "c:/Test/Result.xlsx"; String fileName = "c:/Test/Result.xlsx";
ExcelCommonUtil.mergeExcel(list, fileName); ExcelCommonUtil.mergeExcel(list, fileName,0);
} }
} }

@ -23,12 +23,12 @@ public class IndexController extends Controller {
private static final Logger log = LoggerFactory.getLogger(IndexController.class); private static final Logger log = LoggerFactory.getLogger(IndexController.class);
@Before({GET.class}) @Before({GET.class})
public void index() { public void apply() {
redirect("/html/ypzs/view/apply.html"); redirect("/html/ypzs/view/apply.html");
} }
@Before({GET.class}) @Before({GET.class})
public void admin() { public void index() {
redirect("/html/login.html"); redirect("/html/login.html");
} }

@ -51,6 +51,8 @@ public class Start extends JFinalConfig {
PropKit.use("application.properties"); PropKit.use("application.properties");
//配置统一的错误页面 //配置统一的错误页面
me.setError404View("/html/common/404/index.html"); me.setError404View("/html/common/404/index.html");
//上传图片大小 <=30MB
me.setMaxPostSize(31457280);
} }
/** /**

@ -9,7 +9,6 @@ import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
import com.jfinal.upload.UploadFile; import com.jfinal.upload.UploadFile;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.ss.util.CellRangeAddressList;
@ -85,17 +84,17 @@ public class ExcelCommonUtil {
page = new Page(list, page.getPageNumber(), page.getPageSize(), page.getTotalPage(), page.getTotalRow()); page = new Page(list, page.getPageNumber(), page.getPageSize(), page.getTotalPage(), page.getTotalRow());
} }
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); XSSFWorkbook XSSfWorkbook = new XSSFWorkbook();
HSSFSheet hssfSheet = hssfWorkbook.createSheet(sheetName); XSSFSheet XSSfSheet = XSSfWorkbook.createSheet(sheetName);
int count = 0; int count = 0;
HSSFRow row = hssfSheet.createRow(count++); XSSFRow row = XSSfSheet.createRow(count++);
HSSFCell cell; XSSFCell cell;
//设置标题字体 //设置标题字体
Font fontTitle = hssfWorkbook.createFont(); Font fontTitle = XSSfWorkbook.createFont();
fontTitle.setFontHeightInPoints((short) 18); //字体大小 fontTitle.setFontHeightInPoints((short) 18); //字体大小
fontTitle.setFontName("黑体"); //字体 fontTitle.setFontName("黑体"); //字体
CellStyle cellStyleTitle = hssfWorkbook.createCellStyle(); CellStyle cellStyleTitle = XSSfWorkbook.createCellStyle();
cellStyleTitle.setFont(fontTitle); cellStyleTitle.setFont(fontTitle);
cellStyleTitle.setVerticalAlignment(VerticalAlignment.CENTER); cellStyleTitle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyleTitle.setAlignment(HorizontalAlignment.CENTER); cellStyleTitle.setAlignment(HorizontalAlignment.CENTER);
@ -107,15 +106,15 @@ public class ExcelCommonUtil {
//合并前N列写上标题 //合并前N列写上标题
CellRangeAddress region = new CellRangeAddress(0, 0, 0, colInfo.size() - 1);// 下标从0开始 起始行号,终止行号, 起始列号,终止列号 CellRangeAddress region = new CellRangeAddress(0, 0, 0, colInfo.size() - 1);// 下标从0开始 起始行号,终止行号, 起始列号,终止列号
//在sheet里增加合并单元格 //在sheet里增加合并单元格
hssfSheet.addMergedRegion(region); XSSfSheet.addMergedRegion(region);
//设置标题的高度 //设置标题的高度
row.setHeight(titleHeight); row.setHeight(titleHeight);
Font txtFont = hssfWorkbook.createFont(); Font txtFont = XSSfWorkbook.createFont();
txtFont.setFontHeightInPoints((short) 14); //字体大小 txtFont.setFontHeightInPoints((short) 14); //字体大小
txtFont.setFontName("宋体"); //字体 txtFont.setFontName("宋体"); //字体
txtFont.setBold(true); txtFont.setBold(true);
CellStyle cellStyleTxt = hssfWorkbook.createCellStyle(); CellStyle cellStyleTxt = XSSfWorkbook.createCellStyle();
cellStyleTxt.setFont(txtFont); cellStyleTxt.setFont(txtFont);
cellStyleTxt.setAlignment(HorizontalAlignment.CENTER); cellStyleTxt.setAlignment(HorizontalAlignment.CENTER);
cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex()); cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex());
@ -129,7 +128,7 @@ public class ExcelCommonUtil {
cellStyleTxt.setFillPattern(FillPatternType.SOLID_FOREGROUND); cellStyleTxt.setFillPattern(FillPatternType.SOLID_FOREGROUND);
//写入表头 //写入表头
row = hssfSheet.createRow(count++); row = XSSfSheet.createRow(count++);
for (int i = 0; i < colInfo.size(); i++) { for (int i = 0; i < colInfo.size(); i++) {
//创建传入进来的表头的个数 //创建传入进来的表头的个数
cell = row.createCell(i); cell = row.createCell(i);
@ -141,7 +140,7 @@ public class ExcelCommonUtil {
cell.setCellStyle(cellStyleTxt); cell.setCellStyle(cellStyleTxt);
//需要显示特殊颜色的话 //需要显示特殊颜色的话
if (jsonObject2.getBoolean("specialColor") != null) { if (jsonObject2.getBoolean("specialColor") != null) {
CellStyle style = hssfWorkbook.createCellStyle(); CellStyle style = XSSfWorkbook.createCellStyle();
style.setFont(txtFont); style.setFont(txtFont);
style.setAlignment(HorizontalAlignment.CENTER); style.setAlignment(HorizontalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.LIME.getIndex()); style.setFillForegroundColor(IndexedColors.LIME.getIndex());
@ -156,13 +155,13 @@ public class ExcelCommonUtil {
cell.setCellStyle(style); cell.setCellStyle(style);
} }
//调转宽度 //调转宽度
hssfSheet.setColumnWidth(i, 256 * width + 184); XSSfSheet.setColumnWidth(i, 256 * width + 184);
} }
//正文与表头不是一个颜色 //正文与表头不是一个颜色
txtFont = hssfWorkbook.createFont(); txtFont = XSSfWorkbook.createFont();
txtFont.setFontHeightInPoints((short) 14); //字体大小 txtFont.setFontHeightInPoints((short) 14); //字体大小
txtFont.setFontName("宋体"); //字体 txtFont.setFontName("宋体"); //字体
cellStyleTxt = hssfWorkbook.createCellStyle(); cellStyleTxt = XSSfWorkbook.createCellStyle();
cellStyleTxt.setFont(txtFont); cellStyleTxt.setFont(txtFont);
cellStyleTxt.setAlignment(HorizontalAlignment.CENTER); cellStyleTxt.setAlignment(HorizontalAlignment.CENTER);
cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex()); cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex());
@ -174,7 +173,7 @@ public class ExcelCommonUtil {
cellStyleTxt.setBorderTop(BorderStyle.THIN); // 上边边框 cellStyleTxt.setBorderTop(BorderStyle.THIN); // 上边边框
//导出数据 //导出数据
for (int i = 0; i < page.getList().size(); i++) { for (int i = 0; i < page.getList().size(); i++) {
row = hssfSheet.createRow(count++); row = XSSfSheet.createRow(count++);
Record record = (Record) page.getList().get(i); Record record = (Record) page.getList().get(i);
for (int j = 0; j < colInfo.size(); j++) { for (int j = 0; j < colInfo.size(); j++) {
JSONObject jsonObject2 = colInfo.getJSONObject(j); JSONObject jsonObject2 = colInfo.getJSONObject(j);
@ -200,14 +199,14 @@ public class ExcelCommonUtil {
//处理隐藏列 //处理隐藏列
if (null != hiddenColumns && hiddenColumns.size() > 0) { if (null != hiddenColumns && hiddenColumns.size() > 0) {
for (Integer hiddenColumn : hiddenColumns) { for (Integer hiddenColumn : hiddenColumns) {
hssfSheet.setColumnHidden(hiddenColumn, true); XSSfSheet.setColumnHidden(hiddenColumn, true);
} }
} }
//生成文件 //生成文件
File file = new File(fileName); File file = new File(fileName);
try { try {
FileOutputStream fileOutputStreane = new FileOutputStream(file); FileOutputStream fileOutputStreane = new FileOutputStream(file);
hssfWorkbook.write(fileOutputStreane); XSSfWorkbook.write(fileOutputStreane);
fileOutputStreane.flush(); fileOutputStreane.flush();
fileOutputStreane.close(); fileOutputStreane.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@ -231,7 +230,7 @@ public class ExcelCommonUtil {
Workbook wb = null; Workbook wb = null;
boolean isValidExcel = false; boolean isValidExcel = false;
try { try {
wb = new HSSFWorkbook(in); wb = new XSSFWorkbook(in);
isValidExcel = true; isValidExcel = true;
} finally { } finally {
if (!isValidExcel && wb != null) { if (!isValidExcel && wb != null) {
@ -256,8 +255,8 @@ public class ExcelCommonUtil {
*/ */
public static void addValidation(String excelFile, String sheetName, int col, String[] subjects) throws IOException { public static void addValidation(String excelFile, String sheetName, int col, String[] subjects) throws IOException {
FileInputStream fis = new FileInputStream(excelFile); FileInputStream fis = new FileInputStream(excelFile);
HSSFWorkbook workbook = new HSSFWorkbook(fis); XSSFWorkbook workbook = new XSSFWorkbook(fis);
HSSFSheet sheet = workbook.getSheet(sheetName); XSSFSheet sheet = workbook.getSheet(sheetName);
DataValidationHelper helper = sheet.getDataValidationHelper(); DataValidationHelper helper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = helper.createExplicitListConstraint(subjects); DataValidationConstraint constraint = helper.createExplicitListConstraint(subjects);
CellRangeAddressList addressList; CellRangeAddressList addressList;
@ -291,7 +290,7 @@ public class ExcelCommonUtil {
case FORMULA: case FORMULA:
try { try {
/* /*
* 使HSSFDateUtil.isCellDateFormatted(cell)cell * 使XSSFDateUtil.isCellDateFormatted(cell)cell
* .getNumericCellValue();java.lang.NumberFormatException * .getNumericCellValue();java.lang.NumberFormatException
*/ */
if (DateUtil.isCellDateFormatted(cell)) { if (DateUtil.isCellDateFormatted(cell)) {
@ -850,9 +849,9 @@ public class ExcelCommonUtil {
* @param fileLists excel * @param fileLists excel
* @param fileName * @param fileName
*/ */
public static void mergeExcel(List<String> fileLists, String fileName) { public static void mergeExcel(List<String> fileLists, String fileName,int whiceRowGetColWidth) {
// 创建新的excel工作簿 // 创建新的excel工作簿
XSSFWorkbook newExcelWorkBook = new XSSFWorkbook(); XSSFWorkbook book = new XSSFWorkbook();
// 遍历需要合并的excel文件 // 遍历需要合并的excel文件
for (String excelName : fileLists) { for (String excelName : fileLists) {
try (InputStream in = new FileInputStream(excelName)) { try (InputStream in = new FileInputStream(excelName)) {
@ -860,18 +859,11 @@ public class ExcelCommonUtil {
XSSFWorkbook tmpWorkBook = new XSSFWorkbook(in); XSSFWorkbook tmpWorkBook = new XSSFWorkbook(in);
// 获取工作簿中的Sheet个数 // 获取工作簿中的Sheet个数
int len = tmpWorkBook.getNumberOfSheets(); int len = tmpWorkBook.getNumberOfSheets();
if (len <= 1) { for (int i = 0; i < len; i++) {
XSSFSheet tmpSheet = tmpWorkBook.getSheetAt(0); XSSFSheet tmpSheet = tmpWorkBook.getSheetAt(i);
XSSFSheet newExcelSheet = newExcelWorkBook.createSheet(tmpSheet.getSheetName()); XSSFSheet newExcelSheet = book.createSheet(tmpSheet.getSheetName());
// 复制sheet内容 // 复制sheet内容
copyExcelSheet(newExcelWorkBook, tmpSheet, newExcelSheet); copyExcelSheet(book, tmpSheet, newExcelSheet,whiceRowGetColWidth);
} else {
for (int i = 0; i < len; i++) {
XSSFSheet tmpSheet = tmpWorkBook.getSheetAt(i);
XSSFSheet newExcelSheet = newExcelWorkBook.createSheet(tmpSheet.getSheetName());
// 复制sheet内容
copyExcelSheet(newExcelWorkBook, tmpSheet, newExcelSheet);
}
} }
// 关闭tmpWorkBook工作簿 // 关闭tmpWorkBook工作簿
tmpWorkBook.close(); tmpWorkBook.close();
@ -892,13 +884,13 @@ public class ExcelCommonUtil {
} }
// 使用输出流写出 // 使用输出流写出
try (FileOutputStream fos = new FileOutputStream(fileName)) { try (FileOutputStream fos = new FileOutputStream(fileName)) {
newExcelWorkBook.write(fos); book.write(fos);
fos.flush(); fos.flush();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
try { try {
newExcelWorkBook.close(); book.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -912,12 +904,12 @@ public class ExcelCommonUtil {
* @param tmpSheet sheet * @param tmpSheet sheet
* @param newExcelSheet sheet * @param newExcelSheet sheet
*/ */
public static void copyExcelSheet(XSSFWorkbook workbook, XSSFSheet tmpSheet, XSSFSheet newExcelSheet) { public static void copyExcelSheet(XSSFWorkbook workbook, XSSFSheet tmpSheet, XSSFSheet newExcelSheet, int whiceRowGetColWidth) {
// 合并单元格 // 合并单元格
mergeSheetAllRegion(tmpSheet, newExcelSheet); mergeSheetAllRegion(tmpSheet, newExcelSheet);
// 设置单元格列宽度 // 设置单元格列宽度
// 获取最后一个单元格位置 // 获取最后一个单元格位置
int len = tmpSheet.getRow(tmpSheet.getFirstRowNum()).getLastCellNum(); int len = tmpSheet.getRow(whiceRowGetColWidth).getLastCellNum();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
newExcelSheet.setColumnWidth(i, tmpSheet.getColumnWidth(i)); newExcelSheet.setColumnWidth(i, tmpSheet.getColumnWidth(i));
} }

@ -6,12 +6,12 @@ import com.aspose.cells.License;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -29,15 +29,13 @@ public class ExcelExportUtil {
* @param page * @param page
* @param jo * @param jo
*/ */
public static void export(Page<?> page, JSONObject jo, String fileName, String title) { public static void export(Page<?> page, JSONObject jo, String fileName, String title, String sheetName) {
//标题 //标题
if (StrKit.isBlank(title)) title = jo.getString("title"); if (StrKit.isBlank(title)) title = jo.getString("title");
//是不是显示序号 //是不是显示序号
String showNumber = jo.getString("showNumber"); String showNumber = jo.getString("showNumber");
//sheet名称 //sheet名称
String sheetName = jo.getString("sheetName"); if (StrKit.isBlank(sheetName)) sheetName = jo.getString("sheetName");
//标题高度 //标题高度
short titleHeight = (short) (jo.getInteger("titleHeight") * 20); short titleHeight = (short) (jo.getInteger("titleHeight") * 20);
//每一行数据的高度 //每一行数据的高度
@ -49,7 +47,7 @@ public class ExcelExportUtil {
JSONObject addjo = new JSONObject(); JSONObject addjo = new JSONObject();
addjo.put("show_column_name", "序号"); addjo.put("show_column_name", "序号");
addjo.put("list_column_name", "Number"); addjo.put("list_column_name", "Number");
addjo.put("width", 20); addjo.put("width", 10);
colInfo.add(0, addjo); colInfo.add(0, addjo);
List<Record> list = new ArrayList<>(); List<Record> list = new ArrayList<>();
for (int i = 0; i < page.getList().size(); i++) { for (int i = 0; i < page.getList().size(); i++) {
@ -60,17 +58,17 @@ public class ExcelExportUtil {
page = new Page(list, page.getPageNumber(), page.getPageSize(), page.getTotalPage(), page.getTotalRow()); page = new Page(list, page.getPageNumber(), page.getPageSize(), page.getTotalPage(), page.getTotalRow());
} }
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
HSSFSheet hssfSheet = hssfWorkbook.createSheet(sheetName); XSSFSheet xssfSheet = xssfWorkbook.createSheet(sheetName);
int count = 0; int count = 0;
HSSFRow row = hssfSheet.createRow(count++); XSSFRow row = xssfSheet.createRow(count++);
HSSFCell cell; XSSFCell cell;
//设置标题字体 //设置标题字体
Font fontTitle = hssfWorkbook.createFont(); Font fontTitle = xssfWorkbook.createFont();
fontTitle.setFontHeightInPoints((short) 18); //字体大小 fontTitle.setFontHeightInPoints((short) 18); //字体大小
fontTitle.setFontName("黑体"); //字体 fontTitle.setFontName("黑体"); //字体
CellStyle cellStyleTitle = hssfWorkbook.createCellStyle(); CellStyle cellStyleTitle = xssfWorkbook.createCellStyle();
cellStyleTitle.setFont(fontTitle); cellStyleTitle.setFont(fontTitle);
cellStyleTitle.setVerticalAlignment(VerticalAlignment.CENTER); cellStyleTitle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyleTitle.setAlignment(HorizontalAlignment.CENTER); cellStyleTitle.setAlignment(HorizontalAlignment.CENTER);
@ -82,15 +80,15 @@ public class ExcelExportUtil {
//合并前N列写上标题 //合并前N列写上标题
CellRangeAddress region = new CellRangeAddress(0, 0, 0, colInfo.size() - 1);// 下标从0开始 起始行号,终止行号, 起始列号,终止列号 CellRangeAddress region = new CellRangeAddress(0, 0, 0, colInfo.size() - 1);// 下标从0开始 起始行号,终止行号, 起始列号,终止列号
//在sheet里增加合并单元格 //在sheet里增加合并单元格
hssfSheet.addMergedRegion(region); xssfSheet.addMergedRegion(region);
//设置标题的高度 //设置标题的高度
row.setHeight(titleHeight); row.setHeight(titleHeight);
Font txtFont = hssfWorkbook.createFont(); Font txtFont = xssfWorkbook.createFont();
txtFont.setFontHeightInPoints((short) 14); //字体大小 txtFont.setFontHeightInPoints((short) 14); //字体大小
txtFont.setFontName("宋体"); //字体 txtFont.setFontName("宋体"); //字体
txtFont.setBold(true); txtFont.setBold(true);
CellStyle cellStyleTxt = hssfWorkbook.createCellStyle(); CellStyle cellStyleTxt = xssfWorkbook.createCellStyle();
cellStyleTxt.setFont(txtFont); cellStyleTxt.setFont(txtFont);
cellStyleTxt.setAlignment(HorizontalAlignment.CENTER); cellStyleTxt.setAlignment(HorizontalAlignment.CENTER);
cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex()); cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex());
@ -102,10 +100,8 @@ public class ExcelExportUtil {
cellStyleTxt.setBorderTop(BorderStyle.THIN); // 上边边框 cellStyleTxt.setBorderTop(BorderStyle.THIN); // 上边边框
cellStyleTxt.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); cellStyleTxt.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
cellStyleTxt.setFillPattern(FillPatternType.SOLID_FOREGROUND); cellStyleTxt.setFillPattern(FillPatternType.SOLID_FOREGROUND);
//写入表头 //写入表头
row = hssfSheet.createRow(count++); row = xssfSheet.createRow(count++);
for (int i = 0; i < colInfo.size(); i++) { for (int i = 0; i < colInfo.size(); i++) {
//创建传入进来的表头的个数 //创建传入进来的表头的个数
cell = row.createCell(i); cell = row.createCell(i);
@ -116,13 +112,13 @@ public class ExcelExportUtil {
cell.setCellValue(jsonObject2.getString("show_column_name")); cell.setCellValue(jsonObject2.getString("show_column_name"));
cell.setCellStyle(cellStyleTxt); cell.setCellStyle(cellStyleTxt);
//调转宽度 //调转宽度
hssfSheet.setColumnWidth(i, 256 * width + 184); xssfSheet.setColumnWidth(i, 256 * width + 184);
} }
//正文与表头不是一个颜色 //正文与表头不是一个颜色
txtFont = hssfWorkbook.createFont(); txtFont = xssfWorkbook.createFont();
txtFont.setFontHeightInPoints((short) 14); //字体大小 txtFont.setFontHeightInPoints((short) 14); //字体大小
txtFont.setFontName("宋体"); //字体 txtFont.setFontName("宋体"); //字体
cellStyleTxt = hssfWorkbook.createCellStyle(); cellStyleTxt = xssfWorkbook.createCellStyle();
cellStyleTxt.setFont(txtFont); cellStyleTxt.setFont(txtFont);
cellStyleTxt.setAlignment(HorizontalAlignment.CENTER); cellStyleTxt.setAlignment(HorizontalAlignment.CENTER);
cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex()); cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex());
@ -134,7 +130,7 @@ public class ExcelExportUtil {
cellStyleTxt.setBorderTop(BorderStyle.THIN); // 上边边框 cellStyleTxt.setBorderTop(BorderStyle.THIN); // 上边边框
//导出数据 //导出数据
for (int i = 0; i < page.getList().size(); i++) { for (int i = 0; i < page.getList().size(); i++) {
row = hssfSheet.createRow(count++); row = xssfSheet.createRow(count++);
Record record = (Record) page.getList().get(i); Record record = (Record) page.getList().get(i);
for (int j = 0; j < colInfo.size(); j++) { for (int j = 0; j < colInfo.size(); j++) {
JSONObject jsonObject2 = colInfo.getJSONObject(j); JSONObject jsonObject2 = colInfo.getJSONObject(j);
@ -149,7 +145,7 @@ public class ExcelExportUtil {
File file = new File(fileName); File file = new File(fileName);
try { try {
FileOutputStream fileOutputStreane = new FileOutputStream(file); FileOutputStream fileOutputStreane = new FileOutputStream(file);
hssfWorkbook.write(fileOutputStreane); xssfWorkbook.write(fileOutputStreane);
fileOutputStreane.flush(); fileOutputStreane.flush();
fileOutputStreane.close(); fileOutputStreane.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@ -164,7 +160,7 @@ public class ExcelExportUtil {
} }
public static HSSFWorkbook export(HSSFWorkbook hssfWorkbook, Page<?> page, JSONObject jo) { public static XSSFWorkbook export(XSSFWorkbook XSSfWorkbook, Page<?> page, JSONObject jo) {
//标题 //标题
String title = jo.getString("title"); String title = jo.getString("title");
@ -195,16 +191,16 @@ public class ExcelExportUtil {
page = new Page(list, page.getPageNumber(), page.getPageSize(), page.getTotalPage(), page.getTotalRow()); page = new Page(list, page.getPageNumber(), page.getPageSize(), page.getTotalPage(), page.getTotalRow());
} }
HSSFSheet hssfSheet = hssfWorkbook.createSheet(sheetName); XSSFSheet XSSfSheet = XSSfWorkbook.createSheet(sheetName);
int count = 0; int count = 0;
HSSFRow row = hssfSheet.createRow(count++); XSSFRow row = XSSfSheet.createRow(count++);
HSSFCell cell; XSSFCell cell;
//设置标题字体 //设置标题字体
Font fontTitle = hssfWorkbook.createFont(); Font fontTitle = XSSfWorkbook.createFont();
fontTitle.setFontHeightInPoints((short) 18); //字体大小 fontTitle.setFontHeightInPoints((short) 18); //字体大小
fontTitle.setFontName("黑体"); //字体 fontTitle.setFontName("黑体"); //字体
CellStyle cellStyleTitle = hssfWorkbook.createCellStyle(); CellStyle cellStyleTitle = XSSfWorkbook.createCellStyle();
cellStyleTitle.setFont(fontTitle); cellStyleTitle.setFont(fontTitle);
cellStyleTitle.setVerticalAlignment(VerticalAlignment.CENTER); cellStyleTitle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyleTitle.setAlignment(HorizontalAlignment.CENTER); cellStyleTitle.setAlignment(HorizontalAlignment.CENTER);
@ -216,15 +212,15 @@ public class ExcelExportUtil {
//合并前N列写上标题 //合并前N列写上标题
CellRangeAddress region = new CellRangeAddress(0, 0, 0, colInfo.size() - 1);// 下标从0开始 起始行号,终止行号, 起始列号,终止列号 CellRangeAddress region = new CellRangeAddress(0, 0, 0, colInfo.size() - 1);// 下标从0开始 起始行号,终止行号, 起始列号,终止列号
//在sheet里增加合并单元格 //在sheet里增加合并单元格
hssfSheet.addMergedRegion(region); XSSfSheet.addMergedRegion(region);
//设置标题的高度 //设置标题的高度
row.setHeight(titleHeight); row.setHeight(titleHeight);
Font txtFont = hssfWorkbook.createFont(); Font txtFont = XSSfWorkbook.createFont();
txtFont.setFontHeightInPoints((short) 14); //字体大小 txtFont.setFontHeightInPoints((short) 14); //字体大小
txtFont.setFontName("宋体"); //字体 txtFont.setFontName("宋体"); //字体
txtFont.setBold(true); txtFont.setBold(true);
CellStyle cellStyleTxt = hssfWorkbook.createCellStyle(); CellStyle cellStyleTxt = XSSfWorkbook.createCellStyle();
cellStyleTxt.setFont(txtFont); cellStyleTxt.setFont(txtFont);
cellStyleTxt.setAlignment(HorizontalAlignment.CENTER); cellStyleTxt.setAlignment(HorizontalAlignment.CENTER);
cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex()); cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex());
@ -239,7 +235,7 @@ public class ExcelExportUtil {
//写入表头 //写入表头
row = hssfSheet.createRow(count++); row = XSSfSheet.createRow(count++);
for (int i = 0; i < colInfo.size(); i++) { for (int i = 0; i < colInfo.size(); i++) {
//创建传入进来的表头的个数 //创建传入进来的表头的个数
cell = row.createCell(i); cell = row.createCell(i);
@ -250,13 +246,13 @@ public class ExcelExportUtil {
cell.setCellValue(jsonObject2.getString("show_column_name")); cell.setCellValue(jsonObject2.getString("show_column_name"));
cell.setCellStyle(cellStyleTxt); cell.setCellStyle(cellStyleTxt);
//调转宽度 //调转宽度
hssfSheet.setColumnWidth(i, 256 * width + 184); XSSfSheet.setColumnWidth(i, 256 * width + 184);
} }
//正文与表头不是一个颜色 //正文与表头不是一个颜色
txtFont = hssfWorkbook.createFont(); txtFont = XSSfWorkbook.createFont();
txtFont.setFontHeightInPoints((short) 14); //字体大小 txtFont.setFontHeightInPoints((short) 14); //字体大小
txtFont.setFontName("宋体"); //字体 txtFont.setFontName("宋体"); //字体
cellStyleTxt = hssfWorkbook.createCellStyle(); cellStyleTxt = XSSfWorkbook.createCellStyle();
cellStyleTxt.setFont(txtFont); cellStyleTxt.setFont(txtFont);
cellStyleTxt.setAlignment(HorizontalAlignment.CENTER); cellStyleTxt.setAlignment(HorizontalAlignment.CENTER);
cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex()); cellStyleTxt.setFillForegroundColor(IndexedColors.LIME.getIndex());
@ -268,7 +264,7 @@ public class ExcelExportUtil {
cellStyleTxt.setBorderTop(BorderStyle.THIN); // 上边边框 cellStyleTxt.setBorderTop(BorderStyle.THIN); // 上边边框
//导出数据 //导出数据
for (int i = 0; i < page.getList().size(); i++) { for (int i = 0; i < page.getList().size(); i++) {
row = hssfSheet.createRow(count++); row = XSSfSheet.createRow(count++);
Record record = (Record) page.getList().get(i); Record record = (Record) page.getList().get(i);
for (int j = 0; j < colInfo.size(); j++) { for (int j = 0; j < colInfo.size(); j++) {
JSONObject jsonObject2 = colInfo.getJSONObject(j); JSONObject jsonObject2 = colInfo.getJSONObject(j);
@ -279,7 +275,7 @@ public class ExcelExportUtil {
row.setHeight(rowHeight); row.setHeight(rowHeight);
} }
} }
return hssfWorkbook; return XSSfWorkbook;
} }
public static boolean getLicense() { public static boolean getLicense() {

@ -17,9 +17,7 @@ import com.jfinal.plugin.activerecord.Record;
import com.jfinal.upload.UploadFile; import com.jfinal.upload.UploadFile;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.UUID;
public class YpController extends Controller { public class YpController extends Controller {
YpModel model = new YpModel(); YpModel model = new YpModel();
@ -232,26 +230,27 @@ public class YpController extends Controller {
ArrayList<String> mergeList = new ArrayList<>(); ArrayList<String> mergeList = new ArrayList<>();
//模板文件 //模板文件
String excelPath = PathKit.getRootClassPath() + PropKit.get("excelExportTemplatePathSuffix").replace("\\", "/"); String excelPath = PathKit.getRootClassPath() + PropKit.get("excelExportTemplatePathSuffix").replace("\\", "/");
String filePath = excelPath + "YangPuZhaoShengExcel.json";
//按班型逐个生成 //按班型逐个生成
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
Record record = list.get(i); Record record = list.get(i);
boolean selected = record.getBoolean("selected");
if (!selected) continue;
int bx_id = record.getInt("bx_id"); int bx_id = record.getInt("bx_id");
String bx_name = record.getStr("bx_name"); String bx_name = record.getStr("bx_name");
String filePath = excelPath + "YangPuZhaoShengExcel_" + bx_id + ".json";
//转成 json对象 //转成 json对象
JSONObject jo = FileUtil.readJsonFile(filePath); JSONObject jo = FileUtil.readJsonFile(filePath);
//导出 //导出
Page<Record> rs = model.getTaskInfo(task_id, bx_id, 1, 99999); Page<Record> rs = model.getTaskInfo(task_id, bx_id, 1, 99999);
String excelFile = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xls"; String excelFile = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xlsx";
ExcelExportUtil.export(rs, jo, excelFile, task_name + "申报结果(" + bx_name + ")"); ExcelExportUtil.export(rs, jo, excelFile, task_name + "申报结果(" + bx_name + ")", bx_name);
mergeList.add(excelFile); mergeList.add(excelFile);
} }
String excelFile = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xls"; String excelFile = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xlsx";
ExcelCommonUtil.mergeExcel(mergeList, excelFile); ExcelCommonUtil.mergeExcel(mergeList, excelFile, 1);
//提供下载 //提供下载
String filename = task_name + "申报结果.xls"; String filename = task_name + "申报结果.xlsx";
renderFile(new File(excelFile), filename); renderFile(new File(excelFile), filename);
} }
@ -267,6 +266,15 @@ public class YpController extends Controller {
renderJson(CommonUtil.returnMessageJson(false, "上传文件类型错误系统只允许上传jpg格式")); renderJson(CommonUtil.returnMessageJson(false, "上传文件类型错误系统只允许上传jpg格式"));
return; return;
} }
//判断文件大小大于20mb则返回错误信息并终止上传删除上传文件
long size = picFile.getFile().length();
if (size > 1024 * 1024 * 20) {
Map map = new HashMap();
map.put("success", false);
map.put("message", "图片文件大小大于20MB,请检查后重传!");
renderJson(map);
return;
}
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
//判断目录是不是存在 //判断目录是不是存在
File file = new File(PathKit.getWebRootPath() + "/upload"); File file = new File(PathKit.getWebRootPath() + "/upload");

@ -8,47 +8,42 @@
{ {
"show_column_name": "申报班型", "show_column_name": "申报班型",
"list_column_name": "bx_name", "list_column_name": "bx_name",
"width": 40 "width": 16
}, },
{ {
"show_column_name": "姓名", "show_column_name": "姓名",
"list_column_name": "name", "list_column_name": "name",
"width": 40 "width": 16
}, },
{ {
"show_column_name": "性别", "show_column_name": "性别",
"list_column_name": "xb", "list_column_name": "xb",
"width": 20 "width": 10
}, },
{ {
"show_column_name": "家庭住址", "show_column_name": "家庭住址",
"list_column_name": "address", "list_column_name": "address",
"width": 50 "width": 36
}, },
{ {
"show_column_name": "父亲姓名", "show_column_name": "父亲姓名",
"list_column_name": "address", "list_column_name": "address",
"width": 40 "width": 20
}, },
{ {
"show_column_name": "母亲姓名", "show_column_name": "母亲姓名",
"list_column_name": "address", "list_column_name": "address",
"width": 40 "width": 16
}, },
{ {
"show_column_name": "身份证号", "show_column_name": "身份证号",
"list_column_name": "sfzh", "list_column_name": "sfzh",
"width": 40 "width": 26
}, },
{ {
"show_column_name": "联系电话", "show_column_name": "联系电话",
"list_column_name": "tel", "list_column_name": "tel",
"width": 40 "width": 20
},
{
"show_column_name": "申报时间",
"list_column_name": "create_time",
"width": 40
} }
] ]
} }

@ -1,54 +0,0 @@
{
"title": "小班招生结果",
"sheetName": "小班",
"titleHeight": 30,
"rowHeight": 30,
"showNumber": true,
"colInfo": [
{
"show_column_name": "申报班型",
"list_column_name": "bx_name",
"width": 40
},
{
"show_column_name": "姓名",
"list_column_name": "name",
"width": 40
},
{
"show_column_name": "性别",
"list_column_name": "xb",
"width": 20
},
{
"show_column_name": "家庭住址",
"list_column_name": "address",
"width": 50
},
{
"show_column_name": "父亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "母亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "身份证号",
"list_column_name": "sfzh",
"width": 40
},
{
"show_column_name": "联系电话",
"list_column_name": "tel",
"width": 40
},
{
"show_column_name": "申报时间",
"list_column_name": "create_time",
"width": 40
}
]
}

@ -1,54 +0,0 @@
{
"title": "中班招生结果",
"sheetName": "中班",
"titleHeight": 30,
"rowHeight": 30,
"showNumber": true,
"colInfo": [
{
"show_column_name": "申报班型",
"list_column_name": "bx_name",
"width": 40
},
{
"show_column_name": "姓名",
"list_column_name": "name",
"width": 40
},
{
"show_column_name": "性别",
"list_column_name": "xb",
"width": 20
},
{
"show_column_name": "家庭住址",
"list_column_name": "address",
"width": 50
},
{
"show_column_name": "父亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "母亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "身份证号",
"list_column_name": "sfzh",
"width": 40
},
{
"show_column_name": "联系电话",
"list_column_name": "tel",
"width": 40
},
{
"show_column_name": "申报时间",
"list_column_name": "create_time",
"width": 40
}
]
}

@ -1,54 +0,0 @@
{
"title": "大班招生结果",
"sheetName": "大班",
"titleHeight": 30,
"rowHeight": 30,
"showNumber": true,
"colInfo": [
{
"show_column_name": "申报班型",
"list_column_name": "bx_name",
"width": 40
},
{
"show_column_name": "姓名",
"list_column_name": "name",
"width": 40
},
{
"show_column_name": "性别",
"list_column_name": "xb",
"width": 20
},
{
"show_column_name": "家庭住址",
"list_column_name": "address",
"width": 50
},
{
"show_column_name": "父亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "母亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "身份证号",
"list_column_name": "sfzh",
"width": 40
},
{
"show_column_name": "联系电话",
"list_column_name": "tel",
"width": 40
},
{
"show_column_name": "申报时间",
"list_column_name": "create_time",
"width": 40
}
]
}

@ -8,47 +8,42 @@
{ {
"show_column_name": "申报班型", "show_column_name": "申报班型",
"list_column_name": "bx_name", "list_column_name": "bx_name",
"width": 40 "width": 16
}, },
{ {
"show_column_name": "姓名", "show_column_name": "姓名",
"list_column_name": "name", "list_column_name": "name",
"width": 40 "width": 16
}, },
{ {
"show_column_name": "性别", "show_column_name": "性别",
"list_column_name": "xb", "list_column_name": "xb",
"width": 20 "width": 10
}, },
{ {
"show_column_name": "家庭住址", "show_column_name": "家庭住址",
"list_column_name": "address", "list_column_name": "address",
"width": 50 "width": 36
}, },
{ {
"show_column_name": "父亲姓名", "show_column_name": "父亲姓名",
"list_column_name": "address", "list_column_name": "address",
"width": 40 "width": 20
}, },
{ {
"show_column_name": "母亲姓名", "show_column_name": "母亲姓名",
"list_column_name": "address", "list_column_name": "address",
"width": 40 "width": 16
}, },
{ {
"show_column_name": "身份证号", "show_column_name": "身份证号",
"list_column_name": "sfzh", "list_column_name": "sfzh",
"width": 40 "width": 26
}, },
{ {
"show_column_name": "联系电话", "show_column_name": "联系电话",
"list_column_name": "tel", "list_column_name": "tel",
"width": 40 "width": 20
},
{
"show_column_name": "申报时间",
"list_column_name": "create_time",
"width": 40
} }
] ]
} }

@ -1,54 +0,0 @@
{
"title": "小班招生结果",
"sheetName": "小班",
"titleHeight": 30,
"rowHeight": 30,
"showNumber": true,
"colInfo": [
{
"show_column_name": "申报班型",
"list_column_name": "bx_name",
"width": 40
},
{
"show_column_name": "姓名",
"list_column_name": "name",
"width": 40
},
{
"show_column_name": "性别",
"list_column_name": "xb",
"width": 20
},
{
"show_column_name": "家庭住址",
"list_column_name": "address",
"width": 50
},
{
"show_column_name": "父亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "母亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "身份证号",
"list_column_name": "sfzh",
"width": 40
},
{
"show_column_name": "联系电话",
"list_column_name": "tel",
"width": 40
},
{
"show_column_name": "申报时间",
"list_column_name": "create_time",
"width": 40
}
]
}

@ -1,54 +0,0 @@
{
"title": "中班招生结果",
"sheetName": "中班",
"titleHeight": 30,
"rowHeight": 30,
"showNumber": true,
"colInfo": [
{
"show_column_name": "申报班型",
"list_column_name": "bx_name",
"width": 40
},
{
"show_column_name": "姓名",
"list_column_name": "name",
"width": 40
},
{
"show_column_name": "性别",
"list_column_name": "xb",
"width": 20
},
{
"show_column_name": "家庭住址",
"list_column_name": "address",
"width": 50
},
{
"show_column_name": "父亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "母亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "身份证号",
"list_column_name": "sfzh",
"width": 40
},
{
"show_column_name": "联系电话",
"list_column_name": "tel",
"width": 40
},
{
"show_column_name": "申报时间",
"list_column_name": "create_time",
"width": 40
}
]
}

@ -1,54 +0,0 @@
{
"title": "大班招生结果",
"sheetName": "大班",
"titleHeight": 30,
"rowHeight": 30,
"showNumber": true,
"colInfo": [
{
"show_column_name": "申报班型",
"list_column_name": "bx_name",
"width": 40
},
{
"show_column_name": "姓名",
"list_column_name": "name",
"width": 40
},
{
"show_column_name": "性别",
"list_column_name": "xb",
"width": 20
},
{
"show_column_name": "家庭住址",
"list_column_name": "address",
"width": 50
},
{
"show_column_name": "父亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "母亲姓名",
"list_column_name": "address",
"width": 40
},
{
"show_column_name": "身份证号",
"list_column_name": "sfzh",
"width": 40
},
{
"show_column_name": "联系电话",
"list_column_name": "tel",
"width": 40
},
{
"show_column_name": "申报时间",
"list_column_name": "create_time",
"width": 40
}
]
}

@ -1,9 +1,9 @@
#家长申报页面 #家长申报页面
http://10.10.21.20:9000/FengHuang http://www.wmarkj.com:27009/FengHuang/apply
#管理页面 #管理页面
http://10.10.21.20:9000/FengHuang/admin http://www.wmarkj.com:27009/FengHuang/
# 业务管理员 # 业务管理员
admin 123456 admin 123456
Loading…
Cancel
Save