Advertisement
Guest User

Untitled

a guest
Jun 14th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. word.Visible = True
  2.  
  3. def HtmlToWord(range, soup):
  4.     ''' Take some simple HTML and format it using COM calls '''
  5.     text = []
  6.     for tag in soup:
  7.         raw_input("Step")
  8.         if isinstance(tag, BeautifulSoup.NavigableString):
  9.             range.Text+=str(tag)
  10.         else:
  11.             if tag.name == "div":
  12.                 HtmlToWord(range, tag.contents)
  13.             elif tag.name == "br":
  14.                 #range.Text+=chr(11)
  15.                 range.InsertParagraphAfter()
  16.                 print range.Bold
  17.             elif tag.name == "strong":
  18.                 # Make a new range
  19.                 n_range = doc.Range(Start=range.End, End=range.End)
  20.                 n_range.Text = tag.contents[0]
  21.                 n_range.Bold = True
  22.                 range = doc.Range(Start=n_range.End, End=n_range.End)
  23.                 range.Bold = False
  24.             else:
  25.                 HtmlToWord(range, tag.contents)
  26.  
  27. #print BeautifulSoup.BeautifulSoup(report.scope).prettify()
  28. HtmlToWord(doc.Bookmarks("scope").Range, BeautifulSoup.BeautifulSoup(report.scope))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement