5 apache poi实现excel的动态下拉框功能

news/2024/10/5 14:15:12/

excel_0">excel下拉框

@RequestMapping("xiala")public void xiala(HttpServletResponse response){String fileName = "僵尸表";try{response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");response.setCharacterEncoding("utf-8");response.setHeader("Content-Disposition","attachment;filename=" +URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20") + ".xlsx");Workbook workbook = new XSSFWorkbook();Sheet sheet = workbook.createSheet("Sheet1");String[] dropdownOptions = {"Option 1", "Option 2", "Option 3"};CellRangeAddressList addressList = new CellRangeAddressList(1, 100, 0, 0); // A1单元格。第二行到第100行记录数// 创建数据验证助手DataValidationHelper validationHelper = sheet.getDataValidationHelper();// 创建数据验证约束DataValidationConstraint constraint = validationHelper.createExplicitListConstraint(dropdownOptions);// 创建数据验证对象DataValidation dataValidation = validationHelper.createValidation(constraint, addressList);// 将数据验证添加到表格中sheet.addValidationData(dataValidation);//处罚来源String[] publishType = {"个人", "企业", "33"};CellRangeAddressList publishTypeList = new CellRangeAddressList(1, 100, 1, 1);//A2单元格 处罚来源,第二行到第100行记录数DataValidationConstraint publishTypeConstraint = validationHelper.createExplicitListConstraint(publishType);DataValidation publishValidation = validationHelper.createValidation(publishTypeConstraint, publishTypeList);sheet.addValidationData(publishValidation);OutputStream os = new BufferedOutputStream(response.getOutputStream());workbook.write(os);os.flush();os.close();} catch (IOException e) {e.printStackTrace();} finally {}System.out.println("Excel文件创建成功,包含下拉框!");}

excel_sheet_45">excel sheet的复制

@RequestMapping("list")public void list(HttpServletResponse response) throws Exception{System.out.println("------ 开始下载模板 ------");//获取要下载的模板名称String fileName = URLEncoder.encode("名单导入模板","UTF-8");response.setHeader("Content-Disposition","attachment;filename=" + fileName + ".xlsx");response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");response.setCharacterEncoding("utf-8");//source sheetInputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/template.xlsx");Workbook sourceWorkbook = new XSSFWorkbook(inputStream);Workbook destWorkbook = new XSSFWorkbook();// 获取源工作簿中的第一个工作表Sheet sourceSheet = sourceWorkbook.getSheetAt(0);// 在目标工作簿中创建一个新的工作表Sheet destSheet = destWorkbook.createSheet(sourceSheet.getSheetName());// 复制每一行for (int rowIndex = 0; rowIndex <= sourceSheet.getLastRowNum(); rowIndex++) {Row sourceRow = sourceSheet.getRow(rowIndex);Row destRow = destSheet.createRow(rowIndex);if (sourceRow != null) {// 复制每一列for (int colIndex = 0; colIndex < sourceRow.getLastCellNum(); colIndex++) {Cell sourceCell = sourceRow.getCell(colIndex);Cell destCell = destRow.createCell(colIndex);if (sourceCell != null) {// 复制单元格的样式CellStyle newCellStyle = destWorkbook.createCellStyle();newCellStyle.cloneStyleFrom(sourceCell.getCellStyle());destCell.setCellStyle(newCellStyle);// 复制单元格的值switch (sourceCell.getCellType()) {case STRING:destCell.setCellValue(sourceCell.getStringCellValue());break;case NUMERIC:destCell.setCellValue(sourceCell.getNumericCellValue());break;case BOOLEAN:destCell.setCellValue(sourceCell.getBooleanCellValue());break;case FORMULA:destCell.setCellFormula(sourceCell.getCellFormula());break;case BLANK:destCell.setBlank();break;default:break;}}}}}OutputStream os = new BufferedOutputStream(response.getOutputStream());destWorkbook.write(os);os.flush();os.close();}

excel_114">excel列之间的级联


http://www.ppmy.cn/news/1533938.html

相关文章

小程序兼容问题

【微信小程序】安卓兼容问题&#xff0c;scroll-view上拉导致input输入框上移 引用&#xff1a;https://blog.csdn.net/krico233/article/details/127491690 当一个scroll-view占据全屏高度(100vh)并包含input表单时&#xff0c;输入框聚焦会导致光标上移但输入框本身位置不变…

我博客网站又遭受CC攻击了,记录一下

2024.9.29凌晨4点攻击开始&#xff0c;攻击目标是我的图床tc.zeruns.tech和博客blog.zeruns.tech&#xff0c;图床用的cdn是多吉云融合CDN&#xff0c;流量被刷了20GB左右就触发峰值关闭CDN了&#xff0c;HTTPS请求次数被刷了1.1亿次&#xff0c;因为设置了QPS&#xff0c;实际…

Oracle数据库物理结构操作管理

实验步骤 &#xff08;1&#xff09;查询数据库初始化参数中参数名包含sga的参数的名称、值和描述信息。 SQL> select name,value,description from V$PARAMETER where name like %sga%; &#xff08;2&#xff09;设置sga_max_size的大小为1G SQL> alter system set sg…

ab plc1756连接Profinet 转 EtherNet/IP 网关进行数据交互

Profinet转EtherNet/IP网关在服装工厂中起着至关重要的作用。在服装生产过程中&#xff0c;往往会涉及到多种不同品牌、不同类型的设备&#xff0c;这些设备可能采用不同的通信协议。而Profinet转EtherNet/IP网关就为解决这一问题提供了有效的方案。 据统计&#xff0c;在使用…

OpenCV C++霍夫圆查找

OpenCV 中的霍夫圆检测基于 霍夫变换 (Hough Transform)&#xff0c;它是一种从边缘图像中识别几何形状的算法。霍夫圆检测是专门用于检测图像中的圆形形状的。它通过将图像中的每个像素映射到可能的圆参数空间&#xff0c;来确定哪些像素符合圆形状。 1. 霍夫变换的原理 霍夫…

MongoDB mongoose 的 save、insert 和 create 方法的比较

目录 save 方法 insert 方法 create 方法 使用会话和事务 总结 在本文中&#xff0c;我们将介绍 MongoDB 中使用 mongoose 操作 数据库时的三种常见方法&#xff1a;save、insert 和 create。这些方法可以用于将数据存储到 MongoDB 数据库中&#xff0c;并且在一定程度上具…

【Python】ftfy 使用指南:修复 Unicode 编码问题

ftfy&#xff08;fixes text for you&#xff09;是一个专为修复各种文本编码错误而设计的 Python 工具。它的主要目标是将损坏的 Unicode 文本恢复为正确的 Unicode 格式。ftfy 并非用于处理非 Unicode 编码&#xff0c;而是旨在修复因为编码不一致、解码错误或混合编码导致的…

【保研纪念】计算机保研经验贴——南大cs、复旦cs、中南cs、清深海洋、清软

文章目录 一、个人情况二、经验总结三、夏令营情况1、南京大学计算机学院&#xff08;5月31日-6月2日&#xff09;2、复旦大学计算机学院&#xff08;7月1日-7月4日&#xff09;3、中南大学计算机学院&#xff08;7月5日-7月7日&#xff09;4、武汉大学计算机学院 四、预推免情…