1

I want to write to an open excel sheet. I did this:

import win32com.client

app = win32com.client.GetActiveObject("Excel.Application")

but got errors:

AttributeError: module 'win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9' 
  has no attribute 'CLSIDToClassMap'

Can someone please help?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • Does this answer your question? [python-win32com excel com model started generating errors](https://stackoverflow.com/questions/52889704/python-win32com-excel-com-model-started-generating-errors) – Julienm Apr 03 '21 at 13:15

2 Answers2

0

Try to use:

import win32com.client
app = win32com.client.gencache.EnsureDispatch('Excel.Application')
Peter Ark
  • 244
  • 1
  • 6
0

I suggest using pandas library for this:

e.g.

import pandas as pd

df1 = pd.DataFrame([['a', 'b'], ['c', 'd']],
                   index=['row 1', 'row 2'],
                   columns=['col 1', 'col 2'])
df1.to_excel("output.xlsx") 
tohtohro
  • 1
  • 2