通过POI设置Excel级联导出

本文介绍了如何通过Excel设置数据级联,包括一级、二级及多级,详细阐述了从手动设置到代码实现的过程。首先在Excel中新建sheet并设置固定模式,然后设置数据有效性以实现级联效果。接着,通过Apache POI库在Java代码中创建Workbook并设置级联数据有效性。最后,探讨了如何实现选择更改时自动清除子级联相关数据的方法,涉及VBA宏代码的应用。
摘要由CSDN通过智能技术生成

1:如何通过Excel设置数据级联(包括一级级联、二级级联以及多级级联)
我希望填写者能够按照固定的模式填写性别、省、市,而且市这一列填写内容必须随着省这一列发生动态改变。
在这里插入图片描述
Step1: 在当前excel中新建一个sheet,依次填写对应列的固定模式(此处性别这一列对应的固定模式为男/女,省这一列对应的固定模式为四川省/广西省,四川省对应的市有成都/眉山,广西省对应的市有河池/北海),通过ctrl+F3设置每一行的名称
在这里插入图片描述
Step2:设置目标列的数据有效性,如果当前为一级级联,如省这一列,设置数据有效性的来源为(=省份,此处的省份就是在step1中设置的名称);如果当前列为二级级联,如市这一列,则设置数据有效性的来源为(=INDIRECT($C2) ,此处的$C2就是指省这一列)
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Excel 三级 联动 下拉框 宏代码 实例 代码注释 先在第一个下拉框加入一个valiation, 内容是 =$A$2:$A$5 Private Sub Worksheet_Change(ByVal Target As Range) ' Call back function which defined within according worksheet Dim i As Integer Dim tempStr As String Dim firstDrawBoxRowCount As Integer Dim firstDrawBoxColumn As Integer firstDrawBoxRowCount = 4 'Define the row number of first draw box firstDrawBoxColumn = 1 'Define the column number of ifrst draw box Dim secondDrawBoxRowCount As Integer Dim secondDrawBoxColumn As Integer secondDrawBoxRowCount = 33 'Define the row number of second draw box secondDrawBoxColumn = 4 'Define the column number of second draw box If Target.Column = 1 Then 'This defines the first column of draw box list, you can also define the row number of draw box list Cells(Target.Row, Target.Column + 1) = "" ' Do the clean first Cells(Target.Row, Target.Column + 1).Validation.Delete Cells(Target.Row, Target.Column + 2) = "" Cells(Target.Row, Target.Column + 2).Validation.Delete For i = 2 To firstDrawBoxRowCount + 1 'Enter the cycle to find out the content for column 2 If Trim(Cells(Target.Row, Target.Column)) = Trim(Cells(i, firstDrawBoxColumn)) Then tempStr = Trim(Cells(i, firstDrawBoxColumn + 1)) 'Find out the options for second draw box, it is seperated by , Cells(Target.Row, Target.Column + 1).Select ' Fill the validation to second draw box With Selection.Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:=tempStr .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .IMEMode = xlIMEModeNoControl .ShowInput = True .ShowError = True
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值