-1

I'm making an excel sheet by some string processing from a source text file, using openpyxl in python 2.7. Till now all the values populated in cells are working exactly as I wanted. Now I'm trying to populate a cell with two lines of string. So I created a string and added that value to a cell.

value_cell1 = "single line string"
value_cell2 = "ABC\n"+"XYZ"
ws.append(value_cell1, value_cell2)

The problem I'm facing is that the second cell has a quote around the value. The value in first cell doesn't have any quotes, which is how I wanted the second cell also to behave. To further clarify, if I copy value in first cell and paste it to notepad, it will just paste the value, as below

single line string # with no quotes

But if I paste second cell's value, it'll come as

"ABC
XYZ" # with quotes

These quotes are not desirable for my subsequent steps hence I wanna remove them. I'm trying to understand why it's behaving this way and would like to know if there's some way to remove these quotes (without further processing like "replace" function or anything).

akhilc
  • 181
  • 4
  • 19

1 Answers1

0

Try this: (assuming ws is an empty list)

value_cell1 = "single line string"
value_cell2 = "ABC\n"+"XYZ"
ws.append(value_cell1)
ws.append(value_cell2)
hridayns
  • 697
  • 8
  • 16
  • If two appends are done, won't it be in the next row. I need both values in same row, that's why I'm including both strings in one append command. – akhilc Jul 03 '17 at 08:02
  • @akhilic https://stackoverflow.com/questions/29354868/how-can-openpyxl-write-list-data-in-sheet - See if this helps you. Maybe you could try using `cell()`. I'm not very familiar with openpyxl. – hridayns Jul 03 '17 at 08:47