Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
金手指1668
easyexcel
提交
2384fd19
E
easyexcel
项目概览
金手指1668
/
easyexcel
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
2384fd19
编写于
4月 22, 2020
作者:
庄家钜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改兼容第一行为空的情况
上级
da7b7879
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
58 addition
and
11 deletion
+58
-11
src/main/java/com/alibaba/excel/analysis/v07/handlers/RowTagHandler.java
...om/alibaba/excel/analysis/v07/handlers/RowTagHandler.java
+7
-9
src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java
...m/alibaba/excel/read/metadata/holder/ReadSheetHolder.java
+2
-0
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadListener.java
...va/com/alibaba/easyexcel/test/temp/read/HeadListener.java
+42
-0
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java
...va/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java
+3
-2
src/test/java/com/alibaba/easyexcel/test/util/TestFileUtil.java
...st/java/com/alibaba/easyexcel/test/util/TestFileUtil.java
+4
-0
未找到文件。
src/main/java/com/alibaba/excel/analysis/v07/handlers/RowTagHandler.java
浏览文件 @
2384fd19
...
...
@@ -25,15 +25,13 @@ public class RowTagHandler extends AbstractXlsxTagHandler {
int
rowIndex
=
PositionUtils
.
getRowByRowTagt
(
attributes
.
getValue
(
ExcelXmlConstants
.
ATTRIBUTE_R
),
xlsxReadSheetHolder
.
getRowIndex
());
Integer
lastRowIndex
=
xlsxReadContext
.
readSheetHolder
().
getRowIndex
();
if
(
lastRowIndex
!=
null
)
{
while
(
lastRowIndex
+
1
<
rowIndex
)
{
xlsxReadContext
.
readRowHolder
(
new
ReadRowHolder
(
lastRowIndex
+
1
,
RowTypeEnum
.
EMPTY
,
xlsxReadSheetHolder
.
getGlobalConfiguration
(),
new
LinkedHashMap
<
Integer
,
Cell
>()));
xlsxReadContext
.
analysisEventProcessor
().
endRow
(
xlsxReadContext
);
xlsxReadSheetHolder
.
setColumnIndex
(
null
);
xlsxReadSheetHolder
.
setCellMap
(
new
LinkedHashMap
<
Integer
,
Cell
>());
lastRowIndex
++;
}
while
(
lastRowIndex
+
1
<
rowIndex
)
{
xlsxReadContext
.
readRowHolder
(
new
ReadRowHolder
(
lastRowIndex
+
1
,
RowTypeEnum
.
EMPTY
,
xlsxReadSheetHolder
.
getGlobalConfiguration
(),
new
LinkedHashMap
<
Integer
,
Cell
>()));
xlsxReadContext
.
analysisEventProcessor
().
endRow
(
xlsxReadContext
);
xlsxReadSheetHolder
.
setColumnIndex
(
null
);
xlsxReadSheetHolder
.
setCellMap
(
new
LinkedHashMap
<
Integer
,
Cell
>());
lastRowIndex
++;
}
xlsxReadSheetHolder
.
setRowIndex
(
rowIndex
);
}
...
...
src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java
浏览文件 @
2384fd19
...
...
@@ -15,6 +15,7 @@ import com.alibaba.excel.read.metadata.ReadSheet;
* @author Jiaju Zhuang
*/
public
class
ReadSheetHolder
extends
AbstractReadHolder
{
/**
* current param
*/
...
...
@@ -59,6 +60,7 @@ public class ReadSheetHolder extends AbstractReadHolder {
this
.
sheetNo
=
readSheet
.
getSheetNo
();
this
.
sheetName
=
readSheet
.
getSheetName
();
this
.
cellMap
=
new
LinkedHashMap
<
Integer
,
Cell
>();
this
.
rowIndex
=
-
1
;
}
public
ReadSheet
getReadSheet
()
{
...
...
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadListener.java
0 → 100644
浏览文件 @
2384fd19
package
com.alibaba.easyexcel.test.temp.read
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.fastjson.JSON
;
/**
* 模板的读取类
*
* @author Jiaju Zhuang
*/
public
class
HeadListener
extends
AnalysisEventListener
<
Map
<
Integer
,
String
>>
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
HeadListener
.
class
);
/**
* 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
*/
private
static
final
int
BATCH_COUNT
=
5
;
@Override
public
void
invokeHeadMap
(
Map
<
Integer
,
String
>
headMap
,
AnalysisContext
context
)
{
LOGGER
.
info
(
"HEAD:{}"
,
JSON
.
toJSONString
(
headMap
));
LOGGER
.
info
(
"total:{}"
,
context
.
readSheetHolder
().
getTotal
());
}
@Override
public
void
invoke
(
Map
<
Integer
,
String
>
data
,
AnalysisContext
context
)
{
LOGGER
.
info
(
"index:{}"
,
context
.
readRowHolder
().
getRowIndex
());
LOGGER
.
info
(
"解析到一条数据:{}"
,
JSON
.
toJSONString
(
data
));
}
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
context
)
{
LOGGER
.
info
(
"所有数据解析完成!"
);
}
}
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java
浏览文件 @
2384fd19
...
...
@@ -7,6 +7,7 @@ import org.junit.Test;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.easyexcel.test.util.TestFileUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.cache.Ehcache
;
...
...
@@ -21,8 +22,8 @@ public class HeadReadTest {
@Test
public
void
test
()
throws
Exception
{
File
file
=
new
File
(
"D:\\test\\headt1.xls
"
);
EasyExcel
.
read
(
file
,
HeadReadData
.
class
,
new
HDListener
()
).
sheet
(
0
).
doRead
();
File
file
=
TestFileUtil
.
readUserHomeFile
(
"test/t1.xlsx
"
);
EasyExcel
.
read
(
file
,
null
,
new
HeadListener
()).
ignoreEmptyRow
(
false
).
sheet
(
0
).
doRead
();
}
...
...
src/test/java/com/alibaba/easyexcel/test/util/TestFileUtil.java
浏览文件 @
2384fd19
...
...
@@ -5,6 +5,7 @@ import java.io.InputStream;
public
class
TestFileUtil
{
public
static
InputStream
getResourcesFileInputStream
(
String
fileName
)
{
return
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
""
+
fileName
);
}
...
...
@@ -29,4 +30,7 @@ public class TestFileUtil {
return
new
File
(
getPath
()
+
pathName
);
}
public
static
File
readUserHomeFile
(
String
pathName
)
{
return
new
File
(
System
.
getProperty
(
"user.home"
)
+
File
.
separator
+
pathName
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录