Im looking for a microsoft excel example.

I found this here http://www.daniweb.com/forums/thread102795.html
but dosent give a small example of code in work.

What I gathered from the above thread was:
- You cannot write to xls extensions (What about xlsx 2008 office? & can you write to xls?)
- Each cell seperated by a comma and each row by a newline

I dont require to read from it just to write from it.

Adding new rows and not over riding the file each time.

This seems simple enough and possible, if someone could provide a small example it be very much appericated.

I would really like to write a program that writes a xls file with a few major columns and adds 1 row every week with details gathered from a C++ program,

Thankyou for all your input, Regards X

even with office 2008, you still can't write xls files without giving microsoft a sack of money, so csv would be the way to go.

The thread you're referring to, actually has the writing part in it that you need

Sorry was in a rush previously, I will elaborate now.

He has an example but it is not really clear on what it does.

Ill try break down now and once I get confirmation attempt my own version.

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    ofstream fout("excel.csv");     //CSV== comma separated  value files
    
    int a[20],b[20];
    for(int i=0 ; i<20 ; i++)
    {
            srand(i);
            a[i]=rand()%100;
            fout<<a[i]<<",";
            if(i==10)
            fout<<"\n";
   }
    
    ifstream fin("excel.csv");
    for(int i=0 ; i<20 ; i++)
    {
            fin>>b[i];
            cout<<b[i]<<"\n";      
    }    
    fout.close();
    system(("excel.csv"));    
    return 0;
}

Example so if I understand the above code correctly:
- His first opened a csv file to be writtern to
- Writes random numbers to INDIVIDUAL CELLS (A, B, C) using ","???
- After writing to 10 CELLS he wants a NEW ROW using "\n"???
- What is system(("excel.csv")); used for?

Output of the csv file would be something like:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
21, 22, 23, 24, 25, 26, 27, 28, 29, 30
31, 32, 33, 34, 35, 36, 37, 38, 39, 40

Something like that and when opened in excel:
A B C D E F G H I J
1 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
2 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
3 31, 32, 33, 34, 35, 36, 37, 38, 39, 40

All my assumptions correct? can my above questions be confirmed?

Thankyou, Regards X

Well the last line would (probably) launch Excel on a machine where Excel was installed, and all the file associations were set up correctly.

Other than that, your analysis is good.

commented: Thanks for the support! +1

perhaps this library hepls you - http://www.libexcel.com

I would really like to write a program that writes a xls file with a few major columns and adds 1 row every week with details gathered from a C++ program,

Nice link but, if learnt how to be used I can make a more graphic friendly GUI.

Do you have any ideas how to use it?

The code the show I just copy and paste into C++ and the lib file I copy to where?

Thanks, Regards X

I use dev-cpp and dev has a separate lib folder to copy library files to.

F:\Dev-Cpp\lib\

other software should (probably) have one too.

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.