不需要的字符在Python单元格中的Python [英] Unwanted character in Excel Cell In Python
问题描述
我在设置Excel单元格的值时遇到问题。
我从MS-Word文档(dcx)中的表单元格中获取数据并在输出控制台上打印。
I am facing an issue with setting a value of Excel Cell. I get data from a table cell in MS-Word Document(dcx) and print it on output console.
问题是单元格的数据只是一个字,小时,没有明显的其他前导或尾随可打印字符,如空格。但是当我使用python的print()函数打印它,它显示一些意想不到的字符,更像一个小?
Problem is that the data of the cell is just a word, "Hour", with no apparent other leading or trailing printable character like white-spaces. But when I print it using python's print() function, it shows some unexpected character, more like a small "?" in a rectangle.
我不知道它来自哪里。
保存单词小时的相同变量,对于Excel单元格,在单元格中显示一个粗体点(。)。
And when I write the same variable that holds the word, "Hour", to an Excel cell it shows a bold dot(.) in the cell.
可能是问题?
任何帮助是非常感激。
我使用Python 3.2和PyWin32 3.2 Win7。
感谢。
I Am Using Python 3.2 And PyWin32 3.2 On Win7. Thanks.
推荐答案
尝试使用 value.rstrip('\r\\\
删除任何回车符(
') \r
)或换行符( \\\
)
value
。
Try using value.rstrip('\r\n')
to remove any carriage returns (\r
) or newlines (\n
) at the end of your string value
.
这篇关于不需要的字符在Python单元格中的Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!