python操作excel(xlwings)(自用)
1. 基础
2. 写入excel基本操作
"""
xlwing第一次
运行前提前打开excel,否则会报错
"""
import xlwings as xw
wb=xw.books.add()
sht=wb.sheets("sheet1")
sht.range("a1").value="饭某某"
wb.save('G:\jupyter notebook\python_excel_xwlings\excel_root\demol1.xlsx')
wb.close()
3. 写入excel的常规操作
sht.range("c4").value=[1,2,3,4]
sht.range("c4:f4").value=[5,2,3,4]
sht.range("b7").options(transpose=True).value=[5,2,3,4]
sht.range("c12").value = [[1,2],[3,4]]
4. 读excel的基本操作
wb = xw.books.open('G:\jupyter notebook\python_excel_xwlings\excel_root\demol2.xlsm')
sht = wb.sheets["sheet1"]
print(sht.range("c12").value)