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