Several ways to read and write Excel files in C + +

Source: Internet
Author: User
Tags odbc


because some friends ask the code question, the OLE reads and writes the code to share in this place, everybody asks oneself to see. http://blog.csdn.net/fullsail/article/details/8449448

C + + reads Excel's XLS file in many ways, but maybe it's because there are so many ways that people will be confused when they choose.
Since the first two days to do the Guide table tool, compared with the common methods, summed up to write a short essay,

The way of 1.OLE
This is about the most common way, this way actually initiates an Excel process to read and write Excel files behind the scenes, the biggest benefit of this way is what can be done. Includes formatting Excel, adding delete sheet, reading and writing cells, and more. function is almost the most complete, and it is not particularly difficult to use.
The basic method is to use the exported. h file for OLE operations, but due to the lack of OLE interface documentation, it is not too easy to use them perfectly, but there are many examples.
It is generally believed that OLE is slow, and that OLE reads and writes in Excel the same way. But the reading speed can be improved, and if the entire data of the range of the sheet is loaded in the read, rather than a cell read, then the speed is still relatively good. Consider the principle is also very simple, the overall reading reduces the number of OLE interaction. Ole writes generally only a few more convenient, so the speed may be much faster.
My own personal experience is that an Excel file, more than 100 columns of the field, if the use of a cell reading, 1s about 3 records, if the overall reading, the speed can be increased dozens of times times.
OLE read and write Excel is very powerful, read speed can be, but the writing speed is not high, of course, this method is not portable, and you have to install Excel.

2.Basic EXCEL Mode
This is a recommended open source project on CodeProject,
Http://www.codeproject.com/KB/office/BasicExcel.aspx
The author is an Excel-based file format for processing. But why is it called basic Excel?
He does not support a lot of things, formulas, file formats, form merging, etc. (some people say Chinese support is not good), so you can think he only support the most basic Excel table,
My own attempt is that if this Excel file has other elements (formulas, formatting, etc.), reading with basic Excel will fail.
OLE read and write Excel function is weak, because it is directly based on file format operation, read and write speed are good, you do not need to follow Excel, the other way is portable, but there are some costs, its code is more obscure, and no comments, and even on the Windows platform, There are also many alarms.

Several Excel libraries on the 3.Sourceforge.
Sourceforge There are several open source of Excel library, but the perfect not much, some for PHP read and write Excel prepared, including libxls,xlslib,smartexcel and so on. I downloaded a few experiments and did not compile successfully in WIDONWS. Also.

The way of 4.ODBC
This person has not tried, but according to the principle, should only read and write.
Speed, the speed of ODBC is known to be slow.
http://www.vckbase.com/document/viewdoc/?id=421

It is worth mentioning that the author of basic Excel originally had a package cspreadsheet on CodeProject that gave the ODBC way. If you are interested, you can go and see. In fact, the heart still admire the author.
Http://www.codeproject.com/KB/database/cspreadsheet.aspx

The way of 5.ADO
The way ADO is heard should be the way to use OLE DB. And the way OLE should be no essential difference. I looked at the example and it looked like OLE.

6.LibXL
LIBXL is a library of Excel that is charged.
http://www.libxl.com/
According to his instructions, he can read the XLS file without relying on Excel. Include formatting, and so on. It should be easy to look at the example operation. But whether it can be ported to the Linux platform, I guess it's not a small challenge. Oh.
There is no way to test it because of the charge.

7. Online some claims do not use OLE Read Excel example
As a preliminary look, this should be an example of an online search for Excel format documents. Can actually operate in a way that is not strong.

=============================================================================================================== ===============
January 2015 update
In fact, it seems that the number of cubby that can be used is many.
First.
LIBXL currently uses a lot of people in China. Of course he's not really free, just ... You can find it in csdn, too.
In fact, the author did not buy too expensive.

Second.
QT-based code.
Https://github.com/dbzhang800/QtXlsxWriter
This library can read the format of xlsx. In fact, this format is also open source now.
Of course, the premise is that you use QT, this project quantity merits vast.

Third
Xlslib, this library can read in the XLS format
Http://sourceforge.net/projects/xlslib/?source=navbar

If you are using. NET, you are too happy. Optional is more than take.
http://blog.wwery.cn/?p=210
What do you want to put. NET Library to C + + can be used? This one...... I hope you will succeed.

Transferred from: http://blog.csdn.net/fullsail/article/details/4067416

Several ways to read and write Excel files in C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.