Hi im a new learner on c++ and i need help on how to save the output file in Excel format? any examples can be shown?
All helps are highly appreciated. thanks
Hi im a new learner on c++ and i need help on how to save the output file in Excel format? any examples can be shown?
All helps are highly appreciated. thanks
Saving files in actual .xls format is very hard work. It is a proprietary binary format owned by Microsoft. You can download the specification of the file format, but it will none the less involve a lot of work.
On the other hand, excel is automatically bound to .csv as well, which is exceedingly easy for programs to create. It's just a text file
Code:ofstream of("myfile.csv"); of << "1,2,3" << endl;
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
is there any examples u know? so i can look at it
Search:
Type: Forums, Posts, Groups, Visitor Messages; Keyword(s): excel, format
http://cboard.cprogramming.com/searc...earchid=259219
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
First thing, can you get away with just outputting csv?
If not, explain why not so that we can confirm your reasoning.
Then if not, be prepared for a lot of hard work. It can be done through the Office COM components but you are not going to get very far quickly there.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
owh yea i have tried the .csv file and it works. thanks..... i have another problem which as shown below
cout << "Please enter the name of the file to write to.\n";
cout << "File name: ";
cin >> FileName;
cin.get();
cout << "Please type any text to save to the file.\n";
cout << "Text: ";
cin.getline(UserInput, 512);
ofstream bravo;
bravo.open(FileName);
bravo << UserInput;
bravo.close();
the problem is i got an error after compiling it says : no matching function for call to `std::basic_ofstream<char, std::char_traits<char> >:pen(std::string&)'
can anyone help me to point out where my mistake is?
That is not true.
Using Microsoft run-time components would not give Microsoft a claim to royalties from a program developer. However, if your program was to require certain files from the office distribution, there would probably be some license fee (paid by either you or the end user) if you distribute and install those files. It would be easier to simply stipulate that your program requires Office to be installed.
The error message is telling you that ofstream::open() does not accept an argument of type std::string.
Change the line "bravo.open(FileName)" to "bravo.open(FileName.c_str())"
Next time, read the documentation. And disable smilies in your posts.
owh yea sorry the smile just appear itself when i paste it...
i just realized that there are no numbers appear and only text appears when i open the file from the saved output in excel format. Why all the numbers missing in the excel?
Post your code to generate the .csv file.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
below is the program.....the problem is when i open the .txt file the result didnt appear...only txt appear ....how im gonna solve this?
[tag]
[/tag]Code:#include <iostream> #include <math.h> #include <stdio.h> #include <iomanip> #include <stdlib.h> #include <conio.h> #include <sstream> #include <string> #include <fstream> using namespace std; int main (int argc, char *argv[]) { int V=50, R=70, freq, a, b = 180, minFreq, maxFreq, intvFreq; float L=10e-3, C=10e-6, PI=3.142, anglepol, polZ, Ipol, cart_a, cart_b; float xL, xC; char quit, restart, ans, again; float phs = 45, angVZ; do{ system ("cls"); cout << "\n This is a series RLC circuit program to calculate the current of the circuit\n" << endl; cout << "\t in Polar and Cartesian form \n" << endl; cout << "\t------------R------------L-----------C--------------" << endl; cout << "\t| |" << endl; cout << "\t----------------------AC supply---------------------" << endl; cout << "\n"; cout << endl; cout << "\n Please," << endl; cout << "\n Enter the minimum frequency: " ; cin >> minFreq ; cout << "\n Enter the maximum frequency: " ; cin >> maxFreq ; cout << "\n Enter the frequency interval: "; cin >> intvFreq ; cout << endl << "\n\tFrequency Hz\tCurren" << endl; cout <<"\t\t Polar\n"; cout <<"\t\t\t(current,deg)"; cout <<"\n" << endl; ofstream myfile; myfile.open ("currentdata.txt"); myfile << "\tcurrent of circuit\n"; myfile << "\n\n\n\tFreq\t\tcurrent\n"; for (freq=minFreq; freq<=maxFreq; freq=freq+intvFreq) { xL = 2*PI*freq*L; xC = 1/(2*PI*freq*C); if (xL > xC) { anglepol = atan((xL - xC)/R)*(b/PI); } else if (xL < xC) { anglepol = atan((xC-xL)/R)*(b/PI) ; } if (xL > xC) polZ = sqrt((R*R)+((xL - xC)*(xL - xC))); else if (xL < xC) polZ = sqrt((R*R)+((xC - xL)*(xC - xL))); angVZ = phs - anglepol; Ipol = V/polZ; cart_a = Ipol * cos(angVZ*PI/b); cart_b = Ipol * sin(angVZ*PI/b); cout.precision(2); printf ("\t%d\t\t%3.2f,%3.2f\n", freq, Ipol, anglepol); } cout << "\n\n \t\t Press r and enter to restart the program" << endl; cout << "\n \t\t\t\t or " << endl; cout << "\n \t\t Press q and enter to quit the program" << endl; myfile.close(); cout << "\n\n\tType quit to close: "; cin >> ans; }while (ans != 'q'); // quit program while(toupper(again) == 'r'); //restart program return 0; }
You may want to actually try to write some numbers into your file. Also you should not be mixing C stdio functions with C++ streams.how im gonna solve this?
Jim
so why the result didnt appear in txt file?
You never try to write anything but the text to the file. Show where you think you are writing the result to the file.
Jim