Click here to Skip to main content
Click here to Skip to main content

Fast Excel file reader with basic functionality

, 1 Jul 2006
Rate this:
Please Sign up or sign in to vote.
A set of managed classes for native reading of data from MS Excel files


When I was writing one of the projects (multi-format data parser) I had to deal with Microsoft Excel files.

First of all I tried to read data via COM interop, but this way was very slow (and sometimes input files have up to 100,000 rows and even more) and required Excel to be installed on the target machine.

Then I tried to read data via Excel's OleDb driver. When DataReader ran through data rows without reading them (i.e. while (rd.Read());) it was quite fast, but retrieving data was still very slow.

When I had tried out one of commercial products (TMS FlexCel Studio), it showed rather good results (several seconds for loading 17 MB file, 2 sheets, ~ 80 000 rows), but access to them was not very fast (at least not suitable for displaying data using DataGridView in virtual mode).

So, I decided to write my own reader for Excel files.


First of all I decided that the reader will produce a DataSet object, with sheets represented as DataTables within it. Access to DataTable is rather fast, and its TableName property is suitable for sheet title.

To read an Excel file, we need to get BIFF stream from xls OLE2 container. Working with OLE2 container is implemented in the following classes:

  • XlsHeader (file header representation)
  • XlsFat (support for file system in OLE2 container)
  • XlsRootDirectory (directory tree representation)
  • XlsDirectoryEntry, and
  • XlsStream (file stream)

Note that implementation of OLE2 container object model is limited (e.g. I didn't write any MiniFAT support code) and Excel-specific (XlsHeader supports only MS Excel header field values, any other will produce InvalidHeaderException).

Now we can parse BIFF stream with spreadsheet data. For handy reading data from stream we have a XlsBiffStream class derived from XlsStream. It provides a set of methods for reading XlsBiffRecord common structures. And then, each structure is converted to the appropriate type. Note that only a few record types are supported. All other structures are read as basic XlsBiffRecord and are ignored.

My implementation of reader ignores any text formatting, graphics, embedded objects and charts. Only cell values are read. When a cell contains a formula, the last calculated formula value is used as the cell value. Also, only indexed sheets are read (i.e. sheets with index data) - I didn't write not-indexed sheets support due to my laziness (I didn't come across any file without an index yet).

Using the code

Now, it's very easy to use the parser. All you need is a Stream with an Excel file.

FileStream fs = new FileStream(@"c:\file.xls", 
        FileMode.Open, FileAccess.Read);
ExcelDataReader rd = new ExcelDataReader(fs);

// Now we can access data:
DataSet data = rd.WorkbookData;

Points Of Interest

Latest versions of Excel use SST (Shared String Table) to store string information, and text cells only reference string by index. Also, the size of one BIFF section is limited, and SST can be rather big, so it uses the so-called CONTINUE sections. Every string in SST can be saved as Unicode (2 byte) or as ANSI (single byte per symbol). But when the string is broken with the continue section, it can change its encoding from one to another! This took me a lot of debugging, and I wish nobody has to do the same again...


This implementation of reader is rather nonoptimal (I was pressed for time), but it showed a good speed. It surely beats any interop or OLE method and even some commercial analogs.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Russian Federation Russian Federation
.NET Developer
Russian Federation

Comments and Discussions

QuestionInvalid signature error PinmemberMember 110195831-Oct-14 3:25 
Question.xlsx files PinmemberNikolaj jensen25-Sep-14 4:37 
QuestionSkip hidden rows Pinmemberecunha15-Sep-14 6:34 
QuestionReading Big Excel Files PinprofessionalRubal Walia8-Aug-14 4:17 
QuestionSee also this: PinprofessionalDietmar Schoder29-Jul-14 6:28 
Bug16 Columns problem PinmemberMarcoAurelio11-Jul-12 0:19 
Questionsolution problem only read 16 columns Pinmemberlinhphuongaard12-Jun-12 2:38 
QuestionHow to read many columns Pinmemberlinhphuongaard11-Jun-12 7:53 
QuestionLabels read wrong [modified] Pinmemberdmitry_andrianov13-Feb-12 8:54 
AnswerDateTime value are stored as floating point Pinmemberedvox113813-Oct-11 20:49 
QuestionOnly 16 columns can be imported PinmemberOsman Kazi30-Sep-11 12:38 
QuestionTrying to open an invalid file keeps the file open Pinmemberairadier23-Aug-11 3:58 
GeneralMy vote of 4 Pinmemberstuckne12-Feb-11 6:55 
GeneralRe: My vote of 4 PinmemberNguyen Thanh Hai26-Jul-11 7:20 
GeneralOops! Trying to read stream from FAT area. Pinmemberreferee213-Dec-10 21:00 
GeneralRe: Oops! Trying to read stream from FAT area. Pinmemberflash6655-Apr-11 23:36 
Generalseems does not support multiple worksheet Pinmemberbluesky44851-Nov-10 3:08 
GeneralDownload source Pinmembersutter1828-Sep-10 23:37 
GeneralRe: Download source Pinmemberblam202021-Jan-11 15:35 
GeneralThis library doesn't seem to include the top row as headers or support xlsx format Pinmemberakantro8-Aug-10 4:14 
GeneralRe: This library doesn't seem to include the top row as headers or support xlsx format Pinmemberkaferkopmetluise15-Apr-12 23:43 
GeneralFor excel 2007 & 2010 PinmemberMember 440278925-Jul-10 22:35 
GeneralHidden sheets Pinmemberreferee28-Jul-10 1:34 
QuestionUpdate Code PinmemberJoel Lovison13-Oct-09 13:25 
GeneralHyperlinks PinmembernKognito6-Oct-09 22:39 
GeneralError executing library in MONO Pinmembereyanson26-Sep-09 13:43 
GeneralRe: Error executing library in MONO Pinmembergg423714-Oct-09 5:16 
Generalplease explain the code to me please its urgent............. Pinmemberprasanth.shenoy25-Jun-09 19:12 
GeneralFailed to read column 16 Pinmemberalper ebicoglu11-Jun-09 23:34 
GeneralRe: Failed to read column 16 PinmemberRichard at BDG20-Aug-09 5:30 
QuestionReading a protected workbook PinmemberHervé29-Mar-09 13:41 
QuestionDate Is not Code Pinmemberjatin_chauhan26-Mar-09 1:08 
GeneralRe: Date Is not Code PinmemberGirijesh116-Apr-09 6:12 
AnswerRe: Date Is not Code PinmemberMurat YILMAZ3-May-09 23:34 
GeneralRe: Date Is not Code PinmemberAbu Bakr El-seddiq4-Apr-10 7:08 
GeneralRe: Date Is not Code PinmemberGlaukos26-Apr-10 14:42 
QuestionExcel Reader does not give any result with some excel files PinmemberSandeep Maharana25-Feb-09 23:21 
AnswerRe: Excel Reader does not give any result with some excel files Pinmembernpcomplete125-Mar-09 8:35 
QuestionLots of 'NOT FOUND #XXXXX' PinmemberRG1-Feb-09 2:10 
AnswerRe: Lots of 'NOT FOUND #XXXXX' [modified] Pinmembernpcomplete12-Feb-09 3:09 
GeneralRe: Lots of 'NOT FOUND #XXXXX' PinmemberRG3-Feb-09 3:37 
GeneralRe: Lots of 'NOT FOUND #XXXXX' Pinmember外城25-Jan-10 17:12 
General'NOT FOUND #xx' proposed solution Pinmembernpcomplete19-Dec-08 16:53 
GeneralRe: 'NOT FOUND #xx' proposed solution Pinmemberlinuxsuperfans13-Dec-08 20:56 
GeneralRe: 'NOT FOUND #xx' proposed solution Pinmembernpcomplete117-Dec-08 14:06 
GeneralRe: 'NOT FOUND #xx' proposed solution Pinmembernpcomplete121-Dec-08 15:24 
Questiononly can read digital Pinmemberlinuxsuperfans5-Dec-08 23:10 
AnswerRe: only can read digital Pinmemberlinuxsuperfans6-Dec-08 3:00 
AnswerRe: only can read digital Pinmembernpcomplete19-Dec-08 8:24 
AnswerRe: only can read digital Pinmembernpcomplete19-Dec-08 17:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 1 Jul 2006
Article Copyright 2006 by Messir
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid