網(wǎng)站首頁 編程語言 正文
github地址?https://github.com/exceldatareader/exceldatareader
1.在NuGet中輸入excel搜索,點擊安裝這兩個如圖
2.新建一個類,寫入代碼
class ExcelReader
{
public List> getData(string filePath)
{
List> list = new List>();
using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
{
// Auto-detect format, supports:
// - Binary Excel files (2.0-2003 format; *.xls)
// - OpenXml Excel files (2007 format; *.xlsx, *.xlsb)
using (var reader = ExcelReaderFactory.CreateReader(stream))
{
var configuration = new ExcelDataSetConfiguration { ConfigureDataTable = tableReader => new ExcelDataTableConfiguration { UseHeaderRow = true } };
DataSet result = reader.AsDataSet(configuration);
for (int i = 0; i < result.Tables[0].Rows.Count; i++)
{
Dictionary dict = new Dictionary();
for (int j = 0; j < result.Tables[0].Columns.Count; j++)
{
dict.Add(result.Tables[0].Columns[j].ColumnName, result.Tables[0].Rows[i][j]);
}
list.Add(dict);
}
}
}
return list;
}
}
?
原文鏈接:https://blog.csdn.net/zxw75192/article/details/113406767
相關(guān)推薦
- 2023-03-17 Python導(dǎo)入Excel表格數(shù)據(jù)并以字典dict格式保存的操作方法_python
- 2023-04-07 C/C++浮點數(shù)使用的兩個注意事項詳解_C 語言
- 2022-04-12 push到碼云上報錯 ! [rejected] master -> m
- 2022-07-21 Pandas常用數(shù)據(jù)結(jié)構(gòu)
- 2022-11-27 詳解Go語言如何實現(xiàn)字符串切片反轉(zhuǎn)函數(shù)_Golang
- 2022-04-15 關(guān)于pyinstaller生成.exe程序報錯:缺少.ini文件的分析_python
- 2022-12-15 Android?NotificationListenerService?通知服務(wù)原理解析_Andro
- 2022-07-03 C#預(yù)定義的基礎(chǔ)類型轉(zhuǎn)換_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支