writing backspace "\b" into the cell using xlwt

56 views
Skip to first unread message

陈立

unread,
Sep 4, 2013, 8:47:30 AM9/4/13
to python...@googlegroups.com
Hello, all experts,

I am now using xlwt to create excel file with python.  But there is a problem when I

use the write() function to write a backspace('\b') into one cell of the excel file but it turns out that

the excel file cannot interpret it correctly, that is, this backspace cannot delete what I write it before but is interpreted

as another strange sign instead. The code is like this:

ws.write(3, 1, '2 '+George, xlwt.easyxf('font: name Times New Roman, color-index pink; borders: left THIN, right THIN, top THIN, bottom THIN; align: wrap on, vert center, horiz center;'))

where ws is a sheet pointer and George is a string.


How can I write '\b' correctly into the cell of the excel file?

Thanks!

John Machin

unread,
Sep 9, 2013, 5:05:34 PM9/9/13
to python...@googlegroups.com

Given your definition of correctness, you can't. An Excel text string is not a glass teletype. Instead of wriring "foox\bbar", write "foobar" i.e. do your teletype emulation yourself.
 

Dennis Newbold

unread,
Sep 9, 2013, 7:27:34 PM9/9/13
to python...@googlegroups.com
I'm not sure why you would want to do that. Instead, you could read the entire contents of the cell, modify said string anyway you want via regular expression processing, or displaying it to a human operator and asking him / her to enter whatever the correct string should be.  Once you have the correct string, just write the whole thing back into the cell, replacing the old contents with your new string.  The only reason I can think of for doing what you describe is if your are writing an entire Excel "look alike" program.  In that case, following the standard M-V-C design pattern, your view would be a GUI program which would display the current spreadsheet contents in some user-friendly format, accept user inputs and, once the user's focus has left the text entry field, read the field, and then write that into the appropriate Excel cell.  Which is pretty much the same approach I just spoke about, so I'm repeating myself, and therefore should and will stop. :).


--
You received this message because you are subscribed to the Google Groups "python-excel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-excel...@googlegroups.com.
To post to this group, send an email to python...@googlegroups.com.
Visit this group at http://groups.google.com/group/python-excel.
For more options, visit https://groups.google.com/groups/opt_out.



--
   The way to be happy is to be good.

陈立

unread,
Sep 11, 2013, 9:53:02 AM9/11/13
to python...@googlegroups.com
Thank you for your help. I am using \b just to make the code simple.  If I can use \b, I'd probably overwrite them on the whole as you suggested.

在 2013年9月10日星期二UTC+8上午7时27分34秒,dennisne写道:
Reply all
Reply to author
Forward
0 new messages