Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_879456671
easyexcel
提交
8ded0abc
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,发现更多精彩内容 >>
提交
8ded0abc
编写于
9月 08, 2021
作者:
庄家钜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成csv 书写
上级
fbb79df7
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
268 addition
and
161 deletion
+268
-161
src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
...in/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
+17
-9
src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java
.../com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java
+112
-0
src/main/java/com/alibaba/excel/context/AnalysisContextImpl.java
...n/java/com/alibaba/excel/context/AnalysisContextImpl.java
+8
-1
src/main/java/com/alibaba/excel/context/csv/CsvReadContext.java
...in/java/com/alibaba/excel/context/csv/CsvReadContext.java
+26
-0
src/main/java/com/alibaba/excel/context/csv/DefaultCsvReadContext.java
.../com/alibaba/excel/context/csv/DefaultCsvReadContext.java
+29
-0
src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
...libaba/excel/read/metadata/holder/AbstractReadHolder.java
+2
-0
src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java
...m/alibaba/excel/read/metadata/holder/ReadSheetHolder.java
+2
-0
src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
...libaba/excel/read/metadata/holder/ReadWorkbookHolder.java
+5
-151
src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadSheetHolder.java
...ba/excel/read/metadata/holder/csv/CsvReadSheetHolder.java
+20
-0
src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java
...excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java
+25
-0
src/test/java/com/alibaba/easyexcel/test/temp/csv/CsvReadTest.java
...java/com/alibaba/easyexcel/test/temp/csv/CsvReadTest.java
+22
-0
未找到文件。
src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
浏览文件 @
8ded0abc
...
...
@@ -3,18 +3,12 @@ package com.alibaba.excel.analysis;
import
java.io.InputStream
;
import
java.util.List
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.poi.hssf.record.crypto.Biff8EncryptionKey
;
import
org.apache.poi.poifs.crypt.Decryptor
;
import
org.apache.poi.poifs.filesystem.DocumentFactoryHelper
;
import
org.apache.poi.poifs.filesystem.POIFSFileSystem
;
import
org.apache.poi.util.IOUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.excel.analysis.csv.CsvExcelReadExecutor
;
import
com.alibaba.excel.analysis.v03.XlsSaxAnalyser
;
import
com.alibaba.excel.analysis.v07.XlsxSaxAnalyser
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.context.csv.CsvReadContext
;
import
com.alibaba.excel.context.csv.DefaultCsvReadContext
;
import
com.alibaba.excel.context.xls.DefaultXlsReadContext
;
import
com.alibaba.excel.context.xls.XlsReadContext
;
import
com.alibaba.excel.context.xlsx.DefaultXlsxReadContext
;
...
...
@@ -32,6 +26,15 @@ import com.alibaba.excel.util.FileUtils;
import
com.alibaba.excel.util.NumberDataFormatterUtils
;
import
com.alibaba.excel.util.StringUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.poi.hssf.record.crypto.Biff8EncryptionKey
;
import
org.apache.poi.poifs.crypt.Decryptor
;
import
org.apache.poi.poifs.filesystem.DocumentFactoryHelper
;
import
org.apache.poi.poifs.filesystem.POIFSFileSystem
;
import
org.apache.poi.util.IOUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author jipengfei
*/
...
...
@@ -98,6 +101,11 @@ public class ExcelAnalyserImpl implements ExcelAnalyser {
analysisContext
=
xlsxReadContext
;
excelReadExecutor
=
new
XlsxSaxAnalyser
(
xlsxReadContext
,
null
);
break
;
case
CSV:
CsvReadContext
csvReadContext
=
new
DefaultCsvReadContext
(
readWorkbook
,
ExcelTypeEnum
.
CSV
);
analysisContext
=
csvReadContext
;
excelReadExecutor
=
new
CsvExcelReadExecutor
(
csvReadContext
);
break
;
default
:
break
;
}
...
...
src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java
0 → 100644
浏览文件 @
8ded0abc
package
com.alibaba.excel.analysis.csv
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.alibaba.excel.analysis.ExcelReadExecutor
;
import
com.alibaba.excel.context.csv.CsvReadContext
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.enums.RowTypeEnum
;
import
com.alibaba.excel.exception.ExcelAnalysisException
;
import
com.alibaba.excel.metadata.Cell
;
import
com.alibaba.excel.metadata.data.ReadCellData
;
import
com.alibaba.excel.read.metadata.ReadSheet
;
import
com.alibaba.excel.read.metadata.holder.ReadRowHolder
;
import
com.alibaba.excel.read.metadata.holder.csv.CsvReadWorkbookHolder
;
import
com.alibaba.excel.util.SheetUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.MapUtils
;
import
org.apache.commons.csv.CSVFormat
;
import
org.apache.commons.csv.CSVRecord
;
/**
* azz
*
* @author zhuangjiaju
*/
@Slf4j
public
class
CsvExcelReadExecutor
implements
ExcelReadExecutor
{
private
List
<
ReadSheet
>
sheetList
;
private
CsvReadContext
csvReadContext
;
public
CsvExcelReadExecutor
(
CsvReadContext
csvReadContext
)
{
this
.
csvReadContext
=
csvReadContext
;
sheetList
=
new
ArrayList
<>();
ReadSheet
readSheet
=
new
ReadSheet
();
sheetList
.
add
(
readSheet
);
readSheet
.
setSheetNo
(
0
);
}
@Override
public
List
<
ReadSheet
>
sheetList
()
{
return
sheetList
;
}
@Override
public
void
execute
()
{
Iterable
<
CSVRecord
>
parseRecords
;
try
{
parseRecords
=
parseRecords
();
}
catch
(
IOException
e
)
{
throw
new
ExcelAnalysisException
(
e
);
}
for
(
ReadSheet
readSheet
:
sheetList
)
{
readSheet
=
SheetUtils
.
match
(
readSheet
,
csvReadContext
);
if
(
readSheet
==
null
)
{
continue
;
}
csvReadContext
.
currentSheet
(
readSheet
);
int
rowIndex
=
0
;
for
(
CSVRecord
record
:
parseRecords
)
{
dealRecord
(
record
,
rowIndex
++);
}
// The last sheet is read
csvReadContext
.
analysisEventProcessor
().
endSheet
(
csvReadContext
);
}
}
private
Iterable
<
CSVRecord
>
parseRecords
()
throws
IOException
{
CsvReadWorkbookHolder
csvReadWorkbookHolder
=
csvReadContext
.
csvReadWorkbookHolder
();
CSVFormat
csvFormat
=
csvReadWorkbookHolder
.
getCsvFormat
();
if
(
csvReadWorkbookHolder
.
getMandatoryUseInputStream
())
{
return
csvFormat
.
parse
(
new
InputStreamReader
(
csvReadWorkbookHolder
.
getInputStream
()));
}
if
(
csvReadWorkbookHolder
.
getFile
()
!=
null
)
{
return
csvFormat
.
parse
(
new
FileReader
(
csvReadWorkbookHolder
.
getFile
()));
}
return
csvFormat
.
parse
(
new
InputStreamReader
(
csvReadWorkbookHolder
.
getInputStream
()));
}
private
void
dealRecord
(
CSVRecord
record
,
int
rowIndex
)
{
Map
<
Integer
,
Cell
>
cellMap
=
new
LinkedHashMap
<>();
Iterator
<
String
>
cellIterator
=
record
.
iterator
();
int
cellIndex
=
0
;
while
(
cellIterator
.
hasNext
())
{
String
cellString
=
cellIterator
.
next
();
ReadCellData
<
String
>
readCellData
=
new
ReadCellData
<>();
readCellData
.
setType
(
CellDataTypeEnum
.
STRING
);
readCellData
.
setStringValue
(
cellString
);
cellMap
.
put
(
cellIndex
++,
readCellData
);
}
RowTypeEnum
rowType
=
MapUtils
.
isEmpty
(
cellMap
)
?
RowTypeEnum
.
EMPTY
:
RowTypeEnum
.
DATA
;
ReadRowHolder
readRowHolder
=
new
ReadRowHolder
(
rowIndex
,
rowType
,
csvReadContext
.
readWorkbookHolder
().
getGlobalConfiguration
(),
cellMap
);
csvReadContext
.
readRowHolder
(
readRowHolder
);
csvReadContext
.
csvReadSheetHolder
().
setCellMap
(
cellMap
);
csvReadContext
.
csvReadSheetHolder
().
setRowIndex
(
rowIndex
);
csvReadContext
.
analysisEventProcessor
().
endRow
(
csvReadContext
);
}
}
src/main/java/com/alibaba/excel/context/AnalysisContextImpl.java
浏览文件 @
8ded0abc
...
...
@@ -10,6 +10,8 @@ import com.alibaba.excel.read.metadata.holder.ReadHolder;
import
com.alibaba.excel.read.metadata.holder.ReadRowHolder
;
import
com.alibaba.excel.read.metadata.holder.ReadSheetHolder
;
import
com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder
;
import
com.alibaba.excel.read.metadata.holder.csv.CsvReadSheetHolder
;
import
com.alibaba.excel.read.metadata.holder.csv.CsvReadWorkbookHolder
;
import
com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder
;
import
com.alibaba.excel.read.metadata.holder.xls.XlsReadWorkbookHolder
;
import
com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder
;
...
...
@@ -57,6 +59,9 @@ public class AnalysisContextImpl implements AnalysisContext {
case
XLSX:
readWorkbookHolder
=
new
XlsxReadWorkbookHolder
(
readWorkbook
);
break
;
case
CSV:
readWorkbookHolder
=
new
CsvReadWorkbookHolder
(
readWorkbook
);
break
;
default
:
break
;
}
...
...
@@ -76,6 +81,9 @@ public class AnalysisContextImpl implements AnalysisContext {
case
XLSX:
readSheetHolder
=
new
XlsxReadSheetHolder
(
readSheet
,
readWorkbookHolder
);
break
;
case
CSV:
readSheetHolder
=
new
CsvReadSheetHolder
(
readSheet
,
readWorkbookHolder
);
break
;
default
:
break
;
}
...
...
@@ -134,7 +142,6 @@ public class AnalysisContextImpl implements AnalysisContext {
}
@Override
public
ExcelTypeEnum
getExcelType
()
{
return
readWorkbookHolder
.
getExcelType
();
...
...
src/main/java/com/alibaba/excel/context/csv/CsvReadContext.java
0 → 100644
浏览文件 @
8ded0abc
package
com.alibaba.excel.context.csv
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.read.metadata.holder.csv.CsvReadSheetHolder
;
import
com.alibaba.excel.read.metadata.holder.csv.CsvReadWorkbookHolder
;
/**
* A context is the main anchorage point of a ls xls reader.
*
* @author Jiaju Zhuang
**/
public
interface
CsvReadContext
extends
AnalysisContext
{
/**
* All information about the workbook you are currently working on.
*
* @return Current workbook holder
*/
CsvReadWorkbookHolder
csvReadWorkbookHolder
();
/**
* All information about the sheet you are currently working on.
*
* @return Current sheet holder
*/
CsvReadSheetHolder
csvReadSheetHolder
();
}
src/main/java/com/alibaba/excel/context/csv/DefaultCsvReadContext.java
0 → 100644
浏览文件 @
8ded0abc
package
com.alibaba.excel.context.csv
;
import
com.alibaba.excel.context.AnalysisContextImpl
;
import
com.alibaba.excel.read.metadata.ReadWorkbook
;
import
com.alibaba.excel.read.metadata.holder.csv.CsvReadSheetHolder
;
import
com.alibaba.excel.read.metadata.holder.csv.CsvReadWorkbookHolder
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
/**
* A context is the main anchorage point of a ls xls reader.
*
* @author Jiaju Zhuang
*/
public
class
DefaultCsvReadContext
extends
AnalysisContextImpl
implements
CsvReadContext
{
public
DefaultCsvReadContext
(
ReadWorkbook
readWorkbook
,
ExcelTypeEnum
actualExcelType
)
{
super
(
readWorkbook
,
actualExcelType
);
}
@Override
public
CsvReadWorkbookHolder
csvReadWorkbookHolder
()
{
return
(
CsvReadWorkbookHolder
)
readWorkbookHolder
();
}
@Override
public
CsvReadSheetHolder
csvReadSheetHolder
()
{
return
(
CsvReadSheetHolder
)
readSheetHolder
();
}
}
src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
浏览文件 @
8ded0abc
...
...
@@ -16,6 +16,7 @@ import com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty;
import
com.alibaba.excel.util.ListUtils
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* Read Holder
...
...
@@ -23,6 +24,7 @@ import lombok.Data;
* @author Jiaju Zhuang
*/
@Data
@NoArgsConstructor
public
abstract
class
AbstractReadHolder
extends
AbstractHolder
implements
ReadHolder
{
/**
* Count the number of added heads when read sheet.
...
...
src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java
浏览文件 @
8ded0abc
...
...
@@ -10,6 +10,7 @@ import com.alibaba.excel.metadata.data.ReadCellData;
import
com.alibaba.excel.read.metadata.ReadSheet
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* sheet holder
...
...
@@ -17,6 +18,7 @@ import lombok.Data;
* @author Jiaju Zhuang
*/
@Data
@NoArgsConstructor
public
class
ReadSheetHolder
extends
AbstractReadHolder
{
/**
...
...
src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
浏览文件 @
8ded0abc
...
...
@@ -19,11 +19,16 @@ import com.alibaba.excel.read.metadata.ReadSheet;
import
com.alibaba.excel.read.metadata.ReadWorkbook
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* Workbook holder
*
* @author Jiaju Zhuang
*/
@Data
@NoArgsConstructor
public
class
ReadWorkbookHolder
extends
AbstractReadHolder
{
/**
...
...
@@ -171,157 +176,6 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
this
.
password
=
readWorkbook
.
getPassword
();
}
public
ReadWorkbook
getReadWorkbook
()
{
return
readWorkbook
;
}
public
void
setReadWorkbook
(
ReadWorkbook
readWorkbook
)
{
this
.
readWorkbook
=
readWorkbook
;
}
public
InputStream
getInputStream
()
{
return
inputStream
;
}
public
void
setInputStream
(
InputStream
inputStream
)
{
this
.
inputStream
=
inputStream
;
}
public
File
getFile
()
{
return
file
;
}
public
void
setFile
(
File
file
)
{
this
.
file
=
file
;
}
public
Boolean
getAutoCloseStream
()
{
return
autoCloseStream
;
}
public
void
setAutoCloseStream
(
Boolean
autoCloseStream
)
{
this
.
autoCloseStream
=
autoCloseStream
;
}
public
ExcelTypeEnum
getExcelType
()
{
return
excelType
;
}
public
void
setExcelType
(
ExcelTypeEnum
excelType
)
{
this
.
excelType
=
excelType
;
}
public
Object
getCustomObject
()
{
return
customObject
;
}
public
void
setCustomObject
(
Object
customObject
)
{
this
.
customObject
=
customObject
;
}
public
Boolean
getIgnoreEmptyRow
()
{
return
ignoreEmptyRow
;
}
public
void
setIgnoreEmptyRow
(
Boolean
ignoreEmptyRow
)
{
this
.
ignoreEmptyRow
=
ignoreEmptyRow
;
}
public
ReadCache
getReadCache
()
{
return
readCache
;
}
public
void
setReadCache
(
ReadCache
readCache
)
{
this
.
readCache
=
readCache
;
}
public
ReadCacheSelector
getReadCacheSelector
()
{
return
readCacheSelector
;
}
public
void
setReadCacheSelector
(
ReadCacheSelector
readCacheSelector
)
{
this
.
readCacheSelector
=
readCacheSelector
;
}
public
Boolean
getMandatoryUseInputStream
()
{
return
mandatoryUseInputStream
;
}
public
void
setMandatoryUseInputStream
(
Boolean
mandatoryUseInputStream
)
{
this
.
mandatoryUseInputStream
=
mandatoryUseInputStream
;
}
public
File
getTempFile
()
{
return
tempFile
;
}
public
void
setTempFile
(
File
tempFile
)
{
this
.
tempFile
=
tempFile
;
}
public
Boolean
getConvertAllFiled
()
{
return
convertAllFiled
;
}
public
void
setConvertAllFiled
(
Boolean
convertAllFiled
)
{
this
.
convertAllFiled
=
convertAllFiled
;
}
public
Set
<
Integer
>
getHasReadSheet
()
{
return
hasReadSheet
;
}
public
void
setHasReadSheet
(
Set
<
Integer
>
hasReadSheet
)
{
this
.
hasReadSheet
=
hasReadSheet
;
}
public
Boolean
getDefaultReturnMap
()
{
return
defaultReturnMap
;
}
public
void
setDefaultReturnMap
(
Boolean
defaultReturnMap
)
{
this
.
defaultReturnMap
=
defaultReturnMap
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
Set
<
CellExtraTypeEnum
>
getExtraReadSet
()
{
return
extraReadSet
;
}
public
void
setExtraReadSet
(
Set
<
CellExtraTypeEnum
>
extraReadSet
)
{
this
.
extraReadSet
=
extraReadSet
;
}
public
List
<
ReadSheet
>
getActualSheetDataList
()
{
return
actualSheetDataList
;
}
public
void
setActualSheetDataList
(
List
<
ReadSheet
>
actualSheetDataList
)
{
this
.
actualSheetDataList
=
actualSheetDataList
;
}
public
List
<
ReadSheet
>
getParameterSheetDataList
()
{
return
parameterSheetDataList
;
}
public
void
setParameterSheetDataList
(
List
<
ReadSheet
>
parameterSheetDataList
)
{
this
.
parameterSheetDataList
=
parameterSheetDataList
;
}
public
Boolean
getReadAll
()
{
return
readAll
;
}
public
void
setReadAll
(
Boolean
readAll
)
{
this
.
readAll
=
readAll
;
}
@Override
public
HolderEnum
holderType
()
{
...
...
src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadSheetHolder.java
0 → 100644
浏览文件 @
8ded0abc
package
com.alibaba.excel.read.metadata.holder.csv
;
import
com.alibaba.excel.read.metadata.ReadSheet
;
import
com.alibaba.excel.read.metadata.holder.ReadSheetHolder
;
import
com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder
;
import
lombok.Data
;
/**
* sheet holder
*
* @author Jiaju Zhuang
*/
@Data
public
class
CsvReadSheetHolder
extends
ReadSheetHolder
{
public
CsvReadSheetHolder
(
ReadSheet
readSheet
,
ReadWorkbookHolder
readWorkbookHolder
)
{
super
(
readSheet
,
readWorkbookHolder
);
}
}
src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java
0 → 100644
浏览文件 @
8ded0abc
package
com.alibaba.excel.read.metadata.holder.csv
;
import
com.alibaba.excel.read.metadata.ReadWorkbook
;
import
com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
import
lombok.Data
;
import
org.apache.commons.csv.CSVFormat
;
/**
* Workbook holder
*
* @author Jiaju Zhuang
*/
@Data
public
class
CsvReadWorkbookHolder
extends
ReadWorkbookHolder
{
private
CSVFormat
csvFormat
;
public
CsvReadWorkbookHolder
(
ReadWorkbook
readWorkbook
)
{
super
(
readWorkbook
);
setExcelType
(
ExcelTypeEnum
.
CSV
);
csvFormat
=
CSVFormat
.
DEFAULT
;
}
}
src/test/java/com/alibaba/easyexcel/test/temp/csv/CsvReadTest.java
浏览文件 @
8ded0abc
...
...
@@ -2,6 +2,7 @@ package com.alibaba.easyexcel.test.temp.csv;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileReader
;
import
java.io.PrintWriter
;
import
java.util.ArrayList
;
import
java.util.Date
;
...
...
@@ -9,10 +10,12 @@ import java.util.List;
import
com.alibaba.easyexcel.test.util.TestFileUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.csv.CSVFormat
;
import
org.apache.commons.csv.CSVPrinter
;
import
org.apache.commons.csv.CSVRecord
;
import
org.apache.poi.poifs.filesystem.FileMagic
;
import
org.junit.Ignore
;
import
org.junit.Test
;
...
...
@@ -33,6 +36,18 @@ public class CsvReadTest {
printer
.
close
();
}
@Test
public
void
read1
()
throws
Exception
{
Iterable
<
CSVRecord
>
records
=
CSVFormat
.
DEFAULT
.
parse
(
new
FileReader
(
"/Users/zhuangjiaju/IdeaProjects/easyexcel/target/test-classes/csvWrite1.csv"
));
for
(
CSVRecord
record
:
records
)
{
String
lastName
=
record
.
get
(
0
);
String
firstName
=
record
.
get
(
1
);
log
.
info
(
"row:{},{}"
,
lastName
,
firstName
);
}
}
@Test
public
void
csvWrite
()
throws
Exception
{
// 写法1
...
...
@@ -40,6 +55,13 @@ public class CsvReadTest {
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 如果这里想使用03 则 传入excelType参数即可
EasyExcel
.
write
(
fileName
,
CsvData
.
class
).
sheet
().
doWrite
(
data
());
// 读
List
<
Object
>
list
=
EasyExcel
.
read
(
fileName
).
sheet
(
0
).
headRowNumber
(
0
).
doReadSync
();
log
.
info
(
"数据:{}"
,
list
.
size
());
for
(
Object
data
:
list
)
{
log
.
info
(
"返回数据:{}"
,
JSON
.
toJSONString
(
data
));
}
}
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录