Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (2)


String Grid to HTML fileFormat this article printer-friendly!Bookmark function is only available for registered users!
StrGridToHTML()
Product:
Delphi 5.x (or higher)
Category:
Files Operation
Skill Level:
Scoring:
Last Update:
05/03/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet HTML "FILE CONVERSION" TSTRINGGRID
Times Scored:
5
Visits:
4042
Uploader: Mike Heydon
Company: EOH
Reference: mheydon@eoh.co.za
 
Question/Problem/Abstract:
Procedure to dump the contents of a TStringGrid to HTML format file.

StrGridToHTML(const FileName : string;
                       StrGrid : TStringGrid;
                       const Heading : string = '';
                       TextColor : TColor = clBlack;
                       TableBgColor : TColor = clAqua);

Arguments:
FileName : String containing Path and Filename of output file.
StrGrid : TStringGrid component to dup to file.
Heading : HTML Table Header Text. (optional default = nullstr)
TextColor : TColor denoting color of HTML table text (default = clblack)
TableBgColor : TColor denoting background color of HTML table (default = clAqua)

Example of Syntax

StrGridToHTML('c:\temp\test.htm',StringGrid1,'Account Code',clBlue,clWhite);


Answer:



I AM HAVING A HARD TIME HERE !!!
THE HTML TAGS IN MY SCRIPT ARE
BEING FORMATTED BY THE DELPHI 3000 DISPLAY

HOW DO I INSERT AS PLAIN TEXT ?

HAVE SPLIT THE HTML TAGS BY CONCATENATION, LOOKS A
BIT STUPID BUT AT LEAST YOU CAN READ IT.


procedure StrGridToHTML(const FileName : string;
                        StrGrid : TStringGrid;
                        const Heading : string = '';
                        TextColor : TColor = clBlack;
                        TableBgColor : TColor = clAqua);
var Txt : TextFile;
    i,ii : integer;
    BgColor,TxColor : string;
begin
  // Convert TColor to HTML Hex Color
  BgColor := IntToHex(GetRValue(TableBgColor),2) +
             IntToHex(GetGValue(TableBgColor),2) +
             IntToHex(GetBValue(TableBgColor),2);

  TxColor := IntToHex(GetRValue(TextColor),2) +
             IntToHex(GetGValue(TextColor),2) +
             IntToHex(GetBValue(TextColor),2);

  // Create output file
  AssignFile(Txt,FileName);
  Rewrite(Txt);

  // HTML Header Info
  WriteLn(Txt,'<' + 'HTML>');
  WriteLn(Txt,'<' + 'HEAD>');
  WriteLn(Txt,'<' + 'TITLE>' + ExtractFileName(FileName) + '<' + '/TITLE>');
  WriteLn(Txt,'<' + '/HEAD>');
  WriteLn(Txt);
  WriteLn(Txt,'<' + 'BODY TEXT=#' + TxColor + ' BGCOLOR=#CCCCCC>');
  WriteLn(Txt,'<' + 'H1>' + Heading + '<' + '/H1>');
  WriteLn(Txt,'<' + 'TABLE WIDTH=100% CELLPADDING=2 CELLSPACING=2 ' +
              'BGCOLOR=#' + BgColor + ' BORDER=1>');

  // Column Descriptions
  WriteLn(Txt,'    <' + 'TR>');
  for i := 0 to StrGrid.ColCount - 1 do
     WriteLn(Txt,'        <' + 'TH>' + StrGrid.Cells[i,0] + '<' + '/TH>');
  WriteLn(Txt,'    <' + '/TR>');

  // Write out the Grid Data
  for i := 1 to StrGrid.RowCount - 1 do begin
    WriteLn(Txt,'    <' + 'TR>');
    for ii := 0 to StrGrid.ColCount - 1 do
        WriteLn(Txt,'    <' + 'TD>' + StrGrid.Cells[ii,i] + '<' + '/TD>');
    WriteLn(Txt,'    <' + '/TR>');
  end;

  // Footer
  WriteLn(Txt,'<' + '/TABLE>');
  WriteLn(Txt,'<' + 'P>');
  WriteLn(Txt,'<' + 'H3>' + IntToStr(StrGrid.ColCount) + ' Rows<' + '/H3>');
  WriteLn(Txt,'<' + '/BODY>');
  WriteLn(Txt,'<' + '/HTML>');

  CloseFile(Txt);
end;






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Very good!
    xavier boisseau (Jul 10 2002 11:14AM)

The code is ready to be integrated in your code, no problem...
Perfect
Respond

having a hard time?
    Eber Irigoyen (May 4 2002 12:14AM)

you can use this PAS 2 HTML Converter

just make sure you save a copy of the formatted code on your hard disk before posting!!!, as Delphi3000 itself makes changes to the formatted code

salu2
EberSys
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
Peganza
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)