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 ??
#3
I've not used the openpyxl module, but I have been doing some reading on it, as I plan to use it, but from what I understand (and I could be wrong) I'd try something like:

from openpyxl import Workbook  
wb = Workbook()
sheet = wp.active
sheet['A1'] = f"{=name(parameter)}"
... or something along those lines.

I may even install the module and try it, so that I can see for myself what the issue is.


Okay, I've tried this:

from openpyxl import Workbook

wb = Workbook()
sheet = wb.active
sheet['A1'] = "'\=name(parameter)"
wb.save("test.xlsx")
... and A1 shows as '\=name(parameter)

Is that what you wanted?


Update:
Thinking about your code some more, the issue you have, is that in Python, the backslash is a 'special' character, as in \t for a tab. or \n for a newline. If you want a literal backslash, you need to escape it, which is yet another use for backslash, so your code would need to be sheet.cell(1, 1).value = "\\'" + "=" + "name" + "(parameter)".

As you can see, that looks a little clumsy (as does all string concatenation), which is one reason not to use such code.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Messages In This Thread
RE: How to get cell(x,y).value = "\'=name(p)" to show correctly ?? - by rob101 - Oct-28-2022, 10:22 PM

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