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 ( ... ).
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.
Using the code
It is really simple! Just like this:
- Construct a local object of the
CHtmlEdit class with all strings that should be shown in the body of the file.
CHtmlEdit oHtmlEdt ("Title", "John Doe", "Test Table", "Marquee Text", "http://codeproject.com", "Link to a Cool Site", "#C0C0C0", "#000000", "#ff6666", "#ffffcc");
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).
- Write a variable no. of columns (headlines) to the table:
int InsertTableHeader(int iItemNo, CString sFirstItem, ...);
This example adds 3 columns to the table:
oHtmlEdt.InsertTableHeader(3, "Header 1", "Header 2", "Header 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 (
- Write a variable no. of rows to the table:
int InsertTableRow(CString sFirstItem, ...);
Example for 3 columns:
oHtmlEdt.InsertTableRow("cell 1", "cell 2", "cell 3");
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 (
>) the string will be transformed to an email address and the brackets will be removed.
- Write the HTML code to a file:
void WriteHTMLFile(CString sFullPath);
Points of Interest
I learned how to use a variable amount of arguments for functions.
Updates are not planned yet.
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
but i know that this is not possible. It's
real fun for me and I do small Programms for my own
O.K. enough written..... I need my Time to debug
everything that crosses my way!