User Tools

Site Tools


python:exelprocess

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python:exelprocess [2020/02/26 11:28] – [Parse xls file] adminpython:exelprocess [2022/10/29 16:15] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Exel Processing ====== ====== Exel Processing ======
 +===== Function in Exel =====
 +Trước khi xử lý các hàm tìm kiếm Vlookup and Hlookup, If trong exel cần phải format dữ liệu và sort trước -> Lúc đó hàm xử lý mới chạy đúng
 +VLOOKUP($B2,omni!$A$1:$C$4778,3,FALSE) -> Tìm chính xác nhờ tuỳ chọn **FALSE**
 ===== Install ===== ===== Install =====
   * Install on windows:<code bat>   * Install on windows:<code bat>
Line 11: Line 14:
 pip install xlutils pip install xlutils
 </code> </code>
-===== using xlrd =====+===== Using xlrd =====
 Basic APIs: Basic APIs:
   * **xlrd.open_workbook('adminup/shop.xlsx')** return **xlrd.book.Book** object   * **xlrd.open_workbook('adminup/shop.xlsx')** return **xlrd.book.Book** object
Line 119: Line 122:
 parsexls(constantsfile)   parsexls(constantsfile)  
 </code> </code>
 +==== Error Parse UTF-8 file ====
 +<code>
 +UnicodeDecodeError: 'utf16' codec can't decode bytes in position 3438-3439: unexpected end of data
 +</code> => Check exel format in encoding(not utf-8)(May be exel file was not stored as encoding utf-8, It can be saved as utf16 default encoding) 
 +You can debug for information:<code python>
 +xlsfile = xlrd.open_workbook(filename,verbosity=3)
 +</code>output:<code>
 +BOF: op=0x0809 vers=0x0600 stream=0x0005 buildid=14420 buildyr=1997 -> BIFF80
 +CODEPAGE: codepage 1200 -> encoding 'utf_16_le'
 +DATEMODE: datemode 0
 +</code> => default encoding: **'utf_16_le'**
 +
 +**Fix**: Lỗi do file exel, mở lại file exel và lưu lại sẽ hết lỗi
 ===== Using xlwt ===== ===== Using xlwt =====
python/exelprocess.1582716500.txt.gz · Last modified: 2022/10/29 16:15 (external edit)