1 回答

TA貢獻1856條經(jīng)驗 獲得超17個贊
要刪除rows
并columns
僅使用:
sheet.delete_rows({first_row}, {amount})
sheet.delete_cols({first_col}, {amount})
因此,請閱讀openpyxl 文檔中的更多信息。請注意,列表示為整數(shù)A == 1, B ==2
,依此類推。
import string
def col2num(col):
# Utility function to convert column letters to numbers
num = 0
for c in col:
if c in string.ascii_letters:
num = num * 26 + (ord(c.upper()) - ord('A')) + 1
return num
# Setting initial values for deletion
starting_row = 4
starting_col = col2num('U')
last_col = col2num('AA')
# Deleting rows and columns
sheet.delete_rows(starting_row, sheet.max_row-starting_row)
sheet.delete_cols(starting_col, last_col-starting_col)
添加回答
舉報