0
Python:如何從oracle讀取數據,然後寫入Excel,Excel的部分列只能讀取?Python:如何從oracle讀取數據,然後寫入Excel
Python:如何從oracle讀取數據,然後寫入Excel,Excel的部分列只能讀取?Python:如何從oracle讀取數據,然後寫入Excel
安裝database driver用於連接db和pandas以簡化excel寫入和數據操作。
$ pip install cx_Oracle pandas
做這樣的事情:
import cx_Oracle
con = cx_Oracle.connect('user/[email protected]')
data = pd.read_sql('SELECT * FROM mytable', con)
con.close()
data.head() # take a peek at data
data.to_excel('my_oracle_table.xlsx')
this answer is come from site:
http://stackoverflow.com/questions/8526296/python-xlwt-making-a-column-readonly-cell-protect
from xlwt import Workbook, Worksheet, easyxf
# ...
# Protect worksheet - all cells will be read-only by default
my_worksheet.protect = True # defaults to False
my_worksheet.password = "something_difficult_to_guess"
# Create cell styles for both read-only and editable cells
editable = easyxf("protection: cell_locked false;")
read_only = easyxf("") # "cell_locked true" is default
# Apply your new styles when writing cells
my_worksheet.write(0, 0, "Can't touch this!", read_only)
my_worksheet.write(2, 2, "Erase me :)", editable)
我得到了它,你已經表現出什麼,但我不知道如何設置列的Excel部分可以只讀(我使用python2和xlrd,xlwt) –
你想讓一些只讀的列或整個工作表? –
我想讓一些列只讀,但不是整個工作表。 –