2018年4月1日 星期日

把 IPython notebook貼上Blogger文章上分享

In [1]:
import win32com.client
import time

xlApp = win32com.client.Dispatch("Excel.Application")
xlApp.Visible=1

workBook = xlApp.Workbooks.Open(r"C:\Users\kenne\Desktop\datelist.xlsx")
print(str(workBook.ActiveSheet.Cells(1,1)))
now = time.time()
workBook.ActiveSheet.Cells(1, 2).Value = now
#SaveChanges = 1 : Save flle
# SaveChanges = 0 : Nothing Saved
workBook.Close(SaveChanges=1)
xlApp.Quit()
參考此篇(How to quickly turn an IPython notebook into a blog post)",將 .ipynb 轉成 HTML code
!ipython nbconvert --to html --template basic filename.ipynb
接下來就把目錄底下的 filename.html 檔案內的HTML原碼貼上 blogger.com ,然後記得在HTML原碼前面加上底下的CSS碼,就可以囉~
<style type="text/css">
.highlight{background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .1em;padding:0em .5em;border-radius: 4px;}
.k{color: #338822; font-weight: bold;}
.kn{color: #338822; font-weight: bold;}
.mi{color: #000000;}
.o{color: #000000;}
.ow{color: #BA22FF;  font-weight: bold;}
.nb{color: #338822;}
.n{color: #000000;}
.s{color: #cc2222;}
.se{color: #cc2222; font-weight: bold;}
.si{color: #C06688; font-weight: bold;}
.nn{color: #4D00FF; font-weight: bold;}
</style>

同場加映補充資料:HTML Encoder

沒有留言: