HTML Table Generator

Environment: VC6 SP3, NT4 SP5

HTMLTableGen.gif (29721 bytes)

During my project, I made HTML table generator. Currently, I developed only 2 HTML subset classes, Button & Table what I need at my report report form.
HTML Table Generator class can be used in various way. In case of me, I make this class for simulation result form. If I make result form table with grid or other way, I have to worry about print, separate page, view class, scroll etc.. Theses burden make me decide to make HTML table generator which can solve all problems and my program users like this HTML result form. :-)

!!

How can I use this HTML Table Generator?

1. Include HtmlFile.h, HtmlFile.cpp, HtmlTable.h, HtmlTable.cpp to your project.
   Make Style directory and Put HtmlFile.dat file at Style directory.

2. Define CHtmlFile variable and create HTML file with CreateHtmlFile()


	CHtmlFile m_HtmlFile;
	CHtmlTable *pButton, *pTable;

	// Create Html File
	m_HtmlFile.CreateHtmlFile(_T(result\\result.htm), _T(Simulation Result));

3. Add Button or Table to HtmlFile

    In case of Button, I didn't make text file but do all job at source code.


	pButton = new CHtmlTable();
	pButton->m_iTableType = HTML_TABLE_BITMAP;
	pButton->m_iColumn = 2;
	pButton->m_iRow = 1;
	pButton->m_iFixedRow = 0;
	pButton->m_iFixedColumn = 0;
	pButton->m_iWidth = 50;

	// Write Header Data

	pButton->m_sAddressArray.Add(_T(http://www.rist.re.kr/eng));

	pButton->m_sAddressArray.Add(_T(http://www.codeguru.com));

	// Write Table Data
	pButton->m_sDataArray.Add(_T(image\\rist.gif));
	pButton->m_sDataArray.Add(_T(image\\codeguru.gif));

	pButton->MakeHtmlTable();
	m_HtmlFile.AddTable(pButton);
	delete pButton;

    In case of data Table, You can use text file in a data table format.
    This means your program have to write data file in data table format


	pTable = new CHtmlTable();
	pTable->ReadDataFile(_T("slab.txt"));
	m_HtmlFile.AddTable(pTable);
	delete pTable;

4. Write HTML File


	m_HtmlFile.WriteHtmlFile();

Defined Table Type

Constant Value Comment
HTML_TABLE_GRAY 0 1 fixed column with gray background color
HTML_TABLE_WHITE 1 no border, all white
HTML_TABLE_GRAYBAND 2 1 fixed column with gray, 1 fixed row with gray
HTML_TABLE_GRAY2BAND 3 1 fixed column with gray, 1fixed row with gray, 1fixed row with dark gray & colored text
HTML_TABLE_DARKGRAYBAND 4 1 fixed column with gray, 1 fixed row with dark gray
HTML_TABLE_BITMAP 5 no border, figure buttons in 1 row

!!

Data Table Format


[TITLE] 
Mill Edger Train // You can ignore title
[TYPE]
3		// Table Type
[COLUMN]
9		// Table column number include fixed column
[ROW]
7		// Table Row include fixed row
[FIXEDROW]
1		// Fixed row
[FIXEDCOLUMN]
2		// Fixed column
[WIDTH]
100		// Table width percentage (%)
[DATA]		// All data should be separated with comma
Pass,Mill No.,HRatio (%),Height (mm),dH (mm),EtaH (%),dWh (mm),Temperature (!I),Angle (!F),
1,4Mill 1,0.100,208.32,20.78,0.0887,4.61,1240.69,10.07,
2,4Mill 1,0.161,175.69,33.45,0.1567,8.02,1235.14,12.78,
3,4Mill 1,0.177,139.82,36.78,0.2043,9.06,1227.70,13.40,
4,4Mill 2,0.385,96.17,44.77,0.3125,11.63,1204.26,15.38,
5,4Mill 2,0.335,58.14,38.95,0.3955,10.41,1194.53,14.34,
6,4Mill 2,0.280,26.42,32.56,0.5469,11.06,1150.69,13.11,
[END] 

Style File Format

Htmlfile.dat file has my favorite HTML file and HTML table style. I'm sorry about Style file is not in easy format but  It isn't difficult so much.

HtmlFile.dat has 1 HTML body and several Table body. You can change all HTML code as you like but leave strings in a ^text^ format unchanged!! A string within ^ bracket is keyword used by CHtmlFile or CHtmlTable.


Keyword used at Htmlfile.dat

Keyword Comment
^BODY^ Used By CHtmlFile, All Table or Bitmap data will be inserted at here
^TABLETITLE^ Table title defined at data table format or bitmap button title will be inserted here
^HEIGHT^ Table Height
^WIDTH^ Table Width
^DATA^ Data
Cell

Format

^BOTTOM_SOLID^ CHtmlTable check cell boundary and deicde whether to draw cell outline or not
^LEFT_SOLID^
^RIGHT_SOLID^
^TOP_SOLID^
^ADDRESS^ Button address will be inserted here

Anybody feel free contact with me and enhance this code. If you enhance this code, don't hesitate to report at codeguru. Good Luck :-)

Downloads

Download demo project - 53 Kb
Download source - 7 Kb


Comments

  • Code

    Posted by Legacy on 11/13/2002 12:00am

    Originally posted by: Arsi

    Very nicely done program, ^ ^

    Reply
  • Showing .htm files to HTML?

    Posted by Legacy on 09/16/2002 12:00am

    Originally posted by: Tan

    Very useful and nice work.

    One question: Could you show a .html file directly in your demo? Similar to .igf file, not from formatted .txt files.

    Anybody has Any idea?

    Reply
  • Nice to Meet you!

    Posted by Legacy on 10/15/2001 12:00am

    Originally posted by: Lee JongSeon

    반갑군요!

    한국분들이 올린것은 거의 보기 힘들었는데...
    많은 도움이 될것입니다.

    Reply
  • HTML print cut off the contents

    Posted by Legacy on 08/16/2001 12:00am

    Originally posted by: Dinesh Chandra Maithani

    If I increase columns upto 20 or more in any of the tables, I am not able to print the full contents of the table, rather gets the cut off table

    Any solution ?

    Reply
  • Good Korea!!!

    Posted by Legacy on 09/14/2000 12:00am

    Originally posted by: hyuri98

    Good! Good!

    Reply
  • To make Html Table without text file

    Posted by Legacy on 12/21/1999 12:00am

    Originally posted by: Kim Pil Ho

    I've received 1 question about above title.
    
    

    This is the full comment about that question.

    ==question==
    title: regrading html table generator


    hi and first thanks for sharing.

    my problem is that the data is being duplicated one for the dat file and one for html file it self
    is there any way i can add a col and rows programaticly

    i.e
    phtmltable->addrow(..)
    phtmltable->addcol(..)

    any way thanks in advance


    ==reply==
    Hi~
    I've already provide the way you want.
    It looks like that I made fault at writing my article that can perplex the user.
    Reading text file in case of table is just additional way to help user who likes text result file.

    Try this sample code at HtmlMaker sample project.
    Just insert code in the member function

    void CHtmlMakerView::OnGenerate()

    After :
    m_HtmlFile.CreateHtmlFile(_T("result\\result.htm"), _T("Simulation Result"));

    Before :
    m_HtmlFile.WriteHtmlFile();

    Source Code :
    pTable = new CHtmlTable();
    pTable->m_iTableType = HTML_TABLE_GRAY;
    pTable->m_iColumn = 2;
    pTable->m_iRow = 2;
    pTable->m_iFixedRow = 1;
    pTable->m_iFixedColumn = 1;
    pTable->m_iWidth = 100;
    pTable->m_sTitle = _T("Test of Direct Write Table");

    pTable->m_sHeaderArray.Add(_T("T1"));
    pTable->m_sHeaderArray.Add(_T("T2"));
    pTable->m_sDataArray.Add(_T("120.0"));
    pTable->m_sDataArray.Add(_T("130.0"));
    pTable->MakeHtmlTable();
    m_HtmlFile.AddTable(pTable);
    delete pTable;

    I'm sure you can modify above code as addrow() or addcol()

    Good luck :-)


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • Live Event Date: December 18, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this upcoming webcast …

Most Popular Programming Stories

More for Developers

RSS Feeds