Oct-31-2022, 06:47 PM
If you are interested, this is the program I used to peek around in the workbook.
import openpyxl import pandas as pd def set_cell_text(cell, text): cell.value = text cell.data_type = "s" cell.quotePrefix = True wb = openpyxl.load_workbook("data.xlsx") set_cell_text(wb.active["B3"], "=A1+A2") wb.active["B4"] = "=A1+A2" wb.save("data2.xlsx") cell_attributes = ( "coordinate", "comment", "encoding", "data_type", "encoding", "has_style", "hyperlink", "internal_value", "is_date", "number_format", "pivotButton", "quotePrefix", "style", "style_id", "value") cells = {} for address, title in zip(("B1", "B4", "B2", "B3"), ("Formula", "My Formula", "Text", "My Text")): cell = wb.active[address] cells[title] = {attr:getattr(cell, attr) for attr in cell_attributes} df = pd.DataFrame(cells) print(df)
Output: Formula My Formula Text My Text
coordinate B1 B4 B2 B3
comment None None None None
encoding utf-8 utf-8 utf-8 utf-8
data_type f f s s
has_style False False True True
hyperlink None None None None
internal_value =A1+A2 =A1+A2 =a1+a2 =A1+A2
is_date False False False False
number_format General General General General
pivotButton False False False False
quotePrefix False False True True
style Normal Normal Normal Normal
style_id 0 0 1 1
value =A1+A2 =A1+A2 =a1+a2 =A1+A2