Задать вопрос
  • Проблемы с кодировкой при конвертации из xls в json?

    @967030
    Спасибо! работает!

    import xlrd
    from collections import OrderedDict
    import json

    def main():
    wb = xlrd.open_workbook("filter3.xls", encoding_override='utf-8')
    sh = wb.sheet_by_index(0)

    data_list = []
    print(sh.nrows)

    for rownum in range(0, sh.nrows):
    data = OrderedDict()
    row_values = sh.row_values(rownum)

    data['filter-1'] = row_values[0]
    data['filter-2'] = row_values[1]
    data['filter-3'] = row_values[2]
    data_list.append(data)

    for item in data_list:
    print(item)

    with open("filter.json", "w", encoding='utf8') as writeJsonfile:
    json.dump(data_list, writeJsonfile, indent=4, default=str, ensure_ascii=False)

    print('финиш')

    if __name__ == '__main__':
    main()

    version 3.10
    Ответ написан
    Комментировать