Ich habe ein Excel -Arbeitsbuch mit zwei Blättern. Sheet2 enthält einen ganzen Dump, während SHAP1 Formeln enthält, die bestimmte Daten von Blatt2 abrufen. Aber es funktioniert nicht.import openpyxl
# Load the workbook
wb = openpyxl.load_workbook(file_path)
# Select the worksheet
ws = wb['Sheet1']
# Iterate over cells with formulas
for row in ws.iter_rows():
for cell in row:
if cell.data_type == 'f': # 'f' stands for formula
cell.value = cell.value # This will replace the formula with its value
if isinstance(cell.value, str): # Check if the value is a string
cell.data_type = 's' # 's' stands for string
else:
cell.data_type = 'n' # 'n' stands for number
wb.save(file_path)
< /code>
Ich habe versucht, Pandas zu verwenden, und es funktionierte, aber es hat alle Formatierung und Blatt 2 entfernt.>
Fügen Sie Excel -Formelspalten als Werte mit Python ein ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post