學習easyexcel之前,首先要學習apache poi
1、建立springboot專案,然後匯入依賴.
poi是03版本,然後他的excel結尾是xlspoi-ooxml是07版本,excel結尾是xlsx
>
>
org.apache.poigroupid
>
>
poiartifactid
>
>
3.9version
>
dependency
>
">>
>
>
org.apache.poigroupid
>
>
poi-ooxmlartifactid
>
>
3.9version
>
dependency
>
>
>
joda-timegroupid
>
>
joda-timeartifactid
>
>
2.10.5version
>
dependency
>
2、寫03版本的excel
hssfworkbook是建立03版本的物件。而07版本的是xssfworkbook
@test
public
static
void
excelwrite03()
throws exception
3、寫07版本的excel
@test
public
static
void
excelwrite07()
throws exception
4、讀03版本的excel
static string path=
"d:\\github\\lucas-poi\\"
;@test
public
static
void
excelread03()
throws exception
5、讀07版本的excel
@test
public
static
void
excelread07()
throws exception
6、03版本大資料處理hssfworkbook,
//hssfworkbook只能處理65536行資料,多了則異常報錯,但是較慢,是03版本
@test
public
void
testwrite03bigdata()
throws exception
} system.out.
println
("over");
fileoutputstream fileoutputstream =
newfileoutputstream
(path +
"testwrite03bigdata.xls");
workbook.
write
(fileoutputstream)
; fileoutputstream.
close()
;long end = system.
currenttimemillis()
; system.out.
println
("時間差:"
+(end-begin)
/1000);
}
7、07版本大資料處理xssfworkbook
//xssfworkbook適合處理大資料,但是較慢,是07版本
@test
public
void
testwrite07bigdata()
throws exception
} system.out.
println
("over");
fileoutputstream fileoutputstream =
newfileoutputstream
(path +
"testwrite07bigdata.xlsx");
workbook.
write
(fileoutputstream)
; fileoutputstream.
close()
;long end = system.
currenttimemillis()
; system.out.
println
("時間差:"
+(end-begin)
/1000);
}
8、07版本大資料處理sxssfworkbook
sxssfworkbook是轉變處理大資料的07版本
//sxssfworkbook處理速度非常快
@test
public
void
testwrite07bigdatas()
throws exception
} system.out.
println
("over");
fileoutputstream fileoutputstream =
newfileoutputstream
(path +
"testwrite07bigdatas.xlsx");
workbook.
write
(fileoutputstream)
; fileoutputstream.
close()
;//清除臨時檔案
((sxssfworkbook) workbook)
.dispose()
;long end = system.
currenttimemillis()
; system.out.
println
("時間差:"
+(end-begin)
/1000);
}
1、修改pom.xml,注釋掉原來的poi和poi-ooxml
>
>
org.projectlombokgroupid
>
>
lombokartifactid
>
dependency
>
>
>
com.alibabagroupid
>
>
easyexcelartifactid
>
>
2.2.0-beta2version
>
dependency
>
>
>
com.alibabagroupid
>
>
fastjsonartifactid
>
>
1.2.55version
>
dependency
>
2、建立實體demodata
@data
public
class
demodata
3、寫入excel
static string path=
"d:\\github\\lucas-poi\\"
;private list
data()
return list;
}/**
* 最簡單的寫
*/@test
public
void
******write()
4、讀excel EasyExcel除錯記錄
一.pom.xml com.alibaba easyexcel 2.2.6 二.必須要finish才會寫入,不finish只會建立empty的檔案。writesheet writesheet easyexcel.writersheet 測試1 head list build excelwriter....
EasyExcel讀寫操作
com.alibaba easyexcel 2.1.1 org.apache.poi poi3.1.7 org.apache.poi poi ooxml 3.1.7 注意版本對應 data allargsconstructor noargsconstructor tostring public cl...
EasyExcel匯入匯出
註解 匯出 匯出 excel 乙個 sheet,帶表頭 param list 資料 list,每個元素為乙個 baserowmodel param filename 匯出的檔名 param sheetname 匯入檔案的 sheet 名 param model 對映實體類,excel 模型 匯出檔案...