簡體   English   中英

使用 xlwings 查找第一個沒有數據的 Excel 列

[英]Finding first Excel column with no data using xlwings

我在 Excel 中有一個工作簿,我需要找到第一列為空/其中沒有數據。 我需要始終保持 Excel 打開,所以像openpyxl這樣的東西是行不通的。

到目前為止,這是我的代碼:

import xlwings as xw
from pathlib import Path

wbPath = Path('test.xlsx')

wb = xw.Book(wbPath)

sourceSheet = wb.sheets['source']

這可以使用

destinationSheet["A1"].expand("right").last_cell.column

根據您的確切需要,此代碼可能是最可靠的。 使用used_range時,代碼會為您提供數據末尾的第一個空列 integer,而不管最后一列數據之前的空/空白列。

a_rng = sourceSheet.used_range[-1].offset(column_offset=1).column
print(a_rng)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM