python 使用xlsxwriter 写入数据时,当数据中链接的后面包含空格时(如:"http://*** "),导出问题打开报错
python 在使用 xlsxwriter组件写入数据时,当数据包含类似“http://*** /”数据时,导出的excel,打开时会提示如下错误:

没有查到相关的资料处理这个问题,可能原因为excel识别为链接,与内置库冲突导致,对数据准确性无大影响的情况下,只能临时通过字符替换解决:
if keyword.startswith('http://') and keyword.find(' ') >= 0:
keyword = keyword.replace('','')
截取的部分代码如下:
os.chdir('/data/scripts/file/')
filename = "统计-" + last_month + ".xlsx"
# 将查询的结果写入至EXCEL
workbook = xlsxwriter.Workbook(filename)
worksheet = workbook.add_worksheet(name="数据统计")
worksheet.set_column("B:B", 40)
#header_style = workbook.add_format({})
header_style = workbook.add_format({"bold" : True, "font_size" : 10, "align" : "center", "bg_color" : "#DCDCDC", "top" : 1, "bottom" : 1, "left" : 1, "right" : 1})
#item_style = workbook.add_format({})
item_style = workbook.add_format({"font_size" : 10, "align" : "center", "top" : 1, "bottom" : 1, "left" : 1, "right" : 1})
# 写入表头
worksheet.write(0,0,"序号",header_style)
worksheet.write(0,1,"词",header_style)
worksheet.write(0,2,"总数",header_style)
sorted_search_dict = sorted(search_dict.items(), key=lambda d:d[1], reverse = True)
# 写入数据项
data_row = 0
for i in sorted_search_dict:
data_row += 1
keyword = i[0].strip()
if keyword.startswith('http://'):
keyword = keyword.replace('','')
#print(str(data_row) + "," + i[0] + "," + str(i[1]))
worksheet.write(data_row , 0, data_row, item_style)
worksheet.write(data_row , 1, keyword, item_style)
worksheet.write(data_row , 2, i[1], item_style)
workbook.close()
python 使用xlsxwriter 写入数据时,当数据中链接的后面包含空格时(如:"http://*** "),导出问题打开报错的更多相关文章
- [转]Windows中的命令行提示符里的Start命令执行路径包含空格时的问题
转自:http://www.x2009.net/articles/windows-command-line-prompt-start-path-space.html 当使用Windows 中的命令行提 ...
- excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法
excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法 office2007应该遇到“向程序发送命令时出现 问题”,设置为以管理员运行也不好用,重装office也不好用,下面介绍下 ...
- 转:Windows中的命令行提示符里的Start命令执行路径包含空格时的问题
转自:http://www.x2009.net/articles/windows-command-line-prompt-start-path-space.html 当使用Windows 中的命令行提 ...
- GetPrivateProfileString() 当 key 包含空格时,需要进行转义
使用 GetPrivateProfileString() 方法可以方便的读取 ini 格式文件中的内容,如: [section] tommy = worker 使用 C# 读取如下: 1. 先引入 G ...
- urlencode($url):把url转义,当字符串数据以url的形式传递给web服务器时,字符串中是不允许出现空格和特殊字符串的
1.对url进行编码转义
- sharepoint 2013 文档库 资源管理器打开报错 在文件资源管理器中打开此位置时遇到问题,将此网站添加到受信任站点列表,然后重试。
我们在使用sharepoint 2013的文档库或者资源库的时候,经常会需要用到使用“资源管理器”来管理文档,但是有时候,点击“使用资源管理器打开”,会提示如下错误: 在文件资源管理器中打开此位置时遇 ...
- 记oracle使用expdp将数据导出到asm报错
报错信息如下: ORA-39002: invalid operationORA-39070: Unable to open the log file.ORA-29283: invalid file o ...
- JetBrains GoLand 以debug运行Go程序时出现could not launch process: decoding dwarf section info at offset 0x0: too short报错之保姆级别解决方案
这是一篇写给刚开始学习Go语言而在搭建环境可能遇到问题的小萌新的文,大神请自行绕路哈(0-0) 有天,我把Go运用环境升到最新版1.16后,用以前一直在用的JetBrains GoLand 2017. ...
- Ant 执行 exec cmd.exe 时路径包含空格的问题
需求描述 通过Ant脚本调用bat脚本 问题描述 bat脚本所在目录名称包含空格(space),cmd.exe调用时候报错The system cannot find the path specifi ...
随机推荐
- Redis分布式锁的正确姿势
1. 核心代码: import redis.clients.jedis.Jedis; import java.util.Collections; /** * @Author: qijigui * @C ...
- Vue 3.0 Composition API - 中文翻译
Composition API 发布转载请附原文链接 https://www.cnblogs.com/zgh-blog/articles/composition_api.html 这两天初步了解了下 ...
- Ubuntu syslog 太多的 named[1195]: error (network unreachable) resolving './DNSKEY/IN': 2001:7fd::1#53
Edit file /etc/default/bind9: # run resolvconf? RESOLVCONF=yes # startup options for the server OPTI ...
- QT 无法抓住异常
出处:https://stackoverflow.com/questions/40980171/qt5core-dll-crashing I've found that enabling /EHa ( ...
- java中CompletionService的使用
java中CompletionService的使用 之前的文章中我们讲到了ExecutorService,通过ExecutorService我们可以提交一个个的task,并且返回Future,然后通过 ...
- Spring5参考指南:Environment
文章目录 Profiles PropertySource 使用@PropertySource Spring的Environment接口有两个关键的作用:1. Profile, 2.properties ...
- Boostrap Table学习笔记
最近要对项目上的table进行调整,让表格能够支持更多的操作,于是接触到了boostrapTable这个插件.研究了一天,记录下学习的内容. Boostrap Table可以支持表的分页及动态显示表的 ...
- 中国AI觉醒 阿里王坚:云智能将成为大趋势
2019独角兽企业重金招聘Python工程师标准>>> <麻省理工科技评论>新兴科技峰会EmTech China于北京召开.大会中,其中一项热门的讨论便是:中国和美国的科 ...
- CodeForces - 1245A Good ol' Numbers Coloring (思维)
Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integ ...
- 图论--边双连通V-DCC缩点
// tarjan算法求无向图的割点.点双连通分量并缩点 #include<iostream> #include<cstdio> #include<cstring> ...