1. 程式人生 > >使用ExcelDataReader讀寫excel(.xls,.xlsx)

使用ExcelDataReader讀寫excel(.xls,.xlsx)

介紹

Lightweight and fast library written in C# for reading Microsoft Excel files

ExcelDataReader是一個用c#寫的輕量級且高效的操作Microsoft Excel檔案的類庫。

安裝

可以用nuget管理工具安裝,也可以通過命令列安裝。

Install-Package ExcelDataReader

使用

FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);

//Choose one of either 1 or 2
//1. Reading from a binary Excel file ('97-2003 format; *.xls) IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream); //2. Reading from a OpenXml Excel file (2007 format; *.xlsx) IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); //Choose one of either 3, 4, or 5
//3. DataSet - The result of each spreadsheet will be created in the result.Tables DataSet result = excelReader.AsDataSet(); //4. DataSet - Create column names from first row excelReader.IsFirstRowAsColumnNames = true; DataSet result = excelReader.AsDataSet(); //5. Data Reader methods while (excelReader.Read
()) { //excelReader.GetInt32(0); } //6. Free resources (IExcelDataReader is IDisposable) excelReader.Close();

相關推薦

使用ExcelDataReaderexcel.xls,.xlsx

介紹 Lightweight and fast library written in C# for reading Microsoft Excel files ExcelDataReader

C#EXCELOLEDB方式

  用OLEDB方式讀取EXCEL的速度是非常快的。但是當Excel資料量很大時。會非常佔用記憶體,當記憶體不夠時會丟擲記憶體溢位的異常。      OLEDB方式將Excel作為一個數據源,直接用Sql語句操作資料,並且不需要安裝Office Excel就可以使用。但缺點

javaexcelPOI,支援xlsxlsx兩種格式

這應該是一個比較全的示例了,更加複雜的功能可以在此基礎上擴充套件。此示例基於apache的POI類庫,相關jar包就不列舉了。這個類庫很通用,網上很好找。 1、不包含單元格合併的寫excel /** * excel匯出到輸出流 * 誰呼叫誰負責關閉輸出流 *

用pythonexcelxlrd、xlwt

1 Examples Generating Excel Documents Using Python’s xlwt 2 3 Here are some simple examples using Python’s xlwt library to dynamically generate

java中解析上傳的excel檔案xls,xlsx

一、在maven庫中匯入相關依賴 其中poi是解析xls格式的,poi-ooxml是解析xlsx格式的 <!-- POI,excel解析相關 --> <dependency> <groupId>org.apache.poi</g

MySQL Proxy 分離實戰總結

mysql proxy;讀寫分離 規劃: 主mysql服務器:192.168.1.21 從mysql服務器: 192.168.1.22 mysql讀寫分離器:192.168.1.23 1、讀寫分離服務器上解壓安裝包,並添加對應用戶,並編輯啟動腳本; # tar xf mysql-proxy-

mycat學習02--摸打滾爬之mycat主從復制於分離線上經驗

方案 nac url 特殊 break user 啟動 通過 doc 上一篇文章講到了mycat的安裝和配置,相信驗證過的朋友已經知道了,上一篇的做法已經實現了主從復制與讀寫分離的效果,這裏給大家詳細說以下讀寫分離部分:我的架構還是雙主雙從架構:(試驗環境1主一從)效果一樣

HDFS檔案操作 通俗易懂

首先來介紹兩個概念 ▪NameNode:領導級別。管 NameNode:領導級別。管理資料塊對映;處理客戶端的讀寫請求;配置副本策略;管理HDFS的名稱空間; DataNode:員工級別。負責儲存客戶端發來的資料塊block;執行資料塊的讀寫操作。 理資料 寫詳細步驟: 1、首先

spark通過phoenixhbaseJava版-轉:https://blog.csdn.net/xiongbingcool/article/details/81458602

pom.xml <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql --> <dependency> <groupId

Qt檔案操作 文章收錄

操作檔案是各種語言和類庫的基本功能. Qt是如何讀寫檔案的呢? 在Qt的文件有就有答案. 在QFile的文件中指出了幾種操作檔案的方法, 其中QTextStream是比較好理解和使用的: 讀取操作: The next example uses QTextStream to read a text f

純前端匯出Exceljs-xlsx表格

在GitHub上js匯出excel表,start最多的應該就是js-xlsx了,這種方式簡單,易學,易懂。 直接貼上demo <!DOCTYPE html> <html> <head> <meta charset="UTF-8">

STM32CubeMX的SDIO模式下對SD卡測試附原始碼

1.問題描述:使用STM32CubeMX,配置SDIO的4bit模式,對SD卡進行讀寫測試。 2.準備工作: 軟體版本:STM32CubeMX–4.22.0 ;KEIL5 硬體平臺:原子戰艦V3 (1)軟體設定: I. SDIO選擇,這裡選擇4

spark通過phoenixhbaseJava版

pom.xml <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql --> <dependency> <groupId>or

Mybatis多資料來源分離註解實現

Mybatis多資料來源讀寫分離(註解實現) 首先需要建立兩個庫進行測試,我這裡使用的是master_test和slave_te

Apache POIExcel文件入門支援XLSXLSX格式

值得一提的是,POI的全稱是Poor Obfuscation Implementation,意為“簡陋又模糊的實現”,這和slf4j(Simple Log Facade for Java,Java簡單日誌門面)的取名有異曲同工之妙。這兩個東西實際上是非常強大的,但是它們的作者卻說自己的東西很poor、很sim

java解析Excelxlsxlsx兩種格式

https://www.cnblogs.com/hhhshct/p/7255915.html ********************************************************** 一、需要匯入的jar   1.commons-collections4-4.

pandas21 excel簡要 tcy

excel讀寫 2018/12/27 df=pd.DataFrame({'No':[1001,1002,1003],'Name':['Tom','Bob','Jim'],'Weight':[20,30,40]}) df.to_excel('foo.xlsx', sheet_name='Shee

poi讀取excelxlsxlsx

這是一個poi讀取excel的工具類,支援excel2003,2007以上版本 package io.utils; import org.apache.poi.hssf.usermodel.*; import org.apache.poi.xssf.usermodel.

JavaScript Excel檔案 原生 + NodeJs

1.JavaScript read write excel 原生 https://www.techwalla.com/articles/how-to-use-javascript-with-excel http://blog.csdn.net/foreverxyi/arti

用PythonExcel檔案&&幾種模組比較

關於初始化 Excel的com介面的具體細節我就不介紹了,需要的話直接查閱相關的MSDN文件即可。這裡只提幾個特殊的小問題。 要想得到一個可以操作的excel物件,一般可以有兩種方式: import win32com.client excel = win32com.client.Dispatch('Ex