> Swedish special characters...
> But when sending them to a CSV file and opening it in Excel are not
> shown correctly.
Here my code (functions in controller). I'm not sure if this is
correct solution, but it works for me. I think response header
'Content-Type' with 'utf-8' is important.
My code was tested for czech language and czech localized Excel,
however I hope it will work for swedish too, because swedish is some
kind of czech language?
Note, that there is bug in Opera browser at this time. Opera download/
saves the file correctly to disk, however with Open button the oldest
from saved csv files go to open. Regardless, if you use same name, or
if you change it (as in following code, where I add current time to
the filename). So you have to delete older file earlier, or just Save
it and open it in Excel from the disk, not directly from browser.
Other browser behaves correctly.
def excel():
import StringIO
sIO = StringIO.StringIO()
rsTable = db().select(db.tablename.ALL)
rsTable.export_to_csv_file(sIO, null='', delimiter='|')
__responseHeaders('exportedtable' +
datetime.datetime.now().strftime('_%Y%m%d_%H%M%S') + '.csv')
cFileContent = sIO.getvalue()
sIO.close()
return cFileContent
def __responseHeaders(fName=None):
response.headers['Content-Type'] = 'text/csv; charset=utf-8'
# duplicita s gluon\main.py, ale Expires se tam dělá pomocí time
objektu
response.headers['Cache-Control'] = 'no-store, no-cache, must-
revalidate, post-check=0, pre-check=0'
#response.headers['Cache-Control'] = 'no-cache, private, no-store,
must-revalidate, max-stale=0, post-check=0, pre-check=0'
response.headers['Expires'] =
datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT') #
Tue, 02 Nov 2010 08:15:33 GMT
# nebo lze .Expires = -1
response.headers['Pragma'] = 'no-cache'
if fName:
response.headers['Content-disposition'] = 'attachment;
filename="' + fName + '"'