Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8354955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:42:56+00:00 2026-06-09T09:42:56+00:00

I am currently trying to write a large amount of data to an excel

  • 0

I am currently trying to write a large amount of data to an excel spreadsheet using the pywin32 libraries. As a simple example of the problem that I am facing take the following code to generate a 1000 cell x 1000 cell multiplication table.

import win32com.client
from win32com.client import constants as c

xl = win32com.client.gencache.EnsureDispatch("Excel.Application")                             
xl.Visible = True
Workbook = xl.Workbooks.Add()
Sheets = Workbook.Sheets

tableSize = 1000

for i in range(tableSize):
    for j in range(tableSize):
        Sheets(1).Cells(i+1, j+1).Value = i*j

For small values this works. However, for larger values the python program eventually crashes with the error:

Traceback (most recent call last):
  File ".\Example.py", line 16, in <module>
    Sheets(1).Cells(i+1, j+1).Value = i*j
  File "C:\PYTHON27\lib\site-packages\win32com\client\__init__.py", line 474, in __setattr__
    self._oleobj_.Invoke(*(args + (value,) + defArgs)) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146777998), None)

I’ve already admitted defeat due to the fact that this is significantly slower than xlwt but I am still curious as to what is happening to cause this error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:42:57+00:00Added an answer on June 9, 2026 at 9:42 am

    I figured it out.

    The error only occurred when the user interacted with excel window while code was running. By adding xl.Interactive = False before doing any work with excel this can be avoided. If this is added before the application is visible there is no chance of any interaction.

    So the final code is:

    import win32com.client
    from win32com.client import constants as c
    
    xl = win32com.client.gencache.EnsureDispatch("Excel.Application")
    xl.Interactive = False
    xl.Visible = True
    Workbook = xl.Workbooks.Add()
    Sheets = Workbook.Sheets
    
    Sheets(1).Cells(1,2).Value = "Test"
    print Sheets(1).Cells(1,2).Value
    
    tableSize = 1000
    
    for i in range(tableSize):
        for j in range(tableSize):
                Sheets(1).Cells(i+1, j+1).Value = i*j
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to write a script that will connect to a site using
I am currently trying to write some code that will accept some FTP details,
I am currently trying to write an addin for PowerPoint that whenever any PowerPoint
currently I am trying to write to an 20x4 LCD Dot-Matrix Module using Perle's
Currently am trying to read and write mp3 tags without using any external modules
The idea of my simple program that I've been trying to write is to
I'm quicksorting over a very large amount of data, and for fun am trying
I am currently trying to write a program to store data about people into
I have a few Oracle procedures that generate/return a large amount of data that
I'm currently running into a bit of a problem. I'm trying to write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.