Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_879456671
easyexcel
提交
3d19a196
E
easyexcel
项目概览
qq_879456671
/
easyexcel
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
easyexcel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3d19a196
编写于
9月 15, 2021
作者:
庄家钜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* 新增头的非空校验 [Issue #1765]
上级
9286b57b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
104 addition
and
61 deletion
+104
-61
src/main/java/com/alibaba/excel/metadata/Head.java
src/main/java/com/alibaba/excel/metadata/Head.java
+9
-2
src/main/java/com/alibaba/excel/util/StringUtils.java
src/main/java/com/alibaba/excel/util/StringUtils.java
+94
-3
src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java
.../alibaba/excel/write/property/ExcelWriteHeadProperty.java
+1
-1
src/test/java/com/alibaba/easyexcel/test/demo/Test1765/Data1765.xlsx
...va/com/alibaba/easyexcel/test/demo/Test1765/Data1765.xlsx
+0
-0
src/test/java/com/alibaba/easyexcel/test/demo/Test1765/Issue1765.java
...a/com/alibaba/easyexcel/test/demo/Test1765/Issue1765.java
+0
-55
未找到文件。
src/main/java/com/alibaba/excel/metadata/Head.java
浏览文件 @
3d19a196
...
...
@@ -3,6 +3,7 @@ package com.alibaba.excel.metadata;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.alibaba.excel.exception.ExcelGenerateException
;
import
com.alibaba.excel.metadata.property.ColumnWidthProperty
;
import
com.alibaba.excel.metadata.property.FontProperty
;
import
com.alibaba.excel.metadata.property.LoopMergeProperty
;
...
...
@@ -64,9 +65,15 @@ public class Head {
this
.
columnIndex
=
columnIndex
;
this
.
fieldName
=
fieldName
;
if
(
headNameList
==
null
)
{
headNameList
=
new
ArrayList
<
String
>();
this
.
headNameList
=
new
ArrayList
<>();
}
else
{
this
.
headNameList
=
headNameList
;
for
(
String
headName
:
headNameList
)
{
if
(
headName
==
null
)
{
throw
new
ExcelGenerateException
(
"head name can not be null."
);
}
}
}
this
.
headNameList
=
headNameList
;
this
.
forceIndex
=
forceIndex
;
this
.
forceName
=
forceName
;
}
...
...
src/main/java/com/alibaba/excel/util/StringUtils.java
浏览文件 @
3d19a196
...
...
@@ -69,7 +69,6 @@ public class StringUtils {
return
true
;
}
/**
* <p>Checks if a CharSequence is not empty (""), not null and not whitespace only.</p>
*
...
...
@@ -83,9 +82,9 @@ public class StringUtils {
* StringUtils.isNotBlank(" bob ") = true
* </pre>
*
* @param cs
the CharSequence to check, may be null
* @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is
*
not empty and not null and not whitespace only
* not empty and not null and not whitespace only
* @since 2.0
* @since 3.0 Changed signature from isNotBlank(String) to isNotBlank(CharSequence)
*/
...
...
@@ -93,5 +92,97 @@ public class StringUtils {
return
!
isBlank
(
cs
);
}
/**
* <p>Compares two CharSequences, returning {@code true} if they represent
* equal sequences of characters.</p>
*
* <p>{@code null}s are handled without exceptions. Two {@code null}
* references are considered to be equal. The comparison is case sensitive.</p>
*
* <pre>
* StringUtils.equals(null, null) = true
* StringUtils.equals(null, "abc") = false
* StringUtils.equals("abc", null) = false
* StringUtils.equals("abc", "abc") = true
* StringUtils.equals("abc", "ABC") = false
* </pre>
*
* @param cs1 the first CharSequence, may be {@code null}
* @param cs2 the second CharSequence, may be {@code null}
* @return {@code true} if the CharSequences are equal (case-sensitive), or both {@code null}
* @see Object#equals(Object)
* @since 3.0 Changed signature from equals(String, String) to equals(CharSequence, CharSequence)
*/
public
static
boolean
equals
(
final
CharSequence
cs1
,
final
CharSequence
cs2
)
{
if
(
cs1
==
cs2
)
{
return
true
;
}
if
(
cs1
==
null
||
cs2
==
null
)
{
return
false
;
}
if
(
cs1
.
length
()
!=
cs2
.
length
())
{
return
false
;
}
if
(
cs1
instanceof
String
&&
cs2
instanceof
String
)
{
return
cs1
.
equals
(
cs2
);
}
return
regionMatches
(
cs1
,
false
,
0
,
cs2
,
0
,
cs1
.
length
());
}
/**
* Green implementation of regionMatches.
*
* @param cs the {@code CharSequence} to be processed
* @param ignoreCase whether or not to be case insensitive
* @param thisStart the index to start on the {@code cs} CharSequence
* @param substring the {@code CharSequence} to be looked for
* @param start the index to start on the {@code substring} CharSequence
* @param length character length of the region
* @return whether the region matched
*/
public
static
boolean
regionMatches
(
final
CharSequence
cs
,
final
boolean
ignoreCase
,
final
int
thisStart
,
final
CharSequence
substring
,
final
int
start
,
final
int
length
)
{
if
(
cs
instanceof
String
&&
substring
instanceof
String
)
{
return
((
String
)
cs
).
regionMatches
(
ignoreCase
,
thisStart
,
(
String
)
substring
,
start
,
length
);
}
int
index1
=
thisStart
;
int
index2
=
start
;
int
tmpLen
=
length
;
// Extract these first so we detect NPEs the same as the java.lang.String version
final
int
srcLen
=
cs
.
length
()
-
thisStart
;
final
int
otherLen
=
substring
.
length
()
-
start
;
// Check for invalid parameters
if
(
thisStart
<
0
||
start
<
0
||
length
<
0
)
{
return
false
;
}
// Check that the regions are long enough
if
(
srcLen
<
length
||
otherLen
<
length
)
{
return
false
;
}
while
(
tmpLen
--
>
0
)
{
final
char
c1
=
cs
.
charAt
(
index1
++);
final
char
c2
=
substring
.
charAt
(
index2
++);
if
(
c1
==
c2
)
{
continue
;
}
if
(!
ignoreCase
)
{
return
false
;
}
// The same check as in String.regionMatches():
if
(
Character
.
toUpperCase
(
c1
)
!=
Character
.
toUpperCase
(
c2
)
&&
Character
.
toLowerCase
(
c1
)
!=
Character
.
toLowerCase
(
c2
))
{
return
false
;
}
}
return
true
;
}
}
src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java
浏览文件 @
3d19a196
...
...
@@ -142,7 +142,7 @@ public class ExcelWriteHeadProperty extends ExcelHeadProperty {
continue
;
}
alreadyRangeSet
.
add
(
i
+
"-"
+
j
);
String
headName
=
headNameList
.
get
(
j
)
==
null
?
""
:
headNameList
.
get
(
j
)
;
String
headName
=
headNameList
.
get
(
j
);
int
lastCol
=
i
;
int
lastRow
=
j
;
for
(
int
k
=
i
+
1
;
k
<
headList
.
size
();
k
++)
{
...
...
src/test/java/com/alibaba/easyexcel/test/demo/Test1765/Data1765.xlsx
已删除
100644 → 0
浏览文件 @
9286b57b
文件已删除
src/test/java/com/alibaba/easyexcel/test/demo/Test1765/Issue1765.java
已删除
100644 → 0
浏览文件 @
9286b57b
package
com.alibaba.easyexcel.test.demo.Test1765
;
import
com.alibaba.easyexcel.test.util.TestFileUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.EasyExcelFactory
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
public
class
Issue1765
{
@Test
public
void
test1765
()
throws
FileNotFoundException
{
String
fileName
=
"src/test/java/com/alibaba/easyexcel/test/demo/Test1765/Data1765.xlsx"
;
EasyExcel
.
write
(
fileName
).
head
(
head
()).
sheet
(
"模板"
).
doWrite
(
dataList
());
}
private
List
<
List
<
String
>>
head
()
{
List
<
List
<
String
>>
list
=
new
ArrayList
<
List
<
String
>>();
List
<
String
>
head0
=
new
ArrayList
<
String
>();
List
<
String
>
head1
=
new
ArrayList
<
String
>();
List
<
String
>
head2
=
new
ArrayList
<
String
>();
List
<
String
>
head3
=
new
ArrayList
<
String
>();
head0
.
add
(
"表头"
);
head1
.
add
(
"日期"
);
head2
.
add
(
null
);
head3
.
add
(
"数字"
);
list
.
add
(
head0
);
list
.
add
(
head1
);
list
.
add
(
head2
);
list
.
add
(
head3
);
return
list
;
}
private
List
<
List
<
Object
>>
dataList
()
{
List
<
List
<
Object
>>
list
=
new
ArrayList
<
List
<
Object
>>();
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
List
<
Object
>
data
=
new
ArrayList
<
Object
>();
data
.
add
(
"字符串"
+
i
);
data
.
add
(
new
Date
());
data
.
add
(
i
*
2
);
data
.
add
(
i
*
3
);
list
.
add
(
data
);
}
return
list
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录