close

因我安裝的是Anacoda3,所以基本上已經預先安裝好xlwings這個套件程式庫。

接下來只需要import程式庫來使用。

xlwings使用文件:http://docs.xlwings.org/en/stable/index.html

xlwings quickstart:http://docs.xlwings.org/en/stable/quickstart.html

xlwings 呼叫macro:http://docs.xlwings.org/en/stable/api.html#xlwings.App.macro

 

底下是我使用到的程式碼:

import xlwings as xw


def updatetxo():
    #wb = xw.Book()  # this will create a new workbook
    #wb = xw.Book('FileName.xlsx')  # connect to an existing file in the current working directory
    wb = xw.Book(r'C://Users//********//Google 雲端硬碟//1234.xlsm')  # on Windows: use raw strings to escape backslashes
    wb = xw.books.active
    

    wb.sheets[1].select()  #select sheet[1] to activate
    StockchartUpdate = wb.macro('StockchartUpdate')
    findrow = wb.macro('findrow')
    StockchartUpdate()
    wb.sheets['PC Ratio&十大'].select() 
    PCRatioChartUpdate = wb.macro('PCRatioChartUpdate')
    PCRatioChartUpdate()
    wb.sheets[1].select()
    findrow()

try:
    updatetxo()
   
except Exception as e:
    print(str(e))

 

 

 

 
 
arrow
arrow
    全站熱搜

    LOGa 發表在 痞客邦 留言(0) 人氣()