Python excel oracle read/write, pythonoracle

Source: Internet
Author: User

Python excel oracle read/write, pythonoracle

There is an excel in the job, and one column is a group of numbers. A number indicates a commodity code. There are three types of product statuses: 1, 2, 3. You need to connect to the oracle database in the background, query the product status, and then filter the Product Code of 1 or 2 from the excel table. Save it in another excel file.

The entire code is:

# Coding: UTF-8
Import xlrd
Import xlwt

Import cx_Oracle
Db = cx_Oracle.connect ('username', 'Password', 'IP: 1521/service name ')

Workbook = xlwt. Workbook (encoding = 'ascii ')
Worksheet = workbook. add_sheet ('My Worksheet ')

Data = xlrd.open_workbook('1.xls ')
Table = data. sheets () [0]
Nrows = table. nrows

For I in range (nrows ):
Rowi = unicode (table. row_values (I) [0])
SQL = "select * from tskuplu where pluCode = '" + rowi + "' And IsActive = '1' and YwStatus in ('1', '2 ')"
Cr = db. cursor ()
Cr.exe cute (SQL)
Rs = cr. fetchall ()
If rs:
Print rs [0] [1], type (rs [0] [1])
Worksheet. write (I, 0, label = rs [0] [1])
Workbook.save('111.xls ')

Cr. close ()

Db. close ()

References:

Https://www.cnblogs.com/lhj588/archive/2012/01/06/2314181.html

Http://python.jobbole.com/81244/

Https://www.cnblogs.com/ylqmf/archive/2012/04/16/2451841.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.