Ejemplo n.º 1
0
 def write(self):
     if not self.filename or self.filename == '-':
         report = sys.stdout
     else:
         report = open(self.filename, "w")
     renderer = Renderer.Renderer()
     renderer.Write(self.doc, report)
Ejemplo n.º 2
0
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'))