This library is built based on the following documents, thanks to their authors:
Record structures in BIFF8/BIFF8X format are considered.
Now this project is hosted on Google Code.
You can get the latest code, report issues and submit improvements from there.
What It Can Do?
- It can read worksheets in a workbook and read cells in a worksheet.
- It can read cell content (text, number, datetime, or error) and cell format (font, alignment, linestyle, background, etc.).
- It can read pictures in the file, get information of image size, position, data, and format.
- It can create a workbook and save to file.
Using the Code
- Open file:
Stream fileStream = File.OpenRead(file);
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets;
- Read cell:
int row = 1;
int col = 0;
string ID = sheet.Cells[row, col].StringValue;
Picture pic = sheet.ExtractPicture(row, col);
- Create workbook:
string file = "C:\\newdoc.xls";
Workbook workbook = new Workbook();
Worksheet worksheet = new Worksheet("First Sheet");
worksheet.Cells[0, 1] = new Cell(1);
worksheet.Cells[2, 0] = new Cell(2.8);
worksheet.Cells[3, 3] = new Cell((decimal)3.45);
worksheet.Cells[2, 2] = new Cell("Text string");
worksheet.Cells[2, 4] = new Cell("Second string");
worksheet.Cells[4, 0] = new Cell(32764.5, "#,###.00");
worksheet.Cells[5, 1] = new Cell(DateTime.Now, @"YYYY\-MM\-DD");
worksheet.Cells.ColumnWidth[0, 1] = 3000;
- Traverse worksheet:
foreach (Pair<Pair<int, int>, Cell> cell in sheet.Cells)
dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
for (int rowIndex = sheet.Cells.FirstRowIndex;
rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
Row row = sheet.Cells.GetRow(rowIndex);
for (int colIndex = row.FirstColIndex;
colIndex <= row.LastColIndex; colIndex++)
Cell cell = row.GetCell(colIndex);
- Displayed each Sheet in separate tabpage
- Fixed some bugs in FORMULA.cs and Form1.cs
- Changed default Encoding from ASCII to UTF8 in Record.cs ln97 (suggested by ragundo)
EmptyCell instead of
null for non existing cells (requested by amrlafi)
- Bug fix in Record.cs ln83 and ln133 (proposed by dhirshjr and ilogpasig)
- Tried to fix bug in CompoundDocument.cs (found by stevenbright)
- Create, Open and Modify
- Save modified
- Encoded workbook and worksheet to BIFF8 records
- Fixed a bug that compressed Unicode string wrongly decoded by UTF8
- Fixed XF format so that the created *.xls file can be opened by Microsoft Excel 2003
- Assigned number format for number and date time values
- Set column widths
- Updated project source code and article text
- Many bug fixes
- Added support to create and modify *.xls files
- Fix for getting 'NaN' when reading
string value of a formula cell
- Start a Google Code project
- Support for decode cell format and encode predefined cell format
- Changed namespaces and directory structure
- Added some test cases
- Initial implementation of encode images