| | |
How to read/write to an MS-Excel file??
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
How to output to an excel file and how to read from it??
i have done the writing part...to use
and is there any special format to save that excel file..because when i save it with the extension .xls then it says every time i try to open it...
i have done the writing part...to use
"\t" for moving to next cell in same row and "\n" to move to next row...and is there any special format to save that excel file..because when i save it with the extension .xls then it says every time i try to open it...
•
•
•
•
the file is not known with this extension check whether it is corrupted.
Life is about being happy...
.xls files are a proprietary (that's secret) format of microsoft.
For something portable, the best is "Comma Separated Values", or CSV.
So you would have say
1,2,3
hello,world
"and now, the news","for today"
If you save this text file with the extension .csv, then excel should be able to read it just fine.
For something portable, the best is "Comma Separated Values", or CSV.
So you would have say
1,2,3
hello,world
"and now, the news","for today"
If you save this text file with the extension .csv, then excel should be able to read it just fine.
no i m not able to read from it with an
i told you how i m doing the writing part....
as excel file hav entries in cells so we need to advance the file pointer to next cell after reading one...how to do that...
we can do that by
ifstream fin("filename.cvs") object...i told you how i m doing the writing part....
as excel file hav entries in cells so we need to advance the file pointer to next cell after reading one...how to do that...
we can do that by
fout<<"\t" while writing with an object ofstream fout("filename.cvs") Life is about being happy...
post your code. The cells should be separated by comms, spaces or tabs. Each row separated with '\n'. I would use a combination of stringstream and getline() to read the file and separate its cells.
Something like this which assumes cells are separated with white space. A little different when separated by commas.
Something like this which assumes cells are separated with white space. A little different when separated by commas.
C++ Syntax (Toggle Plain Text)
std::string line; std::ifstream in("filename here"); while( getline(line) ) { vector<string> cells; stringstream str(line); std::string cel; while( str >> cel) { cells.push_back(cel); } // now do something with the individual cells }
Last edited by Ancient Dragon; Dec 29th, 2007 at 12:48 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jan 2008
Posts: 6
Reputation:
Solved Threads: 2
You cannot read and write .xls file using file manipulation functions in c/c++ because it is pre-formatted by excel. However, you can do such on a .csv file since it is just a in a "plain text" format like .txt. You can verify this by comparing the content of a .xls and .csv file using notepad. I`m telling you, you cannot read the content of .xls file.
However, if you are using c++ object oriented builder like borland c++ or visual c++, you can do what you want to do in the file. But you have to study how it work because the functions is very much different to the traditional c/c++. Take a look at this one for example, http://www.jcmiras.net/jcm/item/45/. You have to study object oriented functions like olepropertyget, variant, etc. In short, its hard but worthwhile.
However, if you are using c++ object oriented builder like borland c++ or visual c++, you can do what you want to do in the file. But you have to study how it work because the functions is very much different to the traditional c/c++. Take a look at this one for example, http://www.jcmiras.net/jcm/item/45/. You have to study object oriented functions like olepropertyget, variant, etc. In short, its hard but worthwhile.
>>I`m telling you, you cannot read the content of .xls file.
It could be done but with great difficulty and probably very risky and for those reasons I wouldn't do it. The Microsoft Office SDK would be the best and safest solution but it too requires quite a bit of programming experience.
It could be done but with great difficulty and probably very risky and for those reasons I wouldn't do it. The Microsoft Office SDK would be the best and safest solution but it too requires quite a bit of programming experience.
Last edited by Ancient Dragon; Jan 5th, 2008 at 11:57 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Converting Excel Data to MSAccess .MDB in VB.NET (VB.NET)
- Manipulate Excel file using C++?? (C++)
- Get data out of excel file stored as an image (MS SQL)
- OLE2 & Binary read/write (VB.NET)
- Open Excel file from Visual Basic (Visual Basic 4 / 5 / 6)
- Reading Excel File using JAVA (Java)
- win32::ole and excel question (Perl)
- Using Microsoft Excel 10.0 Libary Object -Dang .dlls (C#)
Other Threads in the C++ Forum
- Previous Thread: double linked list array of pointers, on the right track?
- Next Thread: combo box problem..
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






