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()


技术分享




附件列表

     

    郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。