How do I create an EXCEL file in C++ (not a .txt file)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: How do I create an EXCEL file in C++ (not a .txt file)

  1. #1
    kenny Szeto Guest

    How do I create an EXCEL file in C++ (not a .txt file)


    Hi, I would like to create an EXCEL file in my c++ code. My current code
    is:

    HANDLE hFile=CreateFile("c:\\test.xls",GENERIC_WRITE,FILE_SHARE_WRITE,
    NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

    However, this creates a text delimited file. I know it creates this because
    when I save, a message box pops up saying do I want to convert it to Excel
    97 file. How can I create an excel file so that I won't get a pop up dialog
    box?

    Thanks!
    Kenny


  2. #2
    ralph Guest

    Re: How do I create an EXCEL file in C++ (not a .txt file)


    "kenny Szeto" <kenny.szeto@unitron.com> wrote:
    >
    >Hi, I would like to create an EXCEL file in my c++ code. My current code
    >is:
    >
    >HANDLE hFile=CreateFile("c:\\test.xls",GENERIC_WRITE,FILE_SHARE_WRITE,
    > NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,

    NULL);
    >
    >However, this creates a text delimited file. I know it creates this because
    >when I save, a message box pops up saying do I want to convert it to Excel
    >97 file. How can I create an excel file so that I won't get a pop up dialog
    >box?
    >
    >Thanks!
    >Kenny
    >


    There are 3 major ways to create an "Excel" file.

    1) The simplest method is to do what you just tried to do, only instead of
    a .xls extension, create a "comma-delimited" file and give it a ".csv" extension.
    You can include a "header" line. The disadvantage is of course that "formatting"
    is very limited and it is a "text" file, but .csv files are easily handled
    by Excel without complaint.

    Formatting can often by handled by using an Excel "template" when opening
    your file.

    2) Use Excel/Office automation to create the file. The best solution for
    complex spreadsheets, formatting, and integration with other office applications.
    The result will be a .xls file/worksheet if you like.

    or

    3) Get a copy of the BIFF2/4/x file format and create an .xls file from scratch.
    Be warned that this option is NOT a trivial exercise, and often doesn't provide
    a result much better than the first option.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center