Skip to content

Commit 2cb6709

Browse files
committed
feat: Add support for encoding parameter on read_excel
1 parent 9019582 commit 2cb6709

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pandas/io/excel.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def read_excel(io,
303303
skipfooter=0,
304304
convert_float=True,
305305
**kwds):
306-
306+
encoding = kwds.get("encoding")
307307
# Can't use _deprecate_kwarg since sheetname=None has a special meaning
308308
if is_integer(sheet_name) and sheet_name == 0 and 'sheetname' in kwds:
309309
warnings.warn("The `sheetname` keyword is deprecated, use "
@@ -315,7 +315,7 @@ def read_excel(io,
315315
"`sheet`")
316316

317317
if not isinstance(io, ExcelFile):
318-
io = ExcelFile(io, engine=engine)
318+
io = ExcelFile(io, engine=engine, encoding=encoding)
319319

320320
return io.parse(
321321
sheet_name=sheet_name,
@@ -358,7 +358,7 @@ class ExcelFile(object):
358358
def __init__(self, io, **kwds):
359359

360360
err_msg = "Install xlrd >= 0.9.0 for Excel support"
361-
361+
encoding = kwds.get("encoding")
362362
try:
363363
import xlrd
364364
except ImportError:
@@ -400,9 +400,15 @@ def __init__(self, io, **kwds):
400400
pass
401401

402402
data = io.read()
403-
self.book = xlrd.open_workbook(file_contents=data)
403+
if encoding:
404+
self.book = xlrd.open_workbook(file_contents=data, encoding_override=encoding)
405+
else:
406+
self.book = xlrd.open_workbook(file_contents=data)
404407
elif isinstance(self._io, compat.string_types):
405-
self.book = xlrd.open_workbook(self._io)
408+
if encoding:
409+
self.book = xlrd.open_workbook(self._io, encoding_override=encoding)
410+
else:
411+
self.book = xlrd.open_workbook(self._io)
406412
else:
407413
raise ValueError('Must explicitly set engine if not passing in'
408414
' buffer or path for io.')

0 commit comments

Comments
 (0)