首页 > 解决方案 > 255 个字符,因为它超出了 Excel 对 URLS 的限制

问题描述

我有一个excel。我想读取并更改此 excel 文件,之后我想将此 excel 文件另存为新的 excel 文件。我不得不将 excel 的列更改为字符串,因为在此列中有表情符号。我的问题是当我尝试保存 excel 文件时。

错误信息

with link or location/anchor > 255 characters since it exceeds Excel's limit for URLS
  force_unicode(url))
C:\Users\user\AppData\Local\Continuum\anaconda3\lib\site-packages\xlsxwriter\worksheet.py:931: UserWarning: Ignoring URL 'https://stackoverflow.com/...'

我发现了这个代码片段,其他人有同样的问题

writer = pd.ExcelWriter(path+fileName, options={'strings_to_urls': False})

但我不知道如何使用writerand my df['Content'] = df['Content'].astype(str). 如何保存我的excel文件而不会出错?在保存之前,我想把 excel 文件拿出来并改变它。

我的代码

import pandas as pd


path = '/My Documents/Python/'
fileName = "Test.xlsx"


#ef = pd.ExcelFile(path+fileName)

df = pd.read_excel(path+fileName, 'Coded Data')
#writer = pd.ExcelWriter(path+fileName, options={'strings_to_urls': False})

i = 1
for test in df['Content']:
    try:
        df['Content'] = df['Content'].astype(str)
    except:
        print("An exception occurred")
        break
    i += 1

print('success')
df.to_excel('/My Documents/Python/test_NEW.xlsx')
print('success')

先感谢您!期待您的回音。

标签: pythonexcelpandas

解决方案


推荐阅读