V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
linode
V2EX  ›  Python

使用 xlwt 生成 excel 文件时出现诡异的乱码

  •  
  •   linode · 2012-03-12 20:04:33 +08:00 · 4318 次点击
    这是一个创建于 4421 天前的主题,其中的信息可能已经有所发展或是发生改变。
    系统是 Mac

    用的是 xlwt http://pypi.python.org/pypi/xlwt

    代码如下:
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import xlwt

    file = xlwt.Workbook(encoding = 'utf-8')
    table = file.add_sheet('hello', cell_overwrite_ok = True)

    table.write(1, 1, '测试')
    file.save('demo.xls')

    代码写入到 demo.xls 文件中,打开该文件后,单元格的内容都是乱码,但鼠标点击该单元格,在上方的公式栏(fx)里显示又是正常的(如下图),请问这是什么原因呢?该如何解决?

    http://www.uploadup.com/di-ZBNL.png
    1 条回复    1970-01-01 08:00:00 +08:00
    linode
        1
    linode  
    OP
       2012-03-14 12:51:25 +08:00
    问题解决了,原来是 mac 下的 office 字体问题。写入文件的时候设置下字体就可以了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2348 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 16:09 · PVG 00:09 · LAX 09:09 · JFK 12:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.