# !/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import pycontrol.pycontrol as pc
import time
import csv
import ssl
import xlrd
def read_excel(a):
wb=xlrd.open_workbook(filename=a) #打开文件
print wb.sheet_names() ##获取所有表格名字
for x in wb.sheet_names():
print x
read_excel('test.xlsx')
[u'\u6d4b\u8bd5\u9875aaa', u'\u6d4b\u8bd5\u9875bbb', u'Sheet3']
Traceback (most recent call last):
File "t1.py", line 15, in <module>
read_excel('test.xlsx')
File "t1.py", line 14, in read_excel
print x
File "C:\Python27\lib\encodings\cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-2: character maps to <undefined>
解决 print x.encode('utf-8');