1 (edited by CDB 2020-11-15 12:45:39)

Topic: Problem converting tablegrid to HTML for Emailing

I'm trying to take the contents of a tablegrid and  convert it to HTML for the body of an email.


My problem is that I only seem to get one complete row and the first two columns into the second row into HTML.
I'm practising with a tablegrid that has four columns and five rows.


The code I'm using is below

   sList:TstringList;
begin
         sList:=TStringList.Create;
         sList.Add('<html>');
         sList.Add('<head>');
         sList.add('<style>');
         sList.Add('table, th, td {');
         sList.Add(' border: 1px solid #dddddd; text-align: left; padding: 8px');
         sList.Add('}');
         sList.Add('</style>');
         sList.add('</head>');
         sList.Add('<body>');
         sList.Add('<table>');
         sList.Add('<tr><th>BSuite#:</th>'+ '<th>Part Number</th>' + '<th>Description'+ '</th>'+'<th>Qty'+'</th></tr>');

         for indx := 0 to frmEmail.tgEmailList.RowCount-1 do
         begin
            sList.Add('<tr><td>'+frmEmail.tgEmailList.Cells[0,indx] + '</td>' + '<td>' +frmEmail.tgEmailList.Cells[1,indx] +'</td>'+'<td>'+frmEmail.tgEmailList.Cells[2,indx]+'</td>'+'<td>'+frmEmail.tgEmailList.Cells[3,indx]+'</td></tr>');
         end;
         sList.Add('</table>');
         sList.Add('</body>');
         sList.Add('</html>');

        openURL('mailto:'+frmEmail.cmbEmailAddress.Text+'?subject='+frmEmail.cmbSupplierList.Text+'Order'+'&Body='+sList.text);
sList.Free;

I'm just not seeing why I'm only getting 1 and a bit rows.  This will be going into Outlook, but  my personal email client (emClient) has to have the HTML input manually. My suspicion is that I'm missing an HTML tag, but I can't see where!


Any thoughts gratefully received.

On a clear disk you can seek forever

Re: Problem converting tablegrid to HTML for Emailing

CDB,
I just tested your code and placed the result into an html editor and it displays correctly (all rows and all columns). Do you have any special characters in your columns that may be throwing it off?

Re: Problem converting tablegrid to HTML for Emailing

Thanks EHWagner,


The code isn't working in Outlook when I tested it today, I just get the HTML as text. However, I discovered a parameter that I will try tomorrow which might just change that.

I read at Microsoft that the oleobject for Outlook includes object.HTMLBody  and I was using object.body.


So, tomorrow when I have access to Outlook, I'll give it a try and see what happens.

On a clear disk you can seek forever