pyexcel-renderers / pyexcel-sortable

Inspired by csvtotable. It converts any support excel file formats into sortable table using csvtotable functionality.
Other
5 stars 0 forks source link

UnicodeEncodeError - 'charmap' condec cant encode character #2

Open eugjr opened 3 years ago

eugjr commented 3 years ago

Hello, I'm trying to run a .py script to convert a .csv file to a .html table. I'm using this code as first try. I'm trying to run it on Win7.

import pyexcel as p

sheet = p.get_sheet(file_name='banks.csv', encoding="utf-8")
sheet.save_as('me.sortable.html', dest_encoding="utf-8", display_lenght=10)
from IPython.display import IFrame
IFrame("me.sortable.html", encoding="utf-8", width=600, height=500)

But I'm getting the following error: UnicodeEncodeError: 'charmap' codec can't encode character '\u56fd' in position 239945: character maps to

As you can see in the code, I've even tryied to run the get and save sheets command with "enconding='utf-8' option, but didn't get any luck with it.

Even with a simple csv file with A,B,C,D,E and 1,2,3,4,5 data it gets the same error.

Above the complete output when running the script.

WARNING:excel2table:
Virtual scroll is enabled since number of rows exceeds -1. You can set custom row limit by setting flag -vs, --virtual
croll. Virtual scroll can be disabled by setting the value to -1 and set it to 0 to always enable.
Traceback (most recent call last):
  File "converte1.py", line 7, in <module>
    sheet.save_as('me.sortable.html', dest_encoding="utf-8", display_lenght=10)
  File "C:\Users\Sulamericana\AppData\Local\Programs\Python\Python38\lib\site-packages\pyexcel\internal\meta.py", line
60, in save_as
    return save_sheet(self, file_name=filename, **keywords)
  File "C:\Users\Sulamericana\AppData\Local\Programs\Python\Python38\lib\site-packages\pyexcel\internal\core.py", line
7, in save_sheet
    return _save_any(a_source, sheet)
  File "C:\Users\Sulamericana\AppData\Local\Programs\Python\Python38\lib\site-packages\pyexcel\internal\core.py", line
9, in _save_any
    a_source.write_data(instance)
  File "C:\Users\Sulamericana\AppData\Local\Programs\Python\Python38\lib\site-packages\pyexcel\plugins\sources\file_ou
ut.py", line 31, in write_data
    self._renderer.render_sheet_to_file(
  File "C:\Users\Sulamericana\AppData\Local\Programs\Python\Python38\lib\site-packages\pyexcel\renderer.py", line 87,
 render_sheet_to_file
    self.render_sheet(sheet, **keywords)
  File "C:\Users\Sulamericana\AppData\Local\Programs\Python\Python38\lib\site-packages\pyexcel_sortable\sortable.py",
ne 48, in render_sheet
    self._stream.write(js_freezed_html)
  File "C:\Users\Sulamericana\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u56fd' in position 239945: character maps to <undefined>
chfw commented 3 years ago

Can you configure your dos command prompt to use utf-8?