Python Forum
Problem with Polish characters in xlsx file
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Polish characters in xlsx file
#1
I have got a problem with Polish characters in xlsx file(words do not have Polish letters that have disappeared in an unknown way), which I take from table. What am I doing wrong?

import os
import cx_Oracle
import xlsxwriter

con = cx_Oracle.connect('user/password@SID')

cur = con.cursor()

custdata =[]


def main():


    L_sFilename ="List_PNA.xlsx"

    workbook = xlsxwriter.Workbook(L_sFilename)
    worksheet = workbook.add_worksheet()

    format = workbook.add_format({'bold': True, 'font_color': 'red'})
    format.set_font_name('Times New Roman')
    format.set_align('center')

    worksheet.write('A1','PNA',format)
    worksheet.set_column('A:A', 60)

    worksheet.write('B1','BOX',format)
    worksheet.set_column('B:B', 60)

    worksheet.write('C1','NAME',format)
    worksheet.set_column('C:C', 60)

    worksheet.write('D1','PO',format)
    worksheet.set_column('D:D', 60)

    worksheet.write('E1','STREET',format)
    worksheet.set_column('E:E', 60)

    worksheet.write('F1','NUMBERS',format)
    worksheet.set_column('F:F', 60)

    worksheet.write('G1','CITY',format)
    worksheet.set_column('G:G', 60)

    worksheet.write('H1','PROVINCE',format)
    worksheet.set_column('H:H', 60)

    worksheet.write('I1','DISTRICT',format)
    worksheet.set_column('I:I', 60)

    worksheet.write('J1','COMMUNE',format)
    worksheet.set_column('J:J', 60)

    format2 = workbook.add_format()
    format2.set_align('center')
    format2.set_font_color('black')
    format2.set_font_name('Times New Roman')


    L_sSelect ="""select * from my_xml_schema.LIST_PNA_TAB"""

    cur.arraysize = 100
    cur.execute(L_sSelect)


    for result in cur:
        custdata.append((result))

    cur.close()
    con.close()

    for r, row in enumerate(custdata,1):

        for c, col in enumerate(row):
            a=str(col)
            cell = unicode(a, errors='ignore')
            worksheet.write(r, c, cell,format2)
            #print " r= "+str(r) + " c= "+str(c) + " val= "+cell


    workbook.close()
    os.startfile(os.getcwd()+"\\"+L_sFilename)



if __name__ == "__main__":
    main()
Reply
#2
This looks like python 2 code. Are you still using python 2? The error comes probably from the unicode(a, errors='ignore') if it silently removes polish characters. It could probably be replaced by a.decode("some encoding") or codecs.decode(a, "some encoding")
Reply
#3
Yes, I have got a version 2.7.15. Your solutions doesn`t work.
Reply
#4
You're using a language, which is deprecated. The support of Python 2.7 ends in 2020.
With Python 3 you get better Unicode-Support (also for emoticons).
Try it with Python 3. If you still get the same results, something is wrong with the encoding. Fixing encoding errors is more guessing than knowing.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
Mikser Wrote:Yes, I have got a version 2.7.15.
I agree with DeaD_EyE, upgrade to python 3 first. Most python 2 encoding issues simply disappear by moving to python 3. It is a waste of time to solve them.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,426 Nov-09-2023, 10:56 AM
Last Post: mg24
  Convert legacy print file to XLSX file davidm 1 1,801 Oct-17-2021, 05:08 AM
Last Post: davidm
  guys please help me , pycharm is not able to identify my xlsx file CrazyGreenYT7 1 2,009 Jun-13-2021, 02:22 PM
Last Post: Larz60+
  Python3 doesn't populate xlsx file with openpyxl Auldyin75 2 2,523 Feb-16-2021, 12:00 PM
Last Post: Auldyin75
  Split Characters As Lines in File quest_ 3 2,502 Dec-28-2020, 09:31 AM
Last Post: quest_
  get two characters, count and print from a .txt file Pleiades 9 3,350 Oct-05-2020, 09:22 AM
Last Post: perfringo
  P3, openpyxl, csv to xlsx, cell is not number, problem with colorize genderbee 1 2,129 Sep-29-2020, 03:20 PM
Last Post: Larz60+
  Reading integers from a file; the problem may be the newline characters JRWoodwardMSW 2 1,962 Jul-14-2020, 02:27 AM
Last Post: bowlofred
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,665 May-15-2020, 01:37 PM
Last Post: snippsat
  Call a .xlsx file outside a class criscferr 2 1,860 Apr-24-2020, 04:23 PM
Last Post: criscferr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020