Outlook can't parser multiple tables from html with pywin32 - outlook

I try to convert the html file to msg file, it stopped convert when meet third table tag in html.
I searched this question but didn't get any result -- it seems like only myself meet this problem.
So this is the example html code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>This Email is using for understand outlook mail synthesis</h1>
<h2>0001</h2>
<table>
<tr>
<td>This is image001.jpg</td>
</tr>
<tr>
<td>
// stop parsing after parse this table
<table>
<tr>
<td>
<img src="cid:image001.jpg" alt="">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>This is image002.jpg</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
<img src="cid:image002.jpg" alt="">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>This is image003.jpg</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
<img src="cid:image003.jpg" alt="">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>This is image004.jpg</td>
</tr>
<tr>
<table>
<tr>
<td>
<img src="cid:image004.png" alt="">
</td>
</tr>
</table>
</tr>
</table>
<h1>No!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</h1>
</body>
</html>
And this is my python code:
from win32com import client as win32
import os
outlook = win32.Dispatch("outlook.application")
mail = outlook.CreateItem(0)
mail.Subject = "This is a subject"
with open(".\\mix.html", "r", encoding="utf-8") as f:
html = f.read()
mail.HtmlBody = html
current_path = os.getcwd()
at = mail.Attachments.Add(current_path + "\\image001.jpg")
at.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "image001.jpg")
at = mail.Attachments.Add(current_path + "\\image002.jpg")
at.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "image002.jpg")
at = mail.Attachments.Add(current_path + "\\image003.jpg")
at.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "image003.jpg")
at = mail.Attachments.Add(current_path + "\\image004.png")
at.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "image004.png")
mail.SaveAs(current_path + "\\rst.msg")
This is what I see when I open the "rst.msg" file:
stop parsing after parse the table
I deleted the table in second tr tag and run the python script, this is what I get:
stop parsing again after parse the table
This is the html code I deleted the table in second tr tag:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>This Email is using for understand outlook mail synthesis</h1>
<h2>0001</h2>
<table>
<tr>
<td>This is image001.jpg</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>This is image002.jpg</td>
</tr>
<tr>
<td>
// stop parsing after parse this table
<table>
<tr>
<td>
<img src="cid:image002.jpg" alt="">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>This is image003.jpg</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
<img src="cid:image003.jpg" alt="">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>This is image004.jpg</td>
</tr>
<tr>
<table>
<tr>
<td>
<img src="cid:image004.png" alt="">
</td>
</tr>
</table>
</tr>
</table>
<h1>No!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</h1>
</body>
</html>
Hope you can help me! Thank you very much!

This question was solved by upgrading outlook version. In the new version, outlook can generate email as expected, but if you add some picture to the email used for html generating and save this email, then pictures are added to the email as appendix. If you send the email after generate it and before save it, the receiver can't see those appendix. That's what you might want.
Upgrading the outlook version is a way to solve this question.

Related

Laravel email verification sent with HTML tags

Im trying to send an email but when the email is received it with its html tags
<tr> <td class="header"> TikTak </td> </tr> <tr> <td> <table
class="footer" align="center" width="570" cellpadding="0" cellspacing="0"> <tr> <td class="content-
cell" align="center"> <p>é 2019 êÃÂçÃÂàíÃÂÃÂÃÂ
èñçàRabter ÃÂíÃÂÃÂø ÃÂàèçôï</p> </td> </tr>
</table> </td> </tr>
I do have \Blade::setEchoFormat('e(utf8_encode(%s))'); in my Appserviceprovider and also changed {{}} in markdown folder to {!! !!} and also in the html folder but unfortunately it did NOT fix it
It was working properly and suddently its output turned into this mess
Thanks for anyhelp
You need to put <meta charset="utf-8"> tage in you email template.

Get a cell that is in a table before the current table

See html below. Have a series of tables that include rows with a name attribute name="laneStop". I can select those rows like this in the Chrome dev console
$x("/html[1]/body[1]//TR[#name='laneStop']")
However, I also need to get the 2nd cell of the 2nd row of the 1st table ABOVE these rows, eg. the value
abc_123_florida-45
Here is the html. Whats a way to refer to this value above - knowing that Im getting the "laneStop" rows first
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<table border="1">
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td>Date</td>
<td>11/15/2019</td>
</tr>
<tr>
<td>shipment number</td>
<td>abc_123_florida-45</td>
</tr>
<tr>
<td>Departure time:</td>
<td>0430</td>
</tr>
</tbody>
</table>
</td>
<td>
<table>
<tbody>
<tr>
<td>Time arrival</td>
<td>1715</td>
</tr>
<tr>
<td>customer</td>
<td>bob smith</td>
</tr>
<tr>
<td>box type</td>
<td>square</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table border="1">
<tbody>
<tr>
<td>
<table>
<tbody>
<tr name="laneStop">
<td>box1</td>
<td>23.45</td>
<td>lane1</td>
<td>south</td>
</tr>
<tr name="laneStop">
<td>box2</td>
<td>17.14</td>
<td>lane1</td>
<td>south</td>
</tr>
<tr name="laneStop">
<td>box3</td>
<td>17.18</td>
<td>lane1</td>
<td>north</td>
</tr>
<tr name="laneStop">
<td>box2</td>
<td>199.14</td>
<td>lane1</td>
<td>west</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Try the following xpath.
//td[text()='shipment number']/following::td[1]
Demo:
If you want to travel from your current node (i.e., the "laneStop" rows), one way to do that is to use this xpath expression:
./preceding-sibling::*/ancestor::*[6]/preceding-sibling::table[1]//tr[1]/td[1]/table[1]//td[1]//tr[2]/td[2]
I'm curious to see if it works for you.

How to get the table immediately previous to current table row

Say I get a list of rows like this
var table_stop_rows = (from r in doc.Descendants("TR").Cast<HtmlNode>()
where r.Attributes["name"]?.Value == "laneStop"
select r).ToList();
Now, for each of those "laneStop" rows, I want to refer back to the smaller table containing the "shipment_number" field and read its corresponding node value, eg "abc_123_florida-4". However, I cant simply get a list of all rows where there is a shipment_number, each one has to be in a table that precedes the "laneStop" row in the row collection I'm getting.
I suppose my question then is - if I have a collection of rows, can I then use an xpath statement relative to each row to get back to this shipment_number field in the table preceding?
Here is the html doc, note there would be dozens of these "table pairs". Since I can't control the structure of these files, I need a way to extract the data from the existing structure
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<table border="1">
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td>Date</td>
<td>11/15/2019</td>
</tr>
<tr>
<td>shipment number</td>
<td>abc_123_florida-45</td>
</tr>
<tr>
<td>Departure time:</td>
<td>0430</td>
</tr>
</tbody>
</table>
</td>
<td>
<table>
<tbody>
<tr>
<td>Time arrival</td>
<td>1715</td>
</tr>
<tr>
<td>customer</td>
<td>bob smith</td>
</tr>
<tr>
<td>box type</td>
<td>square</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table border="1">
<tbody>
<tr>
<td>
<table>
<tbody>
<tr name="laneStop">
<td>box1</td>
<td>23.45</td>
<td>lane1</td>
<td>south</td>
</tr>
<tr name="laneStop">
<td>box2</td>
<td>17.14</td>
<td>lane1</td>
<td>south</td>
</tr>
<tr name="laneStop">
<td>box3</td>
<td>17.18</td>
<td>lane1</td>
<td>north</td>
</tr>
<tr name="laneStop">
<td>box2</td>
<td>199.14</td>
<td>lane1</td>
<td>west</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Try this xpath expression:
(//tr[#name="laneStop"]/ancestor::table/preceding-sibling::table//tr[2]/td[2])[1]

WebView stop scrolling after applying CSS Xamarin.forms

After Desalinization of the Json I got HTML content (). I append Html,head and body tag to this web content in order to apply CSS.
But problem is When I apply CSS and Js, web view is stop scrolling. and my table data is stuck in web view.
Same Html page is not scroll in my simple web browser but it is perfectly work in windows mobile application. It is not working in xamarin forms.
Final HTML I have generate from JSON data. only content comes from json.
<html style="background: #ffffff">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1 , maximum-scale=1, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href='http://14.141.36.212/maharastracmo/sites/all/themes/maharastracmonew/css/style.css' rel='stylesheet' type='text/css'/>
<script src="http://192.168.5.123/maharastracmolatest/latest/misc/jquery.js?v=1.4.4"></script>
<script src="http://192.168.5.123/maharastracmolatest/latest/sites/all/themes/maharastracmonew/js/functions.js?obsm2a"></script>
<script src="http://192.168.5.123/maharastracmolatest/latest/sites/all/themes/maharastracmonew/js/general.js?obsm2a"></script>
</head>
<body>
<div class="bgColorWhite">
<table class="tableData formarTable responsiveTable">
<tbody>
<tr>
<th>Name of CM</th>
<th colspan="2">Duration</th>
<th>Political Party Belongs to</th>
<th>No. of Days Served</th>
</tr>
<tr>
<td>Vacant(President's rule)</td>
<td>09/28/14</td>
<td>10/31/14</td>
<td>N/A</td>
<td>32 days</td>
</tr>
<tr>
<td>Prithviraj Chavan</td>
<td>11/11/10</td>
<td>09/26/14</td>
<td rowspan="6">Indian National Congress</td>
<td>1415 Days</td>
</tr>
<tr>
<td rowspan="2">Ashok Chavan</td>
<td>11/07/09</td>
<td>11/09/10</td>
<td>368 Days [Total 679 Days]</td>
</tr>
<tr>
<td>12/08/08</td>
<td>10/15/09</td>
<td>311 Days</td>
</tr>
<tr>
<td>Vilasrao Deshmukh </td>
<td>11/01/04</td>
<td>12/04/08</td>
<td>1494 Days [Total 2681 Days]</td>
</tr>
<tr>
<td>Sushilkumar Shinde</td>
<td>01/18/03</td>
<td>10/30/04</td>
<td>651 Days</td>
</tr>
<tr>
<td>Vilasrao Deshmukh</td>
<td>10/18/99</td>
<td>01/16/03</td>
<td>1187 Days</td>
</tr>
<tr>
<td>Narayan Rane</td>
<td>02/01/99</td>
<td>10/17/99</td>
<td rowspan="2">Shiv Sena</td>
<td>259 Days</td>
</tr>
<tr>
<td>Manohar Joshi</td>
<td>03/14/95</td>
<td>01/31/99</td>
<td>1419 Days</td>
</tr>
<tr>
<td>Sharad Pawar </td>
<td>03/06/93</td>
<td>03/14/95</td>
<td rowspan="8">Indian National Congress</td>
<td>739 Days [Total 2413 Days]</td>
</tr>
<tr>
<td>Sudhakarrao Naik</td>
<td>06/25/91</td>
<td>02/22/93</td>
<td>608 Days</td>
</tr>
<tr>
<td>Sharad Pawar </td>
<td>06/26/88</td>
<td>06/25/91</td>
<td>1094 Days</td>
</tr>
<tr>
<td>Shankarrao Chavan </td>
<td>03/12/86</td>
<td>06/26/88</td>
<td>837 Days [Total 1623 Days]</td>
</tr>
<tr>
<td>Shivajirao Patil Nilangekar</td>
<td>06/03/85</td>
<td>03/06/86</td>
<td>277 Days</td>
</tr>
<tr>
<td>Vasantdada Patil </td>
<td>02/02/83</td>
<td>06/01/85</td>
<td>851 Days [Total 1304 Days]</td>
</tr>
<tr>
<td>Babasaheb Bhosale</td>
<td>01/21/82</td>
<td>02/01/83</td>
<td>377 Days</td>
</tr>
<tr>
<td>Abdul Rehman Antulay</td>
<td>06/09/80</td>
<td>01/12/82</td>
<td>583 Days</td>
</tr>
<tr>
<td>Vacant (President's rule)</td>
<td>02/17/80</td>
<td>06/08/80</td>
<td>N/A</td>
<td>113 Days</td>
</tr>
<tr>
<td>Sharad Pawar</td>
<td>07/18/78</td>
<td>02/17/80</td>
<td>Progressive Democratic Front</td>
<td>580 Days</td>
</tr>
<tr>
<td rowspan="2">Vasantdada Patil</td>
<td>03/07/78</td>
<td>07/18/78</td>
<td rowspan="9">Indian National Congress</td>
<td>134 Days</td>
</tr>
<tr>
<td height="38">04/17/77</td>
<td>03/02/78</td>
<td>319 Days</td>
</tr>
<tr>
<td>Shankarrao Chavan</td>
<td>02/21/75</td>
<td>04/16/77</td>
<td>786 Days</td>
</tr>
<tr>
<td rowspan="3">Vasantrao Naik</td>
<td>03/13/72</td>
<td>02/20/75</td>
<td>709 Days [Total 4097 Days]</td>
</tr>
<tr>
<td>03/01/67</td>
<td>03/13/72</td>
<td>1840 Days</td>
</tr>
<tr>
<td>12/05/63</td>
<td>03/01/67</td>
<td>1548 Days</td>
</tr>
<tr>
<td>P. K. Sawant</td>
<td>11/25/63</td>
<td>12/04/63</td>
<td>10 Days</td>
</tr>
<tr>
<td>Marotrao Kannamwar</td>
<td sdnum="1033;0;MM/DD/YY" sdval="22970">11/20/62</td>
<td sdnum="1033;0;MM/DD/YY" sdval="23339">11/24/63</td>
<td>370 Days</td>
</tr>
<tr>
<td>Yashwantrao Chavan</td>
<td>05/01/60</td>
<td>11/19/62</td>
<td>933 Days</td>
</tr>
</tbody>
</table>
</div></body></html>
I can not figure out what is actual problem and also not understand It's problem of my html or Xamarin.forms or missing property of webView.
Code is :
private async void CallWebService()
{
try
{
List<KeyValuePair<string, string>> values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, string>("page_id", "15"));
var response = await GeneralClass.GetResponse<RootObject>("http://14.141.36.212/maharastracmo/api/getpagecontent", values);
string webcontent = response.page_content;
var HTMLString = CreateHTMLForFormerCMs(webcontent);
var html = new HtmlWebViewSource
{
Html = HTMLString
};
web.Source = html;
}
catch (WebException ex)
{
await DisplayAlert("Something goes wrong...", "Detail:" + ex, "Ok");
}
}
private string CreateHTMLForFormerCMs(string webcontent)
{
var css = "<link href='http://14.141.36.212/maharastracmo/sites/all/themes/maharastracmonew/css/style.css' rel='stylesheet' type='text/css'/>"
+ "<script src=\"http://192.168.5.123/maharastracmolatest/latest/misc/jquery.js?v=1.4.4\"></script>"
+ "<script src=\"http://192.168.5.123/maharastracmolatest/latest/sites/all/themes/maharastracmonew/js/functions.js?obsm2a\"></script>"
+ "<script src=\"http://192.168.5.123/maharastracmolatest/latest/sites/all/themes/maharastracmonew/js/general.js?obsm2a\"></script>";
var htmlConcat = string.Format("<html style=\"background: #ffffff\"><head> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1 , maximum-scale=1, user-scalable=no\" /><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />{1}</head>" +
"<body>"
+
"<div class=\"bgColorWhite\"><section class=\"content contentarea\">{0}</section></div></body></html>", webcontent, css);
return htmlConcat;
}

pandoc: convert HTML table to DOCX

I have a very simplistic HTML document with a table:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Analysis</title>
</head>
<body>
<TABLE border=1>
<TR> <TD> 18.365 </TD> <TD> 1 </TD> </TR>
<TR> <TD> 23.465 </TD> <TD> 1 </TD> </TR>
<TR> <TD> 26.020 </TD> <TD> 1 </TD> </TR>
<TR> <TD> 14.371 </TD> <TD> 1 </TD> </TR>
<TR> <TD> 17.258 </TD> <TD> 1 </TD> </TR>
</TABLE>
</body>
</html>
and I would like to create a DOCX file from it using pandoc. In the result, however, the table is completely messed up. Can anyone please help me with a working example? It is the last step in a complex workflow I have and I assume that a table should be possible.
Pandoc version:1.12.4.2
It's a regression that has already been fixed in the development version
(https://github.com/jgm/pandoc/issues/1341). You can install the development
version from source or revert to a package for 1.12.3.3. This will be fixed in the next pandoc release.

Resources