![](/img/trans.png)
[英]How to insert a pandas data frame in one cell in excel (using openpyxl), where the values will be separated with comma?
[英]OpenPyXl: Can I reference data from one Excel file and insert values into a cell based on an identifier?
是否可以從一個 Excel 文件中獲取 SKU 和其他信息,並在另一個標識符下方引用它:SKU、名稱等?
我有一個 Excel 文件,其中包含像模板一樣的各種工作表。 在每張表中都可以找到相同或非常相似的標識符,例如Product SKU
。
我目前的想法是,一旦我有了Product SKU
的cell.column
和cell.row
,我就可以分別將其存儲在變量中,並將cell.row
增加+1
,這樣我就可以從Product SKU
下面的另一張表中加載信息。 最終結果在 Excel 中將如下所示。 我會將上述邏輯應用於我想要加載的所有其他信息。
+-------------+----------------+
| Product Sku | Product Name |
+-------------+----------------+
| 12345678 | Some Product |
+-------------+----------------+
我試圖產生的想法。 如果有更好的方法,請告訴我。
from openpyxl import load_workbook
wb = load_workbook(filename = "product_import_tmp.xlsx")
inventory_1_sheet = wb["Inventory 1"]
for row in inventory_1_sheet.iter_rows(values_only=False):
for cell in row:
if cell.value == "Product SKU":
sku_y = cell.column
sku_x = cell.row + 1 # The Product SKU information would go here
如果你能提供你的 excel 文件的樣子會更好。 如果對 excel 有復雜的操作,我建議使用 pandas 而不是 openpyxl。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.