Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
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
YZG
yzg-util
Commits
c6aed539
Commit
c6aed539
authored
Mar 05, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实体位置
parent
7c1656d0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
0 deletions
+32
-0
CalcHelper.java
...src/main/java/com/yanzuoguang/util/helper/CalcHelper.java
+22
-0
TestCalcHelper.java
yzg-util-base/src/test/java/helper/TestCalcHelper.java
+8
-0
非法身份证.csv
yzg-util-base/src/test/java/helper/非法身份证.csv
+2
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/CalcHelper.java
View file @
c6aed539
...
@@ -38,6 +38,28 @@ public class CalcHelper {
...
@@ -38,6 +38,28 @@ public class CalcHelper {
}
}
/**
* 获取excel列序号
*
* @param columnName
* @return
*/
public
static
final
int
getExcelIndex
(
String
columnName
)
{
columnName
=
columnName
.
toLowerCase
();
if
(!
columnName
.
matches
(
"^[a-z]+$"
))
{
throw
new
RuntimeException
(
"变量名"
+
columnName
+
"不支持"
);
}
// 从名称转换列序号
int
formulaColumnIndex
=
0
;
char
[]
chs
=
new
char
[
columnName
.
length
()];
columnName
.
getChars
(
0
,
columnName
.
length
()
,
chs
,
0
);
for
(
int
i
=
0
;
i
<
chs
.
length
;
i
++)
{
formulaColumnIndex
=
formulaColumnIndex
*
26
+
(
chs
[
i
]
-
'a'
+
1
);
}
formulaColumnIndex
--;
return
formulaColumnIndex
;
}
/**
/**
* 计算公式
* 计算公式
*
*
...
...
yzg-util-base/src/test/java/helper/TestCalcHelper.java
View file @
c6aed539
...
@@ -43,4 +43,12 @@ public class TestCalcHelper {
...
@@ -43,4 +43,12 @@ public class TestCalcHelper {
}
}
}));
}));
}
}
@Test
public
void
test2
()
{
System
.
out
.
println
(
CalcHelper
.
getExcelIndex
(
"aa"
));
System
.
out
.
println
(
CalcHelper
.
getExcelIndex
(
"ba"
));
System
.
out
.
println
(
CalcHelper
.
getExcelIndex
(
"ab"
));
System
.
out
.
println
(
CalcHelper
.
getExcelIndex
(
"a"
));
}
}
}
yzg-util-base/src/test/java/helper/非法身份证.csv
View file @
c6aed539
aa
王蕾
王蕾
陈俊
陈俊
06151196
06151196
...
...
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