Wie lesen Sie den Wert von Excel Fusioned Cell Properties mit Python?Python

Python-Programme
Anonymous
 Wie lesen Sie den Wert von Excel Fusioned Cell Properties mit Python?

Post by Anonymous »

Ich muss Daten aus einer Excel -Datei lesen. Die erste Zelle enthält den Eigenschaftsnamen und die zweite Zelle enthält den Eigenschaftswert. Einige der Eigenschaftsnamen in der ersten Spalte werden jedoch über zwei oder mehr Spalten zusammengeführt, und die entsprechenden Werte befinden sich in der nächsten Zelle. Zum Beispiel ist der Eigenschaftsname "Ref" in den Spalten A und B und sein Wert in Spalte c. src = "https://i.static.net/cwtxnjag.png"/>
Ich verwende Python. Hier ist die Ausgabe: < /p>

Code: Select all

Approval Memo of : SHILPI AKTER
Name of the Applicant : SHILPI AKTER
Name of Territory : Comilla
Total Family Expenses : 30000
Ref : N/A
Amount : N/A
Total Amount : 3000
< /code>
 Ref und Betrag < /strong> Eigenschaften Wert nicht gefunden.
Hier ist mein Code: < /p>
     import os
import openpyxl
from openpyxl.utils import column_index_from_string

file_path = r"D:\file\input\example.xlsx"
if os.path.exists(file_path):
print("File exists!")
else:
print("File not found! Check the path.")
exit()

target_sheet = "Output Approval Templete"

# Define the properties to extract
properties = [
"Approval Memo of",
"Name of the Applicant",
"Name of Territory",
"Total Family Expenses",
"Ref",
"Amount",
"Total Amount"
]

# Function to get the actual value from a merged cell
def get_merged_cell_value(sheet, row, col):
for merged_range in sheet.merged_cells.ranges:
min_row, min_col, max_row, max_col = merged_range.bounds  # Extract merged cell bounds
if min_row

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post