Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cocktail-party-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cocktail-party
cocktail-party-server
Commits
d311d56b
提交
d311d56b
authored
4月 03, 2022
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复Excel注解prompt/combo同时使用不生效问题
上级
3bc5ef38
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
13 行增加
和
40 行删除
+13
-40
ExcelUtil.java
...n/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+13
-40
没有找到文件。
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
浏览文件 @
d311d56b
...
@@ -786,17 +786,10 @@ public class ExcelUtil<T>
...
@@ -786,17 +786,10 @@ public class ExcelUtil<T>
// 设置列宽
// 设置列宽
sheet
.
setColumnWidth
(
column
,
(
int
)
((
attr
.
width
()
+
0.72
)
*
256
));
sheet
.
setColumnWidth
(
column
,
(
int
)
((
attr
.
width
()
+
0.72
)
*
256
));
}
}
// 如果设置了提示信息则鼠标放上去提示.
if
(
StringUtils
.
isNotEmpty
(
attr
.
prompt
())
||
attr
.
combo
().
length
>
0
)
if
(
StringUtils
.
isNotEmpty
(
attr
.
prompt
()))
{
{
// 这里默认设了2-101列提示.
// 提示信息或只能选择不能输入的列内容.
setXSSFPrompt
(
sheet
,
""
,
attr
.
prompt
(),
1
,
100
,
column
,
column
);
setPromptOrValidation
(
sheet
,
attr
.
combo
(),
attr
.
prompt
(),
1
,
100
,
column
,
column
);
}
// 如果设置了combo属性则本列只能选择不能输入
if
(
attr
.
combo
().
length
>
0
)
{
// 这里默认设了2-101列只能选择不能输入.
setXSSFValidation
(
sheet
,
attr
.
combo
(),
1
,
100
,
column
,
column
);
}
}
}
}
...
@@ -860,48 +853,29 @@ public class ExcelUtil<T>
...
@@ -860,48 +853,29 @@ public class ExcelUtil<T>
}
}
/**
/**
* 设置 POI XSSFSheet 单元格提示
* 设置 POI XSSFSheet 单元格提示
或选择框
*
*
* @param sheet 表单
* @param sheet 表单
* @param
promptTitle 提示标题
* @param
textlist 下拉框显示的内容
* @param promptContent 提示内容
* @param promptContent 提示内容
* @param firstRow 开始行
* @param firstRow 开始行
* @param endRow 结束行
* @param endRow 结束行
* @param firstCol 开始列
* @param firstCol 开始列
* @param endCol 结束列
* @param endCol 结束列
*/
*/
public
void
set
XSSFPrompt
(
Sheet
sheet
,
String
promptTitle
,
String
promptContent
,
int
firstRow
,
int
endRow
,
public
void
set
PromptOrValidation
(
Sheet
sheet
,
String
[]
textlist
,
String
promptContent
,
int
firstRow
,
int
endRow
,
int
firstCol
,
int
endCol
)
int
firstCol
,
int
endCol
)
{
{
DataValidationHelper
helper
=
sheet
.
getDataValidationHelper
();
DataValidationHelper
helper
=
sheet
.
getDataValidationHelper
();
DataValidationConstraint
constraint
=
helper
.
createCustomConstraint
(
"DD1"
);
DataValidationConstraint
constraint
=
textlist
.
length
>
0
?
helper
.
createExplicitListConstraint
(
textlist
)
:
helper
.
createCustomConstraint
(
"DD1"
);
CellRangeAddressList
regions
=
new
CellRangeAddressList
(
firstRow
,
endRow
,
firstCol
,
endCol
);
CellRangeAddressList
regions
=
new
CellRangeAddressList
(
firstRow
,
endRow
,
firstCol
,
endCol
);
DataValidation
dataValidation
=
helper
.
createValidation
(
constraint
,
regions
);
DataValidation
dataValidation
=
helper
.
createValidation
(
constraint
,
regions
);
dataValidation
.
createPromptBox
(
promptTitle
,
promptContent
);
if
(
StringUtils
.
isNotEmpty
(
promptContent
))
dataValidation
.
setShowPromptBox
(
true
);
{
sheet
.
addValidationData
(
dataValidation
);
// 如果设置了提示信息则鼠标放上去提示
}
dataValidation
.
createPromptBox
(
""
,
promptContent
);
dataValidation
.
setShowPromptBox
(
true
);
/**
}
* 设置某些列的值只能输入预制的数据,显示下拉框.
*
* @param sheet 要设置的sheet.
* @param textlist 下拉框显示的内容
* @param firstRow 开始行
* @param endRow 结束行
* @param firstCol 开始列
* @param endCol 结束列
* @return 设置好的sheet.
*/
public
void
setXSSFValidation
(
Sheet
sheet
,
String
[]
textlist
,
int
firstRow
,
int
endRow
,
int
firstCol
,
int
endCol
)
{
DataValidationHelper
helper
=
sheet
.
getDataValidationHelper
();
// 加载下拉列表内容
DataValidationConstraint
constraint
=
helper
.
createExplicitListConstraint
(
textlist
);
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList
regions
=
new
CellRangeAddressList
(
firstRow
,
endRow
,
firstCol
,
endCol
);
// 数据有效性对象
DataValidation
dataValidation
=
helper
.
createValidation
(
constraint
,
regions
);
// 处理Excel兼容性问题
// 处理Excel兼容性问题
if
(
dataValidation
instanceof
XSSFDataValidation
)
if
(
dataValidation
instanceof
XSSFDataValidation
)
{
{
...
@@ -912,7 +886,6 @@ public class ExcelUtil<T>
...
@@ -912,7 +886,6 @@ public class ExcelUtil<T>
{
{
dataValidation
.
setSuppressDropDownArrow
(
false
);
dataValidation
.
setSuppressDropDownArrow
(
false
);
}
}
sheet
.
addValidationData
(
dataValidation
);
sheet
.
addValidationData
(
dataValidation
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论