Python中Excel单元格中不需要的字符 [英] Unwanted character in Excel Cell In Python
问题描述
我在设置 Excel Cell 值时遇到问题.我从 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.
我不知道它来自哪里.
当我将保存单词Hour"的同一个变量写入 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.
可能是什么问题?
非常感谢任何帮助.
我在 Win7 上使用 Python 3.2 和 PyWin32 3.2.谢谢.
I Am Using Python 3.2 And PyWin32 3.2 On Win7. Thanks.
推荐答案
尝试使用 value.rstrip('
')
删除任何回车符 (
code>) 或换行符 (
) 在您的字符串 value
的末尾.
Try using value.rstrip('
')
to remove any carriage returns (
) or newlines (
) at the end of your string value
.
这篇关于Python中Excel单元格中不需要的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!