Advertisement
Guest User

Beginning Python #24 - PyRTF Tables

a guest
May 9th, 2011
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from PyRTF import *
  4.  
  5. def TableExample():
  6.     doc = Document()
  7.     ss = doc.StyleSheet
  8.     section = Section()
  9.     doc.Sections.append(section)
  10.        
  11.     thin_edge  = BorderPS(width=20, style=BorderPS.SINGLE)
  12.     thick_edge = BorderPS(width=80, style=BorderPS.SINGLE)
  13.     thin_frame  = FramePS(thin_edge,  thin_edge,  thin_edge,  thin_edge)
  14.     thick_frame = FramePS(thick_edge, thick_edge, thick_edge, thick_edge)
  15.     mixed_frame = FramePS(thin_edge,  thick_edge, thin_edge,  thick_edge)
  16.  
  17.     table = Table(TabPS.DEFAULT_WIDTH * 3, TabPS.DEFAULT_WIDTH * 3, TabPS.DEFAULT_WIDTH * 3)
  18.     c1 = Cell(Paragraph('R1C1'), thin_frame)
  19.     c2 = Cell(Paragraph('R1C2'))
  20.     c3 = Cell(Paragraph('R1C3'), thick_frame)
  21.     table.AddRow(c1, c2, c3)
  22.  
  23.     c1 = Cell(Paragraph('R2C1'))
  24.     c2 = Cell(Paragraph('R2C2'))
  25.     c3 = Cell(Paragraph('R2C3'))
  26.     table.AddRow(c1, c2, c3)
  27.  
  28.     c1 = Cell(Paragraph('R3C1'), mixed_frame)
  29.     c2 = Cell(Paragraph('R3C2'))
  30.     c3 = Cell(Paragraph('R3C3'), mixed_frame)
  31.     table.AddRow(c1, c2, c3)
  32.  
  33.     section.append(table)
  34.  
  35.  
  36.     return doc
  37.  
  38. def OpenFile(name):
  39.     return file('%s.rtf' % name, 'w')
  40.  
  41. if __name__ == '__main__':
  42.     DR = Renderer()
  43.     doc = TableExample()
  44.     DR.Write(doc, OpenFile('rtftable-b'))
  45.     print "Finished"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement