comtypes
comtypes copied to clipboard
List of 1-tuple not passed to Excel as column array
The following code fails, and I would expect it to fill the "A" column with the values 0-9. Instead, it blanks the cell values.
import comtypes.client as cc
xl = cc.CreateObject("Excel.Application")
xl.Visible = True
xl.Workbooks.Add()
sheet = xl.ActiveSheet
# Doesn't work as expected
sheet.Range("A1:A10").Value[:] = zip(range(10))
# Does work as expected
sheet.Range("A1:A10").Value[:] = np.array(zip(range(10)))
In the first case, the VARIANT type is identified as VT_ARRAY | VT_VARIANT. In the second it is identified as VT_ARRAY | VT_I4. In both cases the array comes back as a tuple of 1-tuples.