EasyExcel导出创建Excel下拉框
EasyExcel导出创建Excel下拉框话不多说,上才艺。
下⾯代码粘贴即⽤
/**
*
* 导出表格带下拉框
*/
@GetMapping("exportBox")
public void export(HttpServletResponse response)
throws IOException
{
String fileName = "模板.xls";
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
// 设置背景颜⾊
headWriteCellStyle.setFillForegroundColor(Index());
// 设置头字体
WriteFont headWriteFont = new WriteFont();
headWriteFont.setFontHeightInPoints((short)14);
// 字体加粗
headWriteFont.setBold(true);
headWriteCellStyle.setWriteFont(headWriteFont);
// 设置头居中
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
/
/ 内容策略
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
// 设置内容字体
WriteFont contentWriteFont = new WriteFont();
contentWriteFont.setFontHeightInPoints((short)12);冰封王座 地图
contentWriteFont.setFontName("宋体");
contentWriteCellStyle.setWriteFont(contentWriteFont);
// 设置⽔平居中
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// 设置垂直居中
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
七年级数学第一单元测试题>碱性水
/
/ 设置单元格格式为⽂本
contentWriteCellStyle.setDataFormat((short)49);
HorizontalCellStyleStrategy horizontalCellStyleStrategy =
new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);出卖我的爱歌词
// 假数据实际开发中⼀般是从数据库中查询
List<Employee> objects = new ArrayList<>();
for (int i = 0; i < 3; i++)
{
Employee employee = new Employee();
employee.setSchool(i + "⼤学");
employee.setName(i + "RR");
objects.add(employee);
}
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=" + de(fileName, "UTF-8"));
// 设置表名,引脚名,⽂件格式,list数据
EasyExcel.OutputStream(), Employee.class)
.registerWriteHandler(horizontalCellStyleStrategy)
.registerWriteHandler(new SpinnerWriteHandler())
.sheet("模板")
.doWrite(objects);
}
controller
porary.handle;
import l.write.handler.SheetWriteHandler;
import adata.holder.WriteSheetHolder;
import adata.holder.WriteWorkbookHolder;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import java.util.HashMap;
import java.util.Map;
/
**
* @author Han
* @Description
* @date 2022/3/21
*/
public class SpinnerWriteHandler implements SheetWriteHandler
{
@Override
public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder)    {
}
@Override
public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder)    {
String[] ageTypes = new String[] {"0 - 14", "15 - 25", "26 - 50", "51 - ~"};
String[] schoolTypes = new String[] {"清华⼤学", "北京⼤学", "郑州⼤学", "南京⼤学"};
Map<Integer, String[]> mapDropDown = new HashMap<>();
// 这⾥的key值对应导出列的顺序从0开始
mapDropDown.put(1, ageTypes);
mapDropDown.put(2, schoolTypes);
Sheet sheet = Sheet();
/// 开始设置下拉框
DataValidationHelper helper = DataValidationHelper();// 设置下拉框简单网名大全
for (Map.Entry<Integer, String[]> entry : Set())
{
/*** 起始⾏、终⽌⾏、起始列、终⽌列 **/
CellRangeAddressList addressList = new CellRangeAddressList(1, 1000, Key(), Key());
/*** 设置下拉框数据 **/
DataValidationConstraint constraint = Value());国标舞分类
DataValidation dataValidation = ateValidation(constraint, addressList);
/*** 处理Excel兼容性问题 **/
if (dataValidation instanceof XSSFDataValidation)
{
dataValidation.setSuppressDropDownArrow(true);
dataValidation.setShowErrorBox(true);
}
else
{
dataValidation.setSuppressDropDownArrow(false);
}
sheet.addValidationData(dataValidation);
}
}
}
Handle

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。