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 ??
#8
I think this might be what you want.
import openpyxl

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")
For testing I made a small spreadsheet named "data.xlsx".
Output:
A1: 3, B1: =A1+A2 A2: 4, B2: '=A1+A2
Running the program creates a new spreadsheet named "data2.xlsx" with new cells A3 which acts just like A2 (text) and A4 which acts just like A1 (formula), all the way down to showing the leading quote for text cells.
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  PIL Image im.show() no show! Pedroski55 2 1,089 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  PIL Image im.show() no show! Pedroski55 6 5,472 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