Unicode support in charts
Created originally on Bitbucket by datacompboy (Anton Fedorov)
#!text
File "/usr/local/lib/python2.7/dist-packages/openpyxl-1.5.8-py2.7.egg/openpyxl/writer/charts.py", line 161, in _write_series
self._write_serial(tx, serie.legend)
File "/usr/local/lib/python2.7/dist-packages/openpyxl-1.5.8-py2.7.egg/openpyxl/writer/charts.py", line 226, in _write_serial
SubElement(point, 'c:v').text = str(val)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
fix is trivial: replace at that line "str" with "unicode"
test code:
#!python
# coding=utf8
from openpyxl import Workbook
from openpyxl.chart import BarChart, Serie, Reference, ScatterChart, LineChart
wb = Workbook()
ws = wb.worksheets[0]
ws.cell('A1').value = u'Тест'
for i in range(10):
ws.cell(row = i+1, column = 0).value = i**2
chart = LineChart()
chart.add_serie(Serie(Reference(ws, (1, 0), (11, 0)), legend=Reference(ws, (0, 0))))
chart.drawing.left = 200
chart.drawing.top = 20
chart.drawing.height = 200
chart.drawing.width = 500
ws.add_chart(chart)
wb.save(filename = "test.xlsx")