Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
6dd660c9
S
SpringBoot-kwan
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringBoot-kwan
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot-kwan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6dd660c9
编写于
8月 14, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:读取excel工具类
上级
cc192e53
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
169 addition
and
0 deletion
+169
-0
pom.xml
pom.xml
+6
-0
src/main/java/com/kwan/springbootkwan/entity/ExcelData.java
src/main/java/com/kwan/springbootkwan/entity/ExcelData.java
+53
-0
src/main/java/com/kwan/springbootkwan/utils/ExcelReader.java
src/main/java/com/kwan/springbootkwan/utils/ExcelReader.java
+110
-0
未找到文件。
pom.xml
浏览文件 @
6dd660c9
...
...
@@ -181,6 +181,12 @@
<artifactId>
mapstruct
</artifactId>
<version>
${mapstruct.version}
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
4.1.2
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
src/main/java/com/kwan/springbootkwan/entity/ExcelData.java
0 → 100644
浏览文件 @
6dd660c9
package
com.kwan.springbootkwan.entity
;
import
lombok.Data
;
/**
* excel实体类
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/8/14 14:59
*/
@Data
public
class
ExcelData
{
private
String
product_id
;
private
String
productName
;
private
String
categoryName2
;
private
String
genderName
;
private
double
productYearName
;
private
String
seasonName
;
private
String
colorName
;
private
String
styleName
;
private
double
avg_sal_price
;
private
double
gross_margin
;
private
double
total7_size_store_day
;
private
double
discount
;
private
double
sal_store_count
;
private
double
day_7_sal_qty_store_rate_rank
;
private
double
inv_store_qty
;
private
String
ondesk_date
;
private
double
inv_store_ratio
;
private
double
avg_now_price
;
private
double
all_store_num
;
private
double
day_7_size_store_day_rank
;
private
double
total_ondesk_day
;
private
double
total_replenish_qty
;
private
double
initial_order_qty
;
private
double
arrive_qty
;
private
double
sal_out_rate
;
private
double
total_arrive_qty
;
private
double
inv_out_qty
;
private
double
total_sal_rank
;
private
double
total_sal_qty
;
private
double
inv_qty
;
private
double
replenish_not_arrive_qty
;
private
String
counter_date
;
private
double
total_sal_amt
;
private
double
total_discount
;
private
double
sal_qty
;
private
double
inv_store_count
;
private
double
total_purchase_qty
;
private
double
day_30_size_store_day_rank
;
private
double
inv_sal_ratio
;
}
src/main/java/com/kwan/springbootkwan/utils/ExcelReader.java
0 → 100644
浏览文件 @
6dd660c9
package
com.kwan.springbootkwan.utils
;
import
com.kwan.springbootkwan.entity.ExcelData
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Objects
;
/**
* 读取excel工具类
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/8/14 15:28
*/
public
class
ExcelReader
{
public
static
List
<
ExcelData
>
readExcel
(
String
filePath
)
{
List
<
ExcelData
>
dataList
=
new
ArrayList
<>();
try
(
FileInputStream
fis
=
new
FileInputStream
(
filePath
);
Workbook
workbook
=
new
XSSFWorkbook
(
fis
))
{
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
Iterator
<
Row
>
rowIterator
=
sheet
.
iterator
();
// Skip the header row
if
(
rowIterator
.
hasNext
())
{
rowIterator
.
next
();
}
//忽略第二行
if
(
rowIterator
.
hasNext
())
{
rowIterator
.
next
();
}
while
(
rowIterator
.
hasNext
())
{
Row
row
=
rowIterator
.
next
();
final
ExcelData
excelDataFromRow
=
createExcelDataFromRow
(
row
);
if
(
Objects
.
nonNull
(
excelDataFromRow
))
{
dataList
.
add
(
excelDataFromRow
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
dataList
;
}
private
static
ExcelData
createExcelDataFromRow
(
Row
row
)
{
ExcelData
data
=
new
ExcelData
();
final
Cell
cell
=
row
.
getCell
(
0
);
if
(
Objects
.
isNull
(
cell
))
{
return
null
;
}
DecimalFormat
decimalFormat
=
new
DecimalFormat
(
"0"
);
data
.
setProduct_id
(
decimalFormat
.
format
(
cell
.
getNumericCellValue
()));
data
.
setProductName
(
row
.
getCell
(
1
).
getStringCellValue
());
data
.
setCategoryName2
(
row
.
getCell
(
2
).
getStringCellValue
());
data
.
setGenderName
(
row
.
getCell
(
3
).
getStringCellValue
());
data
.
setProductYearName
(
row
.
getCell
(
4
).
getNumericCellValue
());
data
.
setSeasonName
(
row
.
getCell
(
5
).
getStringCellValue
());
data
.
setColorName
(
row
.
getCell
(
6
).
getStringCellValue
());
data
.
setStyleName
(
row
.
getCell
(
7
).
getStringCellValue
());
data
.
setAvg_sal_price
(
row
.
getCell
(
8
).
getNumericCellValue
());
data
.
setGross_margin
(
row
.
getCell
(
9
).
getNumericCellValue
());
data
.
setTotal7_size_store_day
(
row
.
getCell
(
10
).
getNumericCellValue
());
data
.
setDiscount
(
row
.
getCell
(
11
).
getNumericCellValue
());
data
.
setSal_store_count
(
row
.
getCell
(
12
).
getNumericCellValue
());
data
.
setDay_7_sal_qty_store_rate_rank
(
row
.
getCell
(
13
).
getNumericCellValue
());
data
.
setInv_store_qty
(
row
.
getCell
(
14
).
getNumericCellValue
());
data
.
setOndesk_date
(
row
.
getCell
(
15
).
getStringCellValue
());
data
.
setInv_store_ratio
(
row
.
getCell
(
16
).
getNumericCellValue
());
data
.
setAvg_now_price
(
row
.
getCell
(
17
).
getNumericCellValue
());
data
.
setAll_store_num
(
row
.
getCell
(
18
).
getNumericCellValue
());
data
.
setDay_7_size_store_day_rank
(
row
.
getCell
(
19
).
getNumericCellValue
());
data
.
setTotal_ondesk_day
(
row
.
getCell
(
20
).
getNumericCellValue
());
data
.
setTotal_replenish_qty
(
row
.
getCell
(
21
).
getNumericCellValue
());
data
.
setInitial_order_qty
(
row
.
getCell
(
22
).
getNumericCellValue
());
data
.
setArrive_qty
(
row
.
getCell
(
23
).
getNumericCellValue
());
data
.
setSal_out_rate
(
row
.
getCell
(
24
).
getNumericCellValue
());
data
.
setTotal_arrive_qty
(
row
.
getCell
(
25
).
getNumericCellValue
());
data
.
setInv_out_qty
(
row
.
getCell
(
26
).
getNumericCellValue
());
data
.
setTotal_sal_rank
(
row
.
getCell
(
27
).
getNumericCellValue
());
data
.
setTotal_sal_qty
(
row
.
getCell
(
28
).
getNumericCellValue
());
data
.
setInv_qty
(
row
.
getCell
(
29
).
getNumericCellValue
());
data
.
setReplenish_not_arrive_qty
(
row
.
getCell
(
30
).
getNumericCellValue
());
data
.
setCounter_date
(
row
.
getCell
(
31
).
getStringCellValue
());
data
.
setTotal_sal_amt
(
row
.
getCell
(
32
).
getNumericCellValue
());
data
.
setTotal_discount
(
row
.
getCell
(
33
).
getNumericCellValue
());
data
.
setSal_qty
(
row
.
getCell
(
34
).
getNumericCellValue
());
data
.
setInv_store_count
(
row
.
getCell
(
35
).
getNumericCellValue
());
data
.
setTotal_purchase_qty
(
row
.
getCell
(
36
).
getNumericCellValue
());
data
.
setDay_30_size_store_day_rank
(
row
.
getCell
(
37
).
getNumericCellValue
());
data
.
setInv_sal_ratio
(
row
.
getCell
(
38
).
getNumericCellValue
());
return
data
;
}
public
static
void
main
(
String
[]
args
)
{
String
filePath
=
"/Users/qinyingjie/Downloads/商品运营助手_滴小R_样例数据_edited.xlsx"
;
List
<
ExcelData
>
dataList
=
readExcel
(
filePath
);
for
(
ExcelData
data
:
dataList
)
{
System
.
out
.
println
(
data
);
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录