上代碼:
import pandas as pd import SqlHelper.ORACLE as ORA if __name__ == '__main__': #連接數據庫 ms = ORA.ORACLE(host="localhost:1521",db="orcl",user="example",pwd="example") ########################################################## 方式一:先讀取為二維list,再轉dataframe,最后保存為Excel reslist = ms.ExecQuery("select * from version ") # list轉dataframe df1 = pd.DataFrame(reslist, columns=['ID', 'VERSION', 'MESSAGE']) df1.to_excel("E:\\MyPrj\\Python\\Files\\Excel1.xlsx", index=False) ########################################################## 方式二:直接讀取為dataframe,然后保存為Excel df2 = ms.ExecQueryToDataFrame("select * from version ") df2.to_excel("E:\\MyPrj\\Python\\Files\\Excel2.xlsx", index=False)
如果對您有幫助,請贊助根棒棒糖~