poi实现生成下拉选联动

java实现导出省市区三级联动下拉excel 阅读详情
在我们实际的程序开发中,经常需要用到从excel导入数据中系统中,而为了防止用户在excel中乱输入文字,有些需要用到下拉选的地方,就需要从程序中动态生成模板。本例子简单的讲解一下,如何生成级联下拉选。

 

效果图:(选择汽车这个下拉选、后面水果下拉选的值动态改变)


 

级联下拉选的实现步骤:

1.在excel中的另外一个sheet页中,保存着下拉选的值

2.给下拉中的数据创建一个名字( 类似于在excel中操作命名管理器 )

3.使用INDIRECT()函数获取到级联下拉选的值。

4.poi官网上创建级联下拉选的说明



  本例子中,动态excel模板的生成的一个简单思路。

注意:每一个模板字段,都是一个ExportDefinition对象,如果是下拉选的类型,则mainDict字段有值,根据它的值从DictData中加载下拉选的值,如果选择它存在一个级联操作,那么subDict和subField字段有值。subDict也是从DictData中加载数据,subField表示级联的字段

思路:

1.根据一组ExportDefinition定义对象,生成excel的导出模板,此时导出的模板中只有一行到出头数据。

2.创建数据字典页,这个里面保存下拉选需要用到的数据。

3.如果是主下拉选,则给主下拉选创建一个名称管理。

4.如果是主下拉选,并且关联了级联下拉选,则此时需要加载子下拉选的数据,且根据主下拉选中的每一项创建一个名称管理,值为关联的子下拉选的值

5.使用INDIRECT函数、设置数据的有效性等。

 

步骤:

1.创建下拉选的值

Java代码  收藏代码
  1. public class DictData {  
  2.     public static Map<String, Object> dict = null;  
  3.     static {  
  4.         dict = new HashMap<>();  
  5.         List<String> list = new ArrayList<>();  
  6.         list.add("汽车");  
  7.         list.add("水果");  
  8.         dict.put("car-dict", list);  
  9.         Map<String, List<String>> subMap = new HashMap<>();  
  10.         list = new ArrayList<>();  
  11.         list.add("宝马");  
  12.         list.add("大众");  
  13.         subMap.put("汽车", list);  
  14.         list = new ArrayList<>();  
  15.         list.add("苹果");  
  16.         list.add("梨子");  
  17.         subMap.put("水果", list);  
  18.         dict.put("fruit-dict", subMap);  
  19.         list = new ArrayList<>();  
  20.         list.add("汽车-1");  
  21.         list.add("水果-1");  
  22.         dict.put("t-dict", list);  
  23.     }  
  24.   
  25.     /** 获取数据字典中的值 */  
  26.     public static Object getDict(String dict) {  
  27.         return DictData.dict.get(dict);  
  28.     }  
  29. }  

 2.创建一个RowCellIndex对象,用于维护,当前创建了下拉选的第几行第几列

Java代码  收藏代码
  1. public class RowCellIndex {  
  2.     /** 单元格的行索引 */  
  3.     private int rowIndex;  
  4.     /** 单元格的列索引 */  
  5.     private int cellIndex;  
  6.     public RowCellIndex(int rowIndex, int cellIndex) {  
  7.         this.rowIndex = rowIndex;  
  8.         this.cellIndex = cellIndex;  
  9.     }  
  10.     public int getRowIndex() {  
  11.         return rowIndex;  
  12.     }  
  13.     public void setRowIndex(int rowIndex) {  
  14.         this.rowIndex = rowIndex;  
  15.     }  
  16.     public int getCellIndex() {  
  17.         return cellIndex;  
  18.     }  
  19.     public void setCellIndex(int cellIndex) {  
  20.         this.cellIndex = cellIndex;  
  21.     }  
  22.     public int incrementRowIndexAndGet() {  
  23.         this.rowIndex++;  
  24.         return this.getRowIndex();  
  25.     }  
  26.     public int incrementCellIndexAndGet() {  
  27.         this.cellIndex++;  
  28.         return this.getCellIndex();  
  29.     }  
  30. }  

 3.创建一个excel列的导出定义对象,省略部分getter和setter方法

Java代码  收藏代码
  1. public class ExportDefinition {  
  2.     private String title; // 标题  
  3.     private String field; // 字段  
  4.     private int rowIndex; // 所在的行  
  5.     private int cellIndex; // 所在的列  
  6.     private String mainDict; // 主字典-用于加载主字典的数据  
  7.     private String subDict; // 子字典-用于加载subField的数据  
  8.     private String subField; // 即需要级联的字典  
  9.     private String refName; // 主字段所在的位置  
  10.     private String point; // 标题的坐标  
  11.     private boolean validate;// 是否设置数据的有限性  
  12.     public ExportDefinition(String title, String field, String mainDict, String subDict, String subField) {  
  13.         this.title = title;  
  14.         this.field = field;  
  15.         this.mainDict = mainDict;  
  16.         this.subDict = subDict;  
  17.         this.subField = subField;  
  18.     }  

 4.实现导出

Java代码  收藏代码
  1. package com.huan.excel.ex2;  
  2.   
  3. import java.io.FileOutputStream;  
  4. import java.io.IOException;  
  5. import java.io.OutputStream;  
  6. import java.util.ArrayList;  
  7. import java.util.List;  
  8. import java.util.Map;  
  9. import java.util.Map.Entry;  
  10. import java.util.Objects;  
  11.   
  12. import org.apache.poi.hssf.usermodel.DVConstraint;  
  13. import org.apache.poi.hssf.usermodel.HSSFDataValidation;  
  14. import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
  15. import org.apache.poi.hssf.util.CellReference;  
  16. import org.apache.poi.ss.usermodel.DataValidation;  
  17. import org.apache.poi.ss.usermodel.Name;  
  18. import org.apache.poi.ss.usermodel.Row;  
  19. import org.apache.poi.ss.usermodel.Sheet;  
  20. import org.apache.poi.ss.usermodel.Workbook;  
  21. import org.apache.poi.ss.util.CellRangeAddressList;  
  22.   
  23. /** 
  24.  * 生成级联下拉选 
  25.  *  
  26.  * @描述 
  27.  * @作者 huan 
  28.  * @时间 2017年3月31日 - 下午9:14:43 
  29.  */  
  30. public class DropDownListTest {  
  31.   
  32.     private static final String DICT_SHEET = "DICT_SHEET";  
  33.   
  34.     public static void main(String[] args) throws IOException {  
  35.         // 1.准备需要生成excel模板的数据  
  36.         List<ExportDefinition> edList = new ArrayList<>(2);  
  37.         edList.add(new ExportDefinition("生活用品", "xx", null, null, null));  
  38.         edList.add(new ExportDefinition("汽车", "cat", "car-dict", "fruit-dict", "fruit"));  
  39.         edList.add(new ExportDefinition("水果", "fruit", "fruit-dict", "", ""));  
  40.         edList.add(new ExportDefinition("测试", "yy", "t-dict", null, null));  
  41.   
  42.         // 2.生成导出模板  
  43.         Workbook wb = new HSSFWorkbook();  
  44.         Sheet sheet = createExportSheet(edList, wb);  
  45.   
  46.         // 3.创建数据字典sheet页  
  47.         createDictSheet(edList, wb);  
  48.   
  49.         // 4.设置数据有效性  
  50.         setDataValidation(edList, sheet);  
  51.   
  52.         // 5.保存excel到本地  
  53.         OutputStream os = new FileOutputStream("d:/4.xls");  
  54.         wb.write(os);  
  55.   
  56.         System.out.println("模板生成成功.");  
  57.     }  
  58.    public static void createDataValidateSubList(Sheet sheet, ExportDefinition ed) {  
  59.         int rowIndex = ed.getRowIndex();  
  60.         CellRangeAddressList cal;  
  61.         DVConstraint constraint;  
  62.         CellReference cr;  
  63.         DataValidation dataValidation;  
  64.         System.out.println(ed);  
  65.         for (int i = 0; i < 100; i++) {  
  66.             int tempRowIndex = ++rowIndex;  
  67.             cal = new CellRangeAddressList(tempRowIndex, tempRowIndex, ed.getCellIndex(), ed.getCellIndex());  
  68.             cr = new CellReference(rowIndex, ed.getCellIndex() - 1, true, true);  
  69.             constraint = DVConstraint.createFormulaListConstraint("INDIRECT(" + cr.formatAsString() + ")");  
  70.             dataValidation = new HSSFDataValidation(cal, constraint);  
  71.             dataValidation.setSuppressDropDownArrow(false);  
  72.             dataValidation.createPromptBox("操作提示", "请选择下拉选中的值");  
  73.             dataValidation.createErrorBox("错误提示", "请从下拉选中选择,不要随便输入");  
  74.             sheet.addValidationData(dataValidation);  
  75.         }  
  76.     }  
  77.   
  78.     /** 
  79.      * @param edList 
  80.      * @param sheet 
  81.      */  
  82.     private static void setDataValidation(List<ExportDefinition> edList, Sheet sheet) {  
  83.         for (ExportDefinition ed : edList) {  
  84.             if (ed.isValidate()) {// 说明是下拉选  
  85.                 DVConstraint constraint = DVConstraint.createFormulaListConstraint(ed.getField());  
  86.                 if (null == ed.getRefName()) {// 说明是一级下拉选  
  87.                     createDataValidate(sheet, ed, constraint);  
  88.                 } else {// 说明是二级下拉选  
  89.                     createDataValidateSubList(sheet, ed);  
  90.                 }  
  91.             }  
  92.         }  
  93.     }  
  94.   
  95.     /** 
  96.      * @param sheet 
  97.      * @param ed 
  98.      * @param constraint 
  99.      */  
  100.     private static void createDataValidate(Sheet sheet, ExportDefinition ed, DVConstraint constraint) {  
  101.         CellRangeAddressList regions = new CellRangeAddressList(ed.getRowIndex() + 1, ed.getRowIndex() + 100, ed.getCellIndex(), ed.getCellIndex());  
  102.         DataValidation dataValidation = new HSSFDataValidation(regions, constraint);  
  103.         dataValidation.setSuppressDropDownArrow(false);  
  104.         // 设置提示信息  
  105.         dataValidation.createPromptBox("操作提示", "请选择下拉选中的值");  
  106.         // 设置输入错误信息  
  107.         dataValidation.createErrorBox("错误提示", "请从下拉选中选择,不要随便输入");  
  108.         sheet.addValidationData(dataValidation);  
  109.     }  
  110.   
  111.     /** 
  112.      * @param edList 
  113.      * @param wb 
  114.      */  
  115.     private static void createDictSheet(List<ExportDefinition> edList, Workbook wb) {  
  116.         Sheet sheet = wb.createSheet(DICT_SHEET);  
  117.         RowCellIndex rci = new RowCellIndex(0, 0);  
  118.         for (ExportDefinition ed : edList) {  
  119.             String mainDict = ed.getMainDict();  
  120.             if (null != mainDict && null == ed.getRefName()) {// 是第一个下拉选  
  121.                 List<String> mainDictList = (List<String>) DictData.getDict(mainDict);  
  122.                 String refersToFormula = createDictAndReturnRefFormula(sheet, rci, mainDictList);  
  123.                 // 创建 命名管理  
  124.                 createName(wb, ed.getField(), refersToFormula);  
  125.                 ed.setValidate(true);  
  126.             }  
  127.             if (null != mainDict && null != ed.getSubDict() && null != ed.getSubField()) {// 联动时加载ed.getSubField()的数据  
  128.                 ExportDefinition subEd = fiterByField(edList, ed.getSubField());// 获取需要级联的那个字段  
  129.                 if (null == subEd) {  
  130.                     continue;  
  131.                 }  
  132.                 subEd.setRefName(ed.getPoint());// 保存主下拉选的位置  
  133.                 subEd.setValidate(true);  
  134.                 Map<String, List<String>> subDictListMap = (Map<String, List<String>>) DictData.getDict(ed.getSubDict());  
  135.                 for (Entry<String, List<String>> entry : subDictListMap.entrySet()) {  
  136.                     String refersToFormula = createDictAndReturnRefFormula(sheet, rci, entry.getValue());  
  137.                     // 创建 命名管理  
  138.                     createName(wb, entry.getKey(), refersToFormula);  
  139.                 }  
  140.             }  
  141.         }  
  142.     }  
  143.   
  144.     /** 
  145.      * @param sheet 
  146.      * @param rci 
  147.      * @param mainDict 
  148.      * @return 
  149.      */  
  150.     private static String createDictAndReturnRefFormula(Sheet sheet, RowCellIndex rci, List<String> datas) {  
  151.         Row row = sheet.createRow(rci.incrementRowIndexAndGet());  
  152.         rci.setCellIndex(0);  
  153.         int startRow = rci.getRowIndex();  
  154.         int startCell = rci.getCellIndex();  
  155.         for (String dict : datas) {  
  156.             row.createCell(rci.incrementCellIndexAndGet()).setCellValue(dict);  
  157.         }  
  158.         int endRow = rci.getRowIndex();  
  159.         int endCell = rci.getCellIndex();  
  160.         String startName = new CellReference(DICT_SHEET, startRow, startCell, true, true).formatAsString();  
  161.         String endName = new CellReference(endRow, endCell, true, true).formatAsString();  
  162.         String refersToFormula = startName + ":" + endName;  
  163.         System.out.println(refersToFormula);  
  164.         return refersToFormula;  
  165.     }  
  166.   
  167.     /** 
  168.      * @param wb 
  169.      * @param nameName 
  170.      *            表示命名管理的名字 
  171.      * @param refersToFormula 
  172.      */  
  173.     private static void createName(Workbook wb, String nameName, String refersToFormula) {  
  174.         Name name = wb.createName();  
  175.         name.setNameName(nameName);  
  176.         name.setRefersToFormula(refersToFormula);  
  177.     }  
  178.   
  179.     private static ExportDefinition fiterByField(List<ExportDefinition> edList, String field) {  
  180.         for (ExportDefinition ed : edList) {  
  181.             if (Objects.equals(ed.getField(), field)) {  
  182.                 return ed;  
  183.             }  
  184.         }  
  185.         return null;  
  186.     }  
  187.   
  188.     /** 
  189.      * @param edList 
  190.      * @param wb 
  191.      */  
  192.     private static Sheet createExportSheet(List<ExportDefinition> edList, Workbook wb) {  
  193.         Sheet sheet = wb.createSheet("导出模板");  
  194.         RowCellIndex rci = new RowCellIndex(0, 0);  
  195.         Row row = sheet.createRow(rci.getRowIndex());  
  196.         CellReference cr = null;  
  197.         for (ExportDefinition ed : edList) {  
  198.             row.createCell(rci.incrementCellIndexAndGet()).setCellValue(ed.getTitle());  
  199.             ed.setRowIndex(rci.getRowIndex());  
  200.             ed.setCellIndex(rci.getCellIndex());  
  201.             cr = new CellReference(ed.getRowIndex() + 1, ed.getCellIndex(), true, true);  
  202.             ed.setPoint(cr.formatAsString());  
  203.         }  
  204.         return sheet;  
  205.     }  
  206.   
  207. }
POI 导出Excel 下拉列表多级联动(以省市县三级联动为例) 一、主要步骤 1 创建workbook,创建要展示的sheet,即需要用户填写的sheet,设置表头等必须字段 2 创建隐藏sheet,列出下拉列表中需要展示的项信息 3 名称管理器设置name 4 利用名称管理器关联到隐藏sheet中信息 5 设置有效性,添加验证 二、详细步骤 可以先熟悉在excel文件中新建多级联动做法,可参照Excel多级下拉菜单联动自动匹配内容 ( 阅读详情

相关推荐

poi操作excel下拉框联动

jar包 package cn.kk.excel.city; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; import java.util.Map; import org.apache.commons.io.FileUtils; ...

qq_24734797的博客 884

JAVA POI excel 添加下拉字典的方式与案例 以及图文详解及个人理解

由于向单元格(cell)中写入数据时需要先指定行,但行需要先创建出来才能继续,所以这里我的思路是取出字典值最多的一项,并在字典值最长的长度上加 3 (这里加3只是为了兼容第一行的标题行和额外两行作为容错行)做为要创建的行数。二、如果给定的字典值数量以及关联原有列的位置这些都是会改变的,那么就是第二种比较复杂的场景,变量增多计算增多,但这样的代码也有更强的兼容性,但理解需要一定时间。这里我们一般的范围是某一列都需要,在每一行都是这一列,如果你的列是固定的那么直接指定固定的列所在索引即可,在我定义的类。

weixin_44131922的博客 4108

深入Luckfox Pico的Web界面:从Angular前端到CGI后端的RV1106 IPCWeb全栈解析

本文深入解析了基于瑞芯微RV1106芯片的Luckfox Pico设备上,IPCWeb全栈解决方案的架构与部署。详细介绍了如何通过SDK编译配置,将现代Angular前端框架与高效的C++ CGI后端结合,并利用nginx和FastCGI在嵌入式环境中构建稳定、高性能的Web管理界面,为物联网设备开发提供了完整的实战参考。

3a9bq4r8t2y的博客 275

poi导入excel表格实现联动效果

一、主要步骤  1 创建workbook,创建要展示的sheet,即需要用户填写的sheet,设置表头等必须字段  2 创建隐藏sheet,列出下拉列表中需要展示的项信息  3 名称管理器设置name  4 利用名称管理器关联到隐藏sheet中信息  5 设置有效性,添加验证  二、详细步骤  可以先熟悉在excel文件中新建多级联动做法,可参照Excel多级下拉菜单联动自动匹配内容  (http...

weixin_42107940的博客 1926

【OWL部署】Manus又一开源平替OWL真的很好用吗?手把手带你部署并运行你的AI助手OWL(对接Qwen、硅基流动接口)

本文介绍了通用人工智能OWL的部署及国内接口对接,全篇干货满满,手把手教学。

MosuoLc的博客 4041

# YOLOv11改进系列 | 引入仓库自研C3k2_EIEM模块,Sobel边缘分支增强检测细节表达

文章摘要: YOLOv11-seg改进中提出的C3k2_EIEM模块通过引入边缘信息增强机制,显著提升了模型对轮廓和纹理的感知能力。该模块在保持原有C3k2结构的基础上,创新性地结合了Sobel边缘检测分支与常规卷积分支的双路特征融合。核心改进包括:(1)固定Sobel算子提供稳定的梯度响应;(2)并行处理边缘与纹理特征;(3)通过1x1卷积实现特征融合。实验显示,改进后模型参数量增加14.16%,计算量提升12.5%,但显著增强了在复杂边界场景下的分割精度。这种设计特别适用于需要精细轮廓识别的任务,如商品

qq_44224801的博客 95

java导出Excel增加下拉框选项,解决小数据量和大数据量下拉框选项的问题

java导出Excel增加下拉框选项,解决小数据量和大数据量下拉框选项的问题!

IT谢彪的博客 6387

10.2 全栈 CRUD 工程结构搭建:Cursor 4 步初始化 + 3 层目录规范

揭示 Cursor 工程初始化中 4 个关键动作如何将 AI 上下文感知能力从 30% 提升至 85%,包括用 pnpm create 显式声明结构契约、通过 monorepo.config.json 设定 workspace 根以支持跨包类型引用、在 shared 包中固化共享类型与协议,以及后续

weixin_42545292的博客 67

Java生成带3级级联下拉框的Excel模板并导出为文件流

使用Java代码生成带级联关系下拉选的Excel模板并导出为文件流。

CrazyBaymax的博客 706

微信小程序 - 最新将页面可分享到朋友圈功能,小程序实现分享到朋友圈功能,开启分享给好友及分享朋友圈功能(微信小程序怎么分享到朋友圈?详细流程及示例代码教程)

没有设置过分享朋友圈功能的小程序,分享朋友圈按钮是灰色且无法点击。小程序 vue2 | vue3 版本语法都能使用,跟着教程复制代码运行即可。如下图所示,将页面开启分享后便可由用户转发出去。

🏆 前端领域优质创作者 2417

【Prometheus】prometheus结合cAdvisor监控docker容器运行状态,并且实现实时告警通知

Docker的监控,可以使用Docker自带的stats命令来获取当前主机上运行中的容器的资源使用情况。 例如:容器的CPU使用率、内存占用、网络IO以及磁盘IO等指标。

景天科技苑 6万+

java实现导出excel三级联动+下拉框(poi)

java实现导出excel三级联动+下拉框(poi)最终效果java 导入导出excel的几种方式代码实现运行结果解析 最终效果 java 导入导出excel的几种方式 常见有2种方式,一种是jxl,一种是poi. 他们之间的区别: jxl只能支持后缀名为xls的文件。 poi不仅支持xls还支持xlsx格式;提供API对Microsoft Office格式档案读和写的功能。 数据较小时两者没有明显差别;数据量过大时,jxl相对poi来说对jvm虚拟机内存的消耗不高,如果只 是简单的单个exc

钓瞄的鱼的博客 1万+

11、ThingsBoard集群部署k8s

今天终于有时间去搞这个啦,拖了很久了,一直没时间,因为我本地没有那么多机器资源,开虚拟机不够,如果租用阿里云服务器,需要有充值的时间,因为这个费用是按小时付费,需要有连贯的时间来搞才行,今天恰好有时间,就开始搞了,弄成功搞出来了,特地写博客记录下来。

AldrichEugene 990

EasyExcel+POI制作带有有效性校验及下拉联动的Excel模板

名称管理器、indirect公式、数据有效性,我这里使用的是WPS,所以下面会通过WPS来进行举例,微软的Office在类似的位置也有一样的功能,使用Office的同学可以自行研究一下。名称管理器类似于一个数据字典的功能,有名称(key)和引用位置(value的引用)两个主要字段,所谓的引用位置就是需要引用的单元格坐标,单元格可以是1个,也可以是1行或者1列。在当前的需求中姓名和id是一一对应的indirect公式这个公式可以用来引用名称管理器的配置,通过=indirect(名称)数据有效性。

积木成林,聚沙成塔 4751

​非线性分析-增加位移量可能出现下面错误。虽然求解无法在所有时间点完成,但在某些点上仍能够求解部分结果。请参阅“帮助系统”中的故障排除,以了解更多信息详情。由于受约束,规划求解引擎无法收敛

基于收敛状态拆分载荷步‌:在已收敛的载荷步基础上,将未收敛的关键区域拆分为更细的子步,比如在载荷突变点前设置5~10个子步,逐步加载。替换冲突约束为弱约束‌:若存在约束冲突,将刚性约束替换为弱弹簧约束(刚度设为1e-6~1e-4),既限制刚体位移,又不影响结构的变形自由度,命令流:SPRING, NODE, K, 1e-6。部分区域约束完整,但存在未被约束的刚体自由度,或约束类型与大变形/接触逻辑冲突,比如某部件的位移约束在初始阶段有效,但大变形后约束位置脱离实际受力点,导致求解器在该阶段无法收敛。

qq_15963745的博客 144

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

POI 创建联动下拉列表实例

现在很多java企业级应用要求进行数据在Excel上的操作,比较常用的技术是jxl和poi,对比而言两者都是比较简单实用,但在实现下拉列表功能上,jxl的功能接口没有poi的完善,比如实现下拉列表联动技术,就是poi比较简单好用,目前还在网上没有找到能够用jxl实现这个功能,希望读者能够仔细阅读jxl api,以求找到实现这一功能的接口。下面我来大概罗列用poi实现下拉列表联动的思路,然后贴出代码

u013252674的专栏 3531

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

java中poi导出模板下拉框实现二级联动

代码实现如下: 二级联动: package com.test; import java.io.FileOutputStream; import java.util.HashMap; import java.util.Map; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.DataValid...

qq_40312909的博客 3739

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

java excel 下拉框联动_Java下使用Apache POI生成具有三级联动下拉列表的Excel文档

使用Apache POI生成具有三级联动下拉列表的Excel文档;具体效果图与代码如下文。先上效果图:开始贴代码,代码中部分测试数据不影响功能。第一部分(核心业务处理):此部分包含几个方面:获取三级下拉框各列的数据;创建每个下拉功能的名称管理器在隐藏的sheet中生成下拉菜单所需要的row代码如下:/*** 第一部分* 将三个列表所有字段从数据库查询出,并生成名称管理器,存放至隐藏的sheet中*...

weixin_36094492的博客 938

poi下拉框,三级联动

现在网上很多使用poi做excel导出的代码例子,不过我只找到一个三级联动的代码例子,而且几乎所有例子都是默认1,2,3,级菜单名称都不重复的,但是实际上重复很难避免。因为excel的机制是从上到下找匹配的菜单,如果在二级菜单有重复的时候就有可能造成找到的菜单不是我们需要的。所以我用那些现成的...

884

Java使用POI导出Excel实现下拉框联动功能

能看懂的看注释,看不懂的直接复制代码用即可。 引入jar包 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version> </dependency> &lt

菜鸟联盟 6830

POI 导出Excel 下拉列表多级联动

原文:https://blog.youkuaiyun.com/m0_37956938/article/details/78084503 一、主要步骤 1 创建workbook,创建要展示的sheet,即需要用户填写的sheet,设置表头等必须字段 2 创建隐藏sheet,列出下拉列表中需要展示的项信息 3 名称管理器设置name 4 利用名称管理器关联到隐藏sheet中信息 5 设置有效性,添加...

qq_38289633的博客 1471

POI创建联动下拉框的Excel

我们有时候需要在Excel中加入级联下拉框,POI功能很强大,可以实现这样的功能,这里我们使用POI实现一个省市县三级地址的级联下拉框。

mingyonghu的博客 2429

JAVA 通过POI实现Excel的级联下拉

发生情景: 最近使用到了模板导出功能,其中有两个下拉框是有关联的,一开始做完下拉之后,对自己做的并不满意,就考虑实现级联下拉的功能,通过第一个选项的值来决定下一个下拉框的选项范围;于是就有了这一篇文章,话不多说,贴代码~! 代码: maven引入POI的包,注意两个包的版本需一致,不然会报错。 <dependency> <groupId>org.apache.poi</groupId> <artifactId&

weixin_44873050的博客 3880

poi怎么设置某个单元格为下拉框_Java 使用POI生成带联动下拉框的excel表格实例代码...

废话不多说了,直接给大家贴代码了,具体代码如下所示:import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import ...

weixin_39816141的博客 420
上一篇: jquery easyui datagrid view detailview 使用
下一篇: Windows7安装和配置MySql5.7.11
rmnjava
博客等级 码龄20年 8粉丝 5原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值