Skip to content

Commit f7f2350

Browse files
committed
revise post
1 parent c63390e commit f7f2350

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

_posts/2024-09-19-error_xls.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,30 @@ ValueError: Excel file format cannot be determined, you must specify an engine m
2424

2525
해당 오류는 openpyxl이 xls 파일을 로드하지 못해서 발생하는 오류입니다.
2626

27-
아래 방법을 통해 간단하게 해결할 수 있습니다.
27+
아래 방법을 통해 엔진을 "xlrd"로 변경하여 해결할 수 있습니다.
2828

2929
```python
3030
pip install xlrd
3131

3232
df = pd.read_excel(PATH, engine='xlrd')
33+
```
34+
35+
하지만 해당 코드로도 아래와 같은 오류가 발생하며 데이터가 로드되지 않는 경우가 있습니다.
36+
37+
```python
38+
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\r\n\r\n\r\n\r\n'
39+
```
40+
41+
이때는 다음과 같은 방법을 통해 데이터의 확장자를 xlsx로 변경해주고 로드해야 합니다.
42+
43+
```python
44+
import win32com.client as win32
45+
46+
fname = PATH # Absolute path
47+
excel = win32.gencache.EnsureDispatch("Excel.Application")
48+
wb = excel.Workbooks.Open(fname)
49+
50+
wb.SaveAs(fname + 'x', FileFormat = 51) # FileFormat = 51 is for .xlsx extension
51+
wb.Close() # FileFormat = 56 is for .xls extension
52+
excel.Application.Quit()
3353
```

0 commit comments

Comments
 (0)