python3.6 xlwt 安装报错解决
来源:互联网 发布:java 内存泄露场景 编辑:程序博客网 时间:2024/05/16 20:28
python3.6 版本
pip install xlwt 安装成功后
import xlwt 一直提示错误
Python 3.6.0a4 (v3.6.0a4:017cf260936b, Aug 16 2016, 00:59:16) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
======= RESTART: E:\work\officedoc\bom\code\python\test_excel3xlwt.py =======
Traceback (most recent call last):
File "E:\work\officedoc\bom\code\python\test_excel3xlwt.py", line 6, in <module>
import xlwt
File "C:\Users\l1600293\AppData\Local\Programs\Python\Python36\lib\site-packages\xlwt\__init__.py", line 4, in <module>
from .Worksheet import Worksheet
File "C:\Users\l1600293\AppData\Local\Programs\Python\Python36\lib\site-packages\xlwt\Worksheet.py", line 38, in <module>
from .Row import Row
File "C:\Users\l1600293\AppData\Local\Programs\Python\Python36\lib\site-packages\xlwt\Row.py", line 7, in <module>
from . import ExcelFormula
File "C:\Users\l1600293\AppData\Local\Programs\Python\Python36\lib\site-packages\xlwt\ExcelFormula.py", line 3, in <module>
from . import ExcelFormulaParser, ExcelFormulaLexer
File "C:\Users\l1600293\AppData\Local\Programs\Python\Python36\lib\site-packages\xlwt\ExcelFormulaLexer.py", line 53, in <module>
VERBOSE+LOCALE+IGNORECASE)
File "C:\Users\l1600293\AppData\Local\Programs\Python\Python36\lib\re.py", line 223, in compile
return _compile(pattern, flags)
File "C:\Users\l1600293\AppData\Local\Programs\Python\Python36\lib\re.py", line 292, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Users\l1600293\AppData\Local\Programs\Python\Python36\lib\sre_compile.py", line 555, in compile
p = sre_parse.parse(p, flags)
File "C:\Users\l1600293\AppData\Local\Programs\Python\Python36\lib\sre_parse.py", line 793, in parse
p.pattern.flags = fix_flags(str, p.pattern.flags)
File "C:\Users\l1600293\AppData\Local\Programs\Python\Python36\lib\sre_parse.py", line 770, in fix_flags
raise ValueError("cannot use LOCALE flag with a str pattern")
ValueError: cannot use LOCALE flag with a str pattern
查找网上,copy xlwt解压包内容到lib下面,也不行。
下班后,依然没有措施。进入sre_parse.py进入查看错误提示770行,
修改代码如下
if flags & SRE_FLAG_LOCALE:
pass #stone20160818 raise ValueError("cannot use LOCALE flag with a str pattern")
执行import xlwt,结果ok。
import xlwt
from datetime import datetime
style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',
num_format_str='#,##0.00')
style1 = xlwt.easyxf(num_format_str='D-MMM-YY')
wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')
ws.write(0, 0, 1234.56, style0)
ws.write(1, 0, datetime.now(), style1)
ws.write(2, 0, 1)
ws.write(2, 1, 1)
ws.write(2, 2, xlwt.Formula("A3+B3"))
wb.save('example.xls')
Windows文件夹生成'example.xls' 内容如下
3.6版本 在同一code中读写同一excel,会提示权限错误(open文件)。(更换不同文件名后,改回来问题不重现了)
必须读和写是不同的文档名。这2个文档可以已经存在。
另外在保存文件后 .xls格式可以打开,保存的 .xlsx格式打开出错。
对.xlsx的文件读取正确
#-*- coding: utf8 -*-
import xlrd
import xlutils
import xlwt
from xlrd import open_workbook
from xlutils.copy import copy
#from datetime import datetime
#fname = "E:/work/officedoc/bom/code/python/reflect.xlsx"
#bk = xlrd.open_workbook(fname)
bk = open_workbook('E:/work/officedoc/bom/code/python/reflect.xls')
shxrange = range(bk.nsheets)
try:
sh = bk.sheet_by_name("sheet1")
except:
print( "no sheet in %s named sheet1" % fname)
#获取行数
nrows = sh.nrows
#获取列数
ncols = sh.ncols
print( "nrows %d, ncols %d" % (nrows,ncols))
#获取第一行第一列数据
cell_value = sh.cell_value(1,1)
#print cell_value
print("cell_value[1,1]=%s" % cell_value)
row_list = []
#获取各行数据
for i in range(1,nrows):
row_data = sh.row_values(i)
row_list.append(row_data)
print ("row_list: ",row_list)
'''
style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',
num_format_str='#,##0.00')
style1 = xlwt.easyxf(num_format_str='D-MMM-YY')
'''
wb = copy(bk)
ws = wb.get_sheet(0) #通过get_sheet()获取的sheet有write()方法
'''
ws.write(10, 0, 1234.56, style0)
ws.write(11, 0, datetime.now(), style1)
'''
ws.write(10, 0, 1234.56)
#ws.write(11, 0, datetime.now())
ws.write(12, 0, 1)
ws.write(12, 1, 1)
ws.write(12, 2, 2)
wb.save('E:/work/officedoc/bom/code/python/reflect2.xls')
- python3.6 xlwt 安装报错解决
- python3.6安装报错,看这里
- python3 scrapy startproject报错解决
- win7 python3.6安装scrapy报错解决方法
- 【已解决】Python3安装multiprocessing报错:SyntaxError: Missing parentheses in call to 'print'
- redis 2.8.6安装报错解决
- Python3解决vs输出中文报错问题
- python3关于urllib中urlopen报错问题的解决
- python3关于urllib中urlopen报错问题的解决
- mac:python3.5+Firefox53总是报错如何解决
- python3 使用thrift操作hbase报错已经解决
- Pycharm使用xlwt时,报错的解决方法
- libmemcached 安装报错 解决
- anaconda安装报错解决
- memcached安装报错解决
- python3 报错
- win7下python3.6通过pip安装scipy报错的解决办法
- Python3.6安装报错 configure: error: no acceptable C compiler found in $PATH
- swift 元组的使用
- ViewPager+PagerTabStrip
- 多少IT人愿意花钱买经验?
- 封装AsyncTask异步请求网络
- ICE之——IceGrid负载均衡部署
- python3.6 xlwt 安装报错解决
- 在py-faster-rcnn/lib下make报错 EnvironmentError: The CUDA lib64 path could not be located in /usr/lib64
- 写给那些用PLSQL和SQLDEV报错的小朋友们
- InnoDB和MyIsAM的区别
- Paxos算法与Zookeeper分析
- scrpay 和 pyv8解析js,抓取天气预报数据
- RESTful API 设计最佳实践
- linux下web测试环境的搭建94
- android5.1修改默认锁屏方式(去除锁屏)