comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

List of 1-tuple not passed to Excel as column array

Open cfarrow opened this issue 11 years ago • 1 comments

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)))

cfarrow avatar Apr 08 '14 21:04 cfarrow

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.

cfarrow avatar Apr 09 '14 02:04 cfarrow