菜鸟选手,第一次发,做个学习记录
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import xlwings as xw
# 方法1
excel1 = xw.App(visible=True, add_book= True)
# visible :表示表格可见
# add_book:表示建立新的工作簿(表格)
# 方法2
excel2 = xw.Book()
# 读取文档
# 方法3
excel3 = xw.Book(r'E:\文档\new_material\原件registration sheet.xls')
# "E:\文档\new_material\原件registration sheet.xls"
# 很常见的错误就是“”,因为直接复制地址会带有““
关于增加sheet
sht1 = excel2.sheets.add()
sht2 = excel2.sheets.add()
sht3 = excel2.sheets["sheet1"].copy()
# sht = excel2.sheets.add(after = 1) :在第一个sheet后面再加一个sheet
# after= 表格从1开始计数
# s = excel2.sheets.add(after = excel2.sheets.count):在最后面的sheet新建一个sheet
# sht =excel2.sheets[0].add(): 方框内为索引
# 是sheets不是sheet,sheet添加无效
# sht3 = excel2.sheets["sheet1"].copy():删除
循环打印
print('the name of the sheet is %s' % sht1.name)
# print(f 'the name of the sheet is {sht.name}')
for circle in excel2.sheets:
print(circle.name)
'''
另一种方式
for i in range(0,2):
print(excel2.sheets[i].name)
'''
circle是以sheet的形式循环,所以可以 用 .name访问