oracle数据存入EXCEL

  1. #coding:gb18030
  2. import cx_Oracle
  3. import xlsxwriter
  4. import time
  5. import sys
  6. reload(sys)
  7. sys.setdefaultencoding("gb18030")
  8. con = cx_Oracle.connect("user/user123@user")
  9. cursor = con.cursor()
  10. query1 = cursor.execute(""" select OL_NBR,OL_ID,To_char(OL_SO_DATE,'YYYY-MM-DD hh24:mi:ss') ,CO_NBR,MIN_CO_ID,MAX_CO_ID,PROD_ID,PROD_SPEC_ID,PROD_NAME,ORDER_TYPE_NAME,OWNER_ID,OWNER_NAME,AREA_ID,AREA_NAME,STAFF_ID,STAFF_NUMBER,STAFF_NAME,CHANNEL_ID,CHANNEL_NAME,To_char(CO_DATE,'YYYY-MM-DD hh24:mi:ss'),To_char(INSTALL_DATE,'YYYY-MM-DD'),CO_FIRST_YYSJ,LXR,LXDH,LAST_STATE_CD,LAST_STATE_NAME,JRH,BDH,JX_ID,JX_NAME,FGS_ID,FGS_NAME,CPLX,DDLX,BSS_ORDER_FZT,E_BS,ORDER_ID,To_char(DISPL_DATE,'YYYY-MM-DD hh24:mi:ss') ,TZ_GDH,TZ_GD_GW,ZYJ_DZ,GEOGRAPHY_LOC_ID,BZ_DZ,YCYY,RETURN_REMARKS,FFBZ,JFE,CO_GRP_ID,LINE_CO_ID,LINE_JRH,LINE_ORDER_ID,LINE_INTE_ORDER_ID,LINE_TZ_GD_GW,FKID,FKLX,ZHBZ from fzt_dd """ )
  11. #取出数据库字段信息
  12. title = [i[0] for i in query1.description]
  13. workbook = xlsxwriter.Workbook('Expenses01.xlsx', {'constant_memory': True})
  14. worksheet = workbook.add_worksheet()
  15. print time.ctime()
  16. data = cursor.fetchall()
  17. print time.ctime()
  18. worksheet.write_row(0, 0, title)
  19. #按列写入xlsx文件
  20. for row, row_date in enumerate(data):
  21. worksheet.write_row(row+1, 0, row_date)
  22. print time.ctime()
  23. cursor.close()
  24. con.close()
  25. workbook.close()







附件列表

     

    posted @ 2015-02-06 16:51  阳光树林  阅读(670)  评论(0编辑  收藏  举报