need to use C to create/edit excel spreadsheet

This is a discussion on need to use C to create/edit excel spreadsheet within the Windows Programming forums, part of the Platform Specific Boards category; is this ridiculously complicated? does anyone know where there is a very simple, very basic example? or can someone post ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    need to use C to create/edit excel spreadsheet

    is this ridiculously complicated?
    does anyone know where there is a very simple, very basic example? or can someone post 1?

    thank you

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    5
    ok then... answered that one myself. forget it

  3. #3
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Well Excell can open delimited files as spreadsheets so you could create and edit via that, but a preexisting spreadsheet you would have to save as a delimited file.

    EDIT:
    @Bubba... so my spelling sucks... oh well. As long as I consistantly misspell it wont affect my programming!
    Last edited by Wraithan; 10-03-2006 at 11:36 PM.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    You mean delimited file?

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    very simple, very basic example
    Code:
    // Compile: cl.exe /MT excel.cpp /link /IGNORE:4089
    
    #pragma comment( lib, "ole32.lib" )   // Search for ole32.lib while linking
    #pragma warning(disable : 4995)   // Disable deprecated warning
    
    #include <afxdb.h>
    #include <iostream.h>
    
    int  main(void)
    {
        CDatabase database;
        CString sDriver = "MICROSOFT EXCEL DRIVER (*.XLS)"; // exactly the same name as in the ODBC-Manager
        CString sSql;
        CString sColumn1, sColumn2;
        CString sExcelFile = "MyExcel.XLS";  
        // Build the creation string for access without DSN
        sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s",
            sDriver, sExcelFile, sExcelFile);
        // Create the spreadsheet (i.e. Excel sheet)
        if( database.OpenEx(sSql,CDatabase::noOdbcDialog) )
        {
            // Create table structure
            sSql = "CREATE TABLE MYTABLE (Name1 TEXT(15), Name2 TEXT(15))";
            database.ExecuteSQL(sSql);
            // Add 3 records to excel table
            sSql.Format("INSERT INTO MYTABLE  VALUES ('%s','%s')","Bob", "Freddy" );
            database.ExecuteSQL(sSql);
            sSql.Format("INSERT INTO MYTABLE  VALUES ('%s','%s')","Jimmy", "Eddy" );
            database.ExecuteSQL(sSql);
            sSql.Format("INSERT INTO MYTABLE  VALUES ('%s','%s')","Frank", "Walter" );
            database.ExecuteSQL(sSql);
            CRecordset recset( &database );
            // Build the SQL statement
            sSql =  "SELECT * FROM MYTABLE";
            // Execute the query
            recset.Open(CRecordset::none,sSql,CRecordset::readOnly);
            // Loop through each record
            for (recset.MoveFirst(); !recset.IsEOF(); recset.MoveNext())
            {
                recset.GetFieldValue(0,sColumn1);
                recset.GetFieldValue(1,sColumn2);
                cout << sColumn1 << " " << sColumn2 << endl;
            }
            database.Close();
        }
        return 0;
    }
    Last edited by BobS0327; 10-04-2006 at 04:32 PM.

  6. #6
    Registered User
    Join Date
    Jan 2011
    Posts
    1

    help

    sry but i have a problem i have just finshed learnin but i am getting an error

    cannot convet char* to int;

    and i have no way of correctin it...can you help???

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    post your code....

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Meh - driveby thread hijacking.

    Shen ron, start a new thread, with YOUR code (and make sure it has code tags as per the intro threads).
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dissecting an Excel XML spreadsheet
    By desmond5 in forum C++ Programming
    Replies: 1
    Last Post: 05-22-2008, 04:32 PM
  2. Reading/Writing an Excel Spreadsheet?
    By Blackroot in forum Windows Programming
    Replies: 3
    Last Post: 10-15-2007, 09:59 PM
  3. Replies: 2
    Last Post: 11-30-2006, 07:04 AM
  4. Replies: 1
    Last Post: 05-05-2006, 11:17 PM
  5. Is it possible to write into an Excel spreadsheet?
    By rtsc17 in forum C++ Programming
    Replies: 6
    Last Post: 09-18-2003, 10:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21