
##第十二章 电子表格单元格翻转程序
##方法一:
import openpyxl
from openpyxl.utils import get_column_letter
wb = openpyxl.load_workbook('style.xlsx')
sheet = wb.active
# length = sheet.max_row if sheet.max_row > sheet.max_column else sheet.max_column
length = [sheet.max_column,sheet.max_row][sheet.max_row > sheet.max_column]#取行跟列的较大值
for i in range(1, length+1):for j in range(1, i):temp =sheet[get_column_letter(i) + str(j)].valuesheet[get_column_letter(i) + str(j)] = sheet[get_column_letter(j) + str(i)].valuesheet[get_column_letter(j) + str(i)] = temp# print(str(sheet[get_column_letter(i) + str(j)].value)+' '+str(sheet[get_column_letter(j) + str(i)].value))
print("Done")
wb.save('style11.xlsx')##电子表格单元格翻转程序方法二
import openpyxl#导入模块
from openpyxl.utils import column_index_from_string
wb=openpyxl.load_workbook('style.xlsx')
wb2 = openpyxl.Workbook()
sheet = wb.active
sheet2 = wb2.active
for rowobj ws:#迭代每一个单元格for cellobj in rowobj:# print(ll(row=column_index_from_lumn),columnw).value=cellobj.value
wb2.save('style22.xlsx')
print('Done')
本文发布于:2024-02-01 00:41:44,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170671930632582.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
| 留言与评论(共有 0 条评论) |