Skip to content

chokes on certain characters when exporting to Excel #19

@ajkessel

Description

@ajkessel

I'm getting this error exporting to Excel:

Traceback (most recent call last):
  File "/Users/adam/Library/Python/3.11/bin/imessage_reader", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/adam/Library/Python/3.11/lib/python/site-packages/imessage_reader/cli.py", line 116, in main
    check_database_path(args)
  File "/Users/adam/Library/Python/3.11/lib/python/site-packages/imessage_reader/cli.py", line 77, in check_database_path
    evaluate(MACOS_DB_PATH, args.output, args.recipients, args.version)
  File "/Users/adam/Library/Python/3.11/lib/python/site-packages/imessage_reader/cli.py", line 104, in evaluate
    data.show_user_txt("excel")
  File "/Users/adam/Library/Python/3.11/lib/python/site-packages/imessage_reader/fetch_data.py", line 125, in show_user_txt
    self._export_excel(fetched_data)
  File "/Users/adam/Library/Python/3.11/lib/python/site-packages/imessage_reader/fetch_data.py", line 143, in _export_excel
    ew.write_data()
  File "/Users/adam/Library/Python/3.11/lib/python/site-packages/imessage_reader/write_excel.py", line 89, in write_data
    sheet.cell(row=messages_row, column=2).value = message
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam/Library/Python/3.11/lib/python/site-packages/openpyxl/cell/cell.py", line 218, in value
    self._bind_value(value)
  File "/Users/adam/Library/Python/3.11/lib/python/site-packages/openpyxl/cell/cell.py", line 197, in _bind_value
    value = self.check_string(value)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam/Library/Python/3.11/lib/python/site-packages/openpyxl/cell/cell.py", line 165, in check_string
    raise IllegalCharacterError(f"{value} cannot be used in worksheets.")

When I look at the message that it's choking on (with a text export), it appears to begin with ^YYour. I'm not sure what the ^Y is there for as the message itself just appears to be "Your..." in iMessages, but it seems like the extended character there is raising an exception. Could you sanitize the string to remove illegal characters?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions