Python Forum
How to get cell(x,y).value = "\'=name(p)" to show correctly ??
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get cell(x,y).value = "\'=name(p)" to show correctly ??
#10
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
Reply


Messages In This Thread
RE: How to get cell(x,y).value = "\'=name(p)" to show correctly ?? - by deanhystad - Oct-31-2022, 06:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PIL Image im.show() no show! Pedroski55 2 1,049 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  PIL Image im.show() no show! Pedroski55 6 5,291 Feb-08-2022, 06:32 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020