question 1 :
I know that c++ could write/ read excel file by changing it into csv format. however, if the content of a cell has a "," inside, then we may have problem when we are reading it as the content may be split into two parts. So how to tackle this problem?

question 2:
Beisdes, is it possible for c++ to read or write excel file directly without changing it into csv?

question 3:
If the content of a CSV file ( which is used for reading) has some chinese characters, then when I write the content back to another new CSV file, some of the characters could not be displayed. How could I eliminate this problem?

question 4:
I have written a c++ program which will read and write csv file.
Is it possible to make an interface for choosing the file to open or write without changing the code inside?

Thank you very much !!!!!!!!!!!!!!!!!!!!!

question 1 :
I know that c++ could write/ read excel file by changing it into csv format. however, if the content of a cell has a "," inside, then we may have problem when we are reading it as the content may be split into two parts. So how to tackle this problem?

question 2:
Beisdes, is it possible for c++ to read or write excel file directly without changing it into csv?

question 3:
If the content of a CSV file ( which is used for reading) has some chinese characters, then when I write the content back to another new CSV file, some of the characters could not be displayed. How could I eliminate this problem?

question 4:
I have written a c++ program which will read and write csv file.
Is it possible to make an interface for choosing the file to open or write without changing the code inside?

Thank you very much !!!!!!!!!!!!!!!!!!!!!

Have you ever actually looked at a .xls file? It's a mess of all sorts of non-printable characters which looks like jibberish to me. Presumably there is some file that explains the .xls format, but my guess is that it's a Microsoft trade secret. I could be wrong, but I don't think they release that stuff. Without knowing the format, I don't know how you could even begin to read from or write to a .xls file.

As above but I guess you might have the problem of wanting to read only a small number of elements. But even if you could do it would you want to fence yourself into a release of Excel? Much better to write open code using defined interfaces if at all possible.

Q1: As for the comma issue try dumping the file tab separated for example. It doesn't have to be a 'comma'.

Q3: Sorry no idea on chinese chars beyond checking the type is correct but I expect you have done that.

Q4: What type of program is it? If it is console then just pass the file name as a argument (argv). Or you could use cin and cout <iostream>to ask the user to enter a name.

hope that helps

commented: agree with point for Q1 (use a tab) +22

Microsoft Excel is an out of process COM server and COM interfaces can be used to read/write anything from it or out of it.

In a pinch I'd use ODBC direct and connect to the Microsoft Jet Database Engine. I don't believe many people know this but the aformentioned can minipulate Excel *.xls files in addition to Microsoft Access databases. Once you know how to use ODBC direct its very easy to do. But not many folks know ODBC direct.

I've posted examples of how to do this in the PowerBASIC forums. Perhaps I ought to translate that to C++ & post it somewhere. Afterall, Excel is widely used.

Here's a link to a lot of info about Excel in the PowerBASIC forums. With that language there is a built in COM implementation that can easily read/write Excel spreadsheets. However, the COM techniques rely on Excel being installed on the computer where the program is running. The ODBC techniques do not. About midway through this link I have ODBC code posted to do this. Translating it to C/C++ would be easy.

http://www.powerbasic.com/support/pbforums/showthread.php?t=13881

Just one more thought. I believe you could probably also use Ado to connect to Excel. Never done it myself though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.