Welcome

首页 / 软件开发 / C++ / 直接读取Excel文件数据

直接读取Excel文件数据2010-11-04weigf前言

由于种种需要直接进行读取Excel文件数据,然而在网上Search多次也没有找到好的方法,

一般就通过ODBC或OLE方式进行读取,但这两种方法都具有局限性...(我相信大家都很清楚)。

怎么办呢?没办法了,只好选择最艰难的路了--分析Excel文件格式。

介绍

MS 是众所周知的电子表格处理软件。Excel文件格式是特定的BIFF(Binary Interchange File Format),BIFF里存储了很多记录,第条记录包括记录头和记录体。记录头是4byte,前两位指定记录类型的代码(opcode),后两位指定记录长度;记录体是存储该记录的实际数据。

比如:

BOF record
| Record Header | Record Body |
Byte | 0 1 2 3 | 0 1 2 3 |
-----------------------------------------
Contents | 09 | 00 | 04 | 00 | 02 | 00 | 10 | 00 |
-----------------------------------------
| opcode | length | version | file |
| | | number | type |
记录头:
opcode: 09h is BOF;
length: 04h record body is 4 bytes long;
记录体:
version number:02h is version number (2 for the initial version of Excel)
file type:10h is a worksheet file;
具体可参考MS Excel File Format。

描述