String Grid to HTML file (Views: 711)
Problem/Question/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: 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, ''); WriteLn(Txt, ''); WriteLn(Txt, ' WriteLn(Txt, ''); WriteLn(Txt); WriteLn(Txt, ''); WriteLn(Txt, ' ' + Heading + '');WriteLn(Txt, '
|