Click here to Skip to main content
Click here to Skip to main content

Create HTML File (Table)

, 18 Apr 2004
Rate this:
Please Sign up or sign in to vote.
An article on creating HTML files with VC++.

Sample Image

Introduction

This simple class writes a HTML file with a table. There is no limit on the rows or columns due to the usage of variable argument functions ( ... ).

Background

I needed to write the contents of a list control to a HTML file, so I wrote this class which is able to write a table without limits to the no. of columns or rows. This class is a fast hack and shows nearly no error handling. But you can use it as a starting point for your own class. If you find this useful, fine! If not, don't flame me. Wink | ;-)

Using the code

It is really simple! Just like this:

  1. Construct a local object of the CHtmlEdit class with all strings that should be shown in the body of the file.
    CHtmlEdit oHtmlEdt ("Title", // Title of the HTML-File
      "John Doe",                // Author of the HTML-File
      "Test Table",              // The caption of the Table
      "Marquee Text",            // The Scrolling Text
      "http://codeproject.com",  // A Link which will be placed in the Footer
      "Link to a Cool Site",     // Text for the link above
      "#C0C0C0",                 // Backgroundcolor of the HTML-File (HTML-Notation)
      "#000000",                 // Textcolor of the HTML-File (HTML-Notation)
      "#ff6666",                 // Backgroundcolor of the Header (HTML-Notation)
      "#ffffcc");                // Backgroundcolor of the Table (HTML-Notation)

    If you add something (description for the table or something) as scrolling text, the scrolling text (MARQUEE) and two buttons will be shown, one to pause the scrolling and one to resume the scrolling. If you don't want MARQUEE, then supply nothing (default).

  2. Write a variable no. of columns (headlines) to the table:
    int InsertTableHeader(int iItemNo, // No. of columns
               CString sFirstItem,     // The CString which is to 
                                       // add to the first column
               ...);                   // all CStrings for the columns

    This example adds 3 columns to the table:

    oHtmlEdt.InsertTableHeader(3,     // add 3 columns to the table
                        "Header 1",   // string for the headline of column 1
                        "Header 2",   // string for the headline of column 2
                        "Header 3");  // string for the headline of column 3

    You can add any no. of columns to the table but then you have to supply this function with the same no. of strings (CStrings).

  3. Write a variable no. of rows to the table:
    int InsertTableRow(CString sFirstItem,  // The CString which is to
                                            // add to the first column
                       ...);                // all other CStrings(!)

    Example for 3 columns:

    oHtmlEdt.InsertTableRow("cell 1",   // string for the 1st cell in column 1
                            "cell 2",   // string for the 2nd cell in column 1
                            "cell 3");  // string for the 3rd cell in column 1

    You have to supply this function call with the same no. of strings (CStrings) as rows are defined. The strings can be empty but they must be there. You can put this function call into a loop in which the cells of a list control are requested. If the string contains brackets (< or >) the string will be transformed to an email address and the brackets will be removed.

  4. Write the HTML code to a file:
    void WriteHTMLFile(CString sFullPath); 
    // sFullPath is the path AND the Filename

    Example:

    oHtmlEdt.WriteHTMLFile("TestTable.HTML");

Points of Interest

I learned how to use a variable amount of arguments for functions.

History

Updates are not planned yet.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Thomas Latuske
Web Developer
Germany Germany
My name is Thomas, I'm born on January the 11th in
1970, right now I'm working in the Quality department
of a big Pipe mill as a Technician.
My hobbies are my girl friend, my car, RC-Planes and
Computers. I begun with VC++ some time ago and now
Programming is like a drug to me (I'm still a
beginner). I want to learn it all in a blink of an
eye Wink | ;-) but i know that this is not possible. It's
real fun for me and I do small Programms for my own
use.
O.K. enough written..... I need my Time to debug
everything that crosses my way! Wink | ;-)

Comments and Discussions

 
Questionhow to seperate images? Pinmembersamathareddy_p28-Feb-05 7:45 
GeneralNetscape! PinsussAnonymous19-Apr-04 8:51 
GeneralRe: Netscape! PinmemberThomas Latuske19-Apr-04 11:09 
GeneralAnother way PinmemberAnna-Jayne Metcalfe18-Apr-04 23:37 
Why not just output the data you want to present and use an XSLT template to transform it to the display format you want?
 
That way, you can offer the user a choice of which template they want to use - or allow them to define their own. Smile | :)
 
I've used this technique in my ResOrg add-in and it's incredibly powerful...I'm even able to supply custom templates without recompiling the app!
 
Anna Rose | [Rose]
 
Homepage | Tears and Laughter
 
"Be yourself - not what others think you should be"
- Marcia Graesch
 
"Anna's just a sexy-looking lesbian tart"
- A friend, trying to wind me up. It didn't work.
 
Trouble with resource IDs? Try the Resource ID Organiser Visual C++ Add-In

GeneralRe: Another way PinmemberThomas Latuske19-Apr-04 11:12 
GeneralRe: Another way PinmemberAnna-Jayne Metcalfe19-Apr-04 11:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141216.1 | Last Updated 19 Apr 2004
Article Copyright 2004 by Thomas Latuske
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid