Mega Code Archive

 
Categories / Delphi / Files
 

String Grid to HTML file

Title: String Grid to HTML file Question: 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,''); WriteLn(Txt,''); WriteLn(Txt,'' + ExtractFileName(FileName) + ''); WriteLn(Txt,''); WriteLn(Txt); WriteLn(Txt,''); WriteLn(Txt,'' + Heading + ''); WriteLn(Txt,' 'BGCOLOR=#' + BgColor + ' BORDER=1'); // Column Descriptions WriteLn(Txt,' '); for i := 0 to StrGrid.ColCount - 1 do WriteLn(Txt,' ' + StrGrid.Cells[i,0] + ''); WriteLn(Txt,' '); // Write out the Grid Data for i := 1 to StrGrid.RowCount - 1 do begin WriteLn(Txt,' '); for ii := 0 to StrGrid.ColCount - 1 do WriteLn(Txt,' ' + StrGrid.Cells[ii,i] + ''); WriteLn(Txt,' '); end; // Footer WriteLn(Txt,''); WriteLn(Txt,''); WriteLn(Txt,'' + IntToStr(StrGrid.ColCount) + ' Rows'); WriteLn(Txt,''); WriteLn(Txt,''); CloseFile(Txt); end;