Unable to write UUIDs

Issue #638 closed
Marcus Mo
created an issue

Currently obtaining a ValueError: Cannot convert 8af14199-c965-4d8c-8aee-3c9f0cc08d03 to Excel error when attempting to write a cell of UUID type. A simple example is shown below.

from openpyxl import Workbook
import uuid

wb = Workbook(guess_types=True)
ws = wb.active

ws['A1'] = uuid.uuid4()

wb.save('test.xlsx')

Had a quick peek at the openpyxl/cell/cell._bind_value() method - could there be an extra conditional there for UUIDs, or is there a preferred formatting hook to use?

Comments (6)

  1. CharlieC

    Well, as Excel has no idea of what a UUID is there is no mapping for it. Best thing is just to convert it to a string. I don't really see the need for adding another condition for this unlike NumPy types, which 2.4 supports. This is hotspot code that needs to run as fast as possible.

  2. CharlieC

    In theory, anything that has a string representation should be okay but we basically only handle mappings because of the two-way process and we want to provide feedback early.

  3. Log in to comment