473,549 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Win32 Excel Generation Slow

I am trying to create an excel document that displays a table of data.
It does exactly what I want but takes a long time. I am writing around
1000 rows and it takes around a second to do each row.

Is there a quicker way to write this? The reason I want excel is this
needs to read and manipulated by management.

The function I am using is:

def createExcel(dat a):
xlApp = Dispatch("Excel .Application")
wb = xlApp.Workbooks .Add()
xlApp.Visible = 1
ws = wb.Worksheets[0];

headers = ["Sales Rank", "UPC", "Descriptio n", "Stock", "Manifest
Stock", "Total Stock", "Week Sales", "Price", "Total Price", "Days Cover"]

column = 1
for each in headers:
xlApp.ActiveShe et.Cells(1, column).Value = each
column = column + 1

row = 1
for eachline in data:
xlApp.ActiveShe et.Cells(row, 1).Value = row
xlApp.ActiveShe et.Cells(row, 2).Value = eachline[0]
xlApp.ActiveShe et.Cells(row, 3).Value = eachline[1]
xlApp.ActiveShe et.Cells(row, 4).Value = eachline[2]
xlApp.ActiveShe et.Cells(row, 5).Value = eachline[3]
xlApp.ActiveShe et.Cells(row, 6).Value = eachline[4]
xlApp.ActiveShe et.Cells(row, 7).Value = eachline[5]
xlApp.ActiveShe et.Cells(row, 8).Value = eachline[6]
xlApp.ActiveShe et.Cells(row, 9).Value = eachline[7]
xlApp.ActiveShe et.Cells(row, 10).Value = eachline[8]
row = row + 1

Dec 1 '06 #1
2 3265

"Daniel Bowett" <da****@bowetts olutions.comwro te in message news:ma******** *************** *************** @python.org...
>I am trying to create an excel document that displays a table of data. It does exactly what I want but takes a long time. I am
writing around 1000 rows and it takes around a second to do each row.

Is there a quicker way to write this? The reason I want excel is this needs to read and manipulated by management.

The function I am using is:

def createExcel(dat a):
xlApp = Dispatch("Excel .Application")
wb = xlApp.Workbooks .Add()
xlApp.Visible = 1
ws = wb.Worksheets[0];

headers = ["Sales Rank", "UPC", "Descriptio n", "Stock", "Manifest Stock", "Total Stock", "Week Sales", "Price", "Total Price",
"Days Cover"]

column = 1
for each in headers:
xlApp.ActiveShe et.Cells(1, column).Value = each
column = column + 1

row = 1
for eachline in data:
xlApp.ActiveShe et.Cells(row, 1).Value = row
xlApp.ActiveShe et.Cells(row, 2).Value = eachline[0]
xlApp.ActiveShe et.Cells(row, 3).Value = eachline[1]
xlApp.ActiveShe et.Cells(row, 4).Value = eachline[2]
xlApp.ActiveShe et.Cells(row, 5).Value = eachline[3]
xlApp.ActiveShe et.Cells(row, 6).Value = eachline[4]
xlApp.ActiveShe et.Cells(row, 7).Value = eachline[5]
xlApp.ActiveShe et.Cells(row, 8).Value = eachline[6]
xlApp.ActiveShe et.Cells(row, 9).Value = eachline[7]
xlApp.ActiveShe et.Cells(row, 10).Value = eachline[8] row = row + 1
If you preformat the data including the row number, you can
insert it en masse using a Range object. This runs in just a
couple of seconds:

from win32com.client import Dispatch
data=[(x,'data1','dat a2','data3','da ta4','data5','d ata6','data7',' data8','data9') for x in xrange(1000)]
def createExcel(dat a):
xlApp = Dispatch("Excel .Application")
wb = xlApp.Workbooks .Add()
xlApp.Visible = 1
ws = wb.Worksheets[0];

headers = ["Sales Rank", "UPC", "Descriptio n", "Stock", "Manifest Stock", "Total Stock", "Week Sales", "Price", "Total
Price", "Days Cover"]

column = 1
for each in headers:
xlApp.ActiveShe et.Cells(1, column).Value = each
column = column + 1
xlApp.ActiveShe et.Range("A2:J1 001").Value=dat a

createExcel(dat a)
Roger

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 1 '06 #2
"Daniel Bowett" <da****@bowetts olutions.comwro te in message
news:ma******** *************** *************** @python.org...
>I am trying to create an excel document that displays a table of data. It
does exactly what I want but takes a long time. I am writing around 1000
rows and it takes around a second to do each row.

Is there a quicker way to write this? The reason I want excel is this
needs to read and manipulated by management.
Are there many many formulas in your worksheet? Try setting calculate to
manual, and turn off screenupdating while creating your rows. Then when
done, do a manual calculate, and turn auto calc and screenupdating back on.
(These are all open to the COM interface, although I don't recall the exact
function names.)

-- Paul
Dec 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8774
by: Jawahar Rajan | last post by:
All, I am using the ASP code below to save some data from a SQL Server database via ADO as an Excel spreadsheet strReportName = Request.QueryString("ReportName") If len(strReportName) > 0 then stResultsSql = Session.Contents("sSQL") Set objComm = CreateObject("ADODB.Command")
10
5567
by: Mark Day | last post by:
Hi All, I am using Access 2000 to generate over 40 Excel charts and pivot tables using early binding to the Excel 9.0 object library. I am finding that if I show the Excel object while processing the charts, the whole process completes in around 2 minutes. However if I hide the Excel object the same process takes around 27 minutes to...
3
41768
by: sandycat05 | last post by:
Hello all, I am a new Perl programmer. Below is the beginnings of a code that I am using to manipulate an Excel spreadsheet via Perl using win32::OLE. However, what I'd like to do is the following: instead of either opening a file or creating a new one, I'd like to do BOTH. I was thinking of creating a loop where I could basically say something...
3
2052
by: DS | last post by:
I try to generate a excel workbook using Excel object in ASP.NET program. When I implement the Excel workbook generation with out a thread it works fine. When I wrap all the excel generation process inside a method, and spin this method in a different thread I get the following error: "An unhandled exception of type...
8
36461
by: rssd | last post by:
can somebody help me. I'm trying to read some excel files but i'm always getting this error No type library matching "Microsoft Excel" found at D:\Genes_datasets\exp.pl line 4 Win32::OLE(0.16): GetOleTypeLibObject() Not a Win32::OLE::TypeLib object at C:/Perl/site/lib/Win32/OLE/Const.pm line 45. Died at D:\Genes_datasets\exp.pl line 6. i...
1
1593
by: =?Utf-8?B?S3VtYXIuQS5QLlA=?= | last post by:
I am using Excel automation for a report. Dim objExcel As New Excel.Application objExcel.DisplayAlerts = False Dim objWorkbooks As Excel.Workbooks = objExcel.Workbooks Dim objWorkbook As Excel.Workbook Dim objXLsheetUnits As Excel.Worksheet objWorkbook = objWorkbooks.Open(strPath) Then worksheets are populated with data from database and a...
1
6165
by: mohanprasadgutta | last post by:
Hi, I need help to open a password protected excel file in perl using Win32:OLE. when I tried to open file in normal way at the time of program execution it is prompting me to enter password. I am giving the script i used for opening excel file.. So i want to know how to provide password parameter while opening the file. use strict; use...
6
6463
by: poolboi | last post by:
hi all, i've got the following program that needs yr help: use Win32::OLE; # use existing instance if Excel is already running eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')}; die "Excel not installed" if $@; unless (defined $ex) {
1
4509
by: user1357 | last post by:
Hi all, i am trying to run the following code use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel';
0
7524
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6048
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5089
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.