Advertisement
webmanix

Automated report

Sep 18th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. import psycopg2
  2. import xlsxwriter
  3.  
  4. wb = xlsxwriter.Workbook("datapump.xlsx")
  5. ws = wb.add_worksheet()
  6.  
  7. conn = psycopg2.connect("dbname=matrizpitstop user=postgres password=postgres host=srvmatriz")
  8. cur = conn.cursor()
  9. cur.execute("SELECT codigo, nome FROM produto LIMIT 500")
  10.  
  11. ws.write(0, 0, "Codigo")
  12. ws.write(0, 1, "Nome")
  13.  
  14. curow = 1
  15.  
  16. for record in cur: 
  17.     for col in range(len(record)):
  18.         ws.write(curow, col, record[col].decode('latin1'))
  19.     curow+=1
  20.    
  21. wb.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement