Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
entrance_api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王琮
entrance_api
Commits
685bf41b
Commit
685bf41b
authored
Jan 05, 2023
by
王琮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改员工导出模板
parent
5f1fffbf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
12 deletions
+55
-12
CyEpExcelUtil.java
...main/java/org/rcisoft/sys/sysuser/util/CyEpExcelUtil.java
+55
-12
No files found.
src/main/java/org/rcisoft/sys/sysuser/util/CyEpExcelUtil.java
View file @
685bf41b
...
...
@@ -12,10 +12,11 @@ import org.apache.poi.hssf.usermodel.DVConstraint;
import
org.apache.poi.hssf.usermodel.HSSFDataValidation
;
import
org.apache.poi.hssf.usermodel.HSSFSheet
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Name
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.ss.util.CellRangeAddressList
;
import
org.rcisoft.core.exception.CyServiceException
;
import
org.rcisoft.sys.sysuser.dto.ExcelDTO
;
...
...
@@ -152,8 +153,7 @@ public class CyEpExcelUtil {
List
<
T
>
list
=
null
;
try
{
list
=
ExcelImportUtil
.
importExcel
(
file
.
getInputStream
(),
pojoClass
,
params
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
CyServiceException
(
502
,
"模板格式错误"
);
}
return
list
;
...
...
@@ -180,27 +180,43 @@ public class CyEpExcelUtil {
private
static
void
defaultExportSelect
(
List
<?>
list
,
Class
<?>
pojoClass
,
String
fileName
,
HttpServletResponse
response
,
ExportParams
exportParams
,
ExcelDTO
excelDto
)
{
Workbook
workbook
=
ExcelExportUtil
.
exportExcel
(
exportParams
,
pojoClass
,
list
);
workbook
.
createSheet
(
"hidden"
);
if
(
excelDto
!=
null
&&
null
!=
excelDto
.
getSex
()
&&
excelDto
.
getSex
().
length
>
0
)
{
CyEpExcelUtil
.
selectList
(
workbook
,
3
,
510
,
1
,
1
,
excelDto
.
getSex
());
CyEpExcelUtil
.
selectList
(
workbook
,
3
,
510
,
1
,
1
,
excelDto
.
getSex
()
,
"sex"
);
}
if
(
excelDto
!=
null
&&
null
!=
excelDto
.
getDeptName
()
&&
excelDto
.
getDeptName
().
length
>
0
)
{
CyEpExcelUtil
.
selectList
(
workbook
,
3
,
510
,
4
,
4
,
excelDto
.
getDeptName
());
CyEpExcelUtil
.
selectList
(
workbook
,
3
,
510
,
4
,
4
,
excelDto
.
getDeptName
()
,
"dept"
);
}
if
(
excelDto
!=
null
&&
null
!=
excelDto
.
getYq
()
&&
excelDto
.
getYq
().
length
>
0
)
{
CyEpExcelUtil
.
selectList
(
workbook
,
3
,
510
,
3
,
3
,
excelDto
.
getYq
());
CyEpExcelUtil
.
selectList
(
workbook
,
3
,
510
,
3
,
3
,
excelDto
.
getYq
()
,
"yq"
);
}
if
(
excelDto
!=
null
&&
null
!=
excelDto
.
getZw
()
&&
excelDto
.
getZw
().
length
>
0
)
{
CyEpExcelUtil
.
selectList
(
workbook
,
3
,
510
,
5
,
5
,
excelDto
.
getZw
());
CyEpExcelUtil
.
selectList
(
workbook
,
3
,
510
,
5
,
5
,
excelDto
.
getZw
()
,
"zw"
);
}
// 班次
if
(
excelDto
!=
null
&&
null
!=
excelDto
.
getShift
()
&&
excelDto
.
getShift
().
length
>
0
)
{
CyEpExcelUtil
.
selectList
(
workbook
,
3
,
510
,
6
,
6
,
excelDto
.
getShift
());
CyEpExcelUtil
.
selectList
(
workbook
,
3
,
510
,
6
,
6
,
excelDto
.
getShift
()
,
"shift"
);
}
if
(
workbook
!=
null
)
{
downLoadExcel
(
fileName
,
response
,
workbook
);
}
}
public
static
String
excelColIndexToStr
(
int
columnIndex
)
{
if
(
columnIndex
<=
0
)
{
return
null
;
}
String
columnStr
=
""
;
columnIndex
--;
do
{
if
(
columnStr
.
length
()
>
0
)
{
columnIndex
--;
}
columnStr
=
((
char
)
(
columnIndex
%
26
+
(
int
)
'A'
))
+
columnStr
;
columnIndex
=
(
int
)
((
columnIndex
-
columnIndex
%
26
)
/
26
);
}
while
(
columnIndex
>
0
);
return
columnStr
;
}
/**
* firstRow 開始行號 根据此项目,默认为2(下标0开始)
...
...
@@ -209,18 +225,45 @@ public class CyEpExcelUtil {
* lastCol 区域中最后一个单元格的列号
* strings 下拉内容
*/
public
static
void
selectList
(
Workbook
workbook
,
int
firstRow
,
int
lastRow
,
int
firstCol
,
int
lastCol
,
String
[]
strings
)
{
public
static
void
selectList
(
Workbook
workbook
,
int
firstRow
,
int
lastRow
,
int
firstCol
,
int
lastCol
,
String
[]
strings
,
String
cellName
)
{
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
// 生成下拉列表
Sheet
hidden
=
workbook
.
getSheet
(
"hidden"
);
int
index
=
workbook
.
getSheetIndex
(
"hidden"
);
int
last
=
hidden
.
getLastRowNum
();
//创建单元格对象
Cell
cell
=
null
;
//遍历我们上面的数组,将数据取出来放到新sheet的单元格中
for
(
int
i
=
0
,
length
=
strings
.
length
;
i
<
length
;
i
++)
{
//取出数组中的每个元素
String
name
=
strings
[
i
];
//根据i创建相应的行对象(说明我们将会把每个元素单独放一行)
Row
row
=
null
;
if
(
hidden
.
getRow
(
i
)
==
null
)
row
=
hidden
.
createRow
(
i
);
else
row
=
hidden
.
getRow
(
i
);
//创建每一行中的第一个单元格
cell
=
row
.
createCell
(
firstCol
);
//然后将数组中的元素赋值给这个单元格
cell
.
setCellValue
(
name
);
last
=
hidden
.
getLastRowNum
();
}
// 创建名称,可被其他单元格引用
Name
namedCell
=
workbook
.
createName
();
namedCell
.
setNameName
(
cellName
);
String
letter
=
excelColIndexToStr
(
firstCol
+
1
);
// 设置名称引用的公式
namedCell
.
setRefersToFormula
(
"hidden!$"
+
letter
+
"$1:$"
+
letter
+
"$"
+
strings
.
length
);
// 只对(x,x)单元格有效
CellRangeAddressList
cellRangeAddressList
=
new
CellRangeAddressList
(
firstRow
,
lastRow
,
firstCol
,
lastCol
);
// 生成下拉框内容
DVConstraint
dvConstraint
=
DVConstraint
.
create
ExplicitListConstraint
(
strings
);
DVConstraint
dvConstraint
=
DVConstraint
.
create
FormulaListConstraint
(
cellName
);
HSSFDataValidation
dataValidation
=
new
HSSFDataValidation
(
cellRangeAddressList
,
dvConstraint
);
workbook
.
setSheetHidden
(
index
,
true
);
// HSSFDataValidation dataValidation = getDataValidationList4Col(sheet,firstRow,firstCol,lastRow,lastCol,strings,workbook);
// 对sheet页生效
sheet
.
addValidationData
(
dataValidation
);
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment