def __init__(self, title, filename=None, description_fields=None): self.title = title self.filename = filename self.description_fields = description_fields or [] # setup document styles self.doc = Elements.Document() self.doc.SetTitle(self.title) self.ss = self.doc.StyleSheet NormalText = self.ss.ParagraphStyles.Normal self.metastyle = NormalText.Copy() self.metastyle.TextStyle.textProps.size = 16 self.metastyle.TextStyle.textProps.italic = True self.ps = Styles.ParagraphStyle('Metadata', self.metastyle.TextStyle) self.ss.ParagraphStyles.append(self.ps) # add the document title self.new_section().append(self.new_title(self.title))
def make_rtf(sql_results): doc = Elements.Document() ss = doc.StyleSheet sec = section.Section() doc.Sections.append(sec) p = paragraph.Paragraph(ss.ParagraphStyles.Heading1) p.append('catalog id = 1504') sec.append(p) table = paragraph.Table(PropertySets.TabPropertySet.DEFAULT_WIDTH * 3, PropertySets.TabPropertySet.DEFAULT_WIDTH * 7) # edge = PropertySets.BorderPropertySet( width=20, style=PropertySets.BorderPropertySet.SINGLE) frame = PropertySets.FramePropertySet(edge, edge, edge, edge) for row in sql_results: c1 = paragraph.Cell( paragraph.Paragraph(ss.ParagraphStyles.Normal, str(row[0])), frame) row1 = '' if type(row[1]) is unicode: # row1 = unicode(row[1]).encode('utf8', 'ignore') row1 = rtf_encode(row[1]) # .decode('utf8').encode('latin') # .encode('urf8', 'ignore') # .decdde('utf8', 'ignore') else: row1 = '' print row1 c2 = paragraph.Cell( paragraph.Paragraph(ss.ParagraphStyles.Normal, str(row1), frame)) if row1 != '': table.AddRow(c1, c2) sec.append(table) DR = Renderer.Renderer() DR.Write(doc, open_file('test1'))
def new_section(self): section = Elements.Section() self.doc.Sections.append(section) return section