Python Excel 讀寫操作 #2 sheet 載入
簡單的屬性和方法如下:
新建工作簿對象:
from openpyxl import load_workbook
from openpyxl.styles import colors, Font, Fill, NamedStyle
from openpyxl.styles import PatternFill, Border, Side, Alignment
# 載入文件
wb = load_workbook('./5a.xlsx')
print('輸出文件所有工作表名:\n', wb.sheetnames)
#定位當前活躍工作表:
ws = wb.active
#列印
c = ws['A4']
c1 = ws.cell(row=1, column=2)
print(c, c1)
print(c.value, c1.value)
Example :
from openpyxl import load_workbook
i='One';
wb = load_workbook('./DA_TEST1.xlsx')
print('Output Sheet Name:\n', wb.sheetnames)
ws = wb.active
c = ws['A4']
c1 = ws.cell(row=1, column=2)
c2 = ws['C4']
print(c, c1, c2)
print(c.value, c1.value, c2.value)
if c1.value == "One":
print('Yes')
else:
print('No')
if c1.value == None:
print('Yes')
else:
print('No')
新建工作簿對象:
from openpyxl import load_workbook
from openpyxl.styles import colors, Font, Fill, NamedStyle
from openpyxl.styles import PatternFill, Border, Side, Alignment
# 載入文件
wb = load_workbook('./5a.xlsx')
print('輸出文件所有工作表名:\n', wb.sheetnames)
#定位當前活躍工作表:
ws = wb.active
#列印
c = ws['A4']
c1 = ws.cell(row=1, column=2)
print(c, c1)
print(c.value, c1.value)
Example :
from openpyxl import load_workbook
i='One';
wb = load_workbook('./DA_TEST1.xlsx')
print('Output Sheet Name:\n', wb.sheetnames)
ws = wb.active
c = ws['A4']
c1 = ws.cell(row=1, column=2)
c2 = ws['C4']
print(c, c1, c2)
print(c.value, c1.value, c2.value)
if c1.value == "One":
print('Yes')
else:
print('No')
if c1.value == None:
print('Yes')
else:
print('No')
留言
張貼留言