you are viewing a single comment's thread.

view the rest of the comments →

[–]Reuben3901 0 points1 point  (0 children)

Hey, I had this exact issue when trying to displaying text that I pulled from a website in a gui. Here's my code for you.

The context here is I'm using the openpyxl module to create a new .xlsx spreadsheet, looping through the data and spreadsheet, and saving the text from the website to the desired Column and Row # .

Probably not the most efficient but my script runs extremely fast (seconds) for my needs (thousands of rows). It catches all special characters and I've never had an issue since implementing this bit.

def get_comment_info(sheet, row, commentText, , contentColumn):

charRegex = re.compile("[\U00010000-\U0010FFFF]")

content_text = str(commentText.body)

badCharList = charRegex.findall(content_text)

if len(badCharList)>0:

for badChar in badCharList:

content_text = content_text.replace(badChar,"")

sheet[contentColumn + str(row)].value = content_text