472,114 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,114 software developers and data experts.

Copying values from one spreadsheet to another

Does anyone have an example of reading an Excel spreadsheet and iteratively copying the VALUES from each of the cells in each of the sheets over to a new spreadsheet?


TIA
Feb 21 '09 #1
1 6611
python and excel...uhum

first thing to do:
install the win32 extension for python (just search sourceforge for this)

now assume we have an excel file (file.xls) with 2 sheets : "sheet 1", "sheet 2"

#####################################
import win32com.client

xlApp = win32com.client.Dispatch('Excel.Application')
xlBook = xlApp.Workbooks.Open("file.xls")

sheet1 = xlBook.Worksheets["sheet 1"]
sheet2 = xlBook.Worksheets["sheet 2"]

# assume we are going to copy the first 200 rows of column 1

rows = 200
col = 1

index = 1
while index <= rows:
sheet2.Cells(index,col).Value = sheet1.Cells(index,col).Value

xlBook.Save(SaveChanges=0) #save the file
del xlApp #kill the excel application

#####################################

...hope this helps
Mar 2 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Nathan Sokalski | last post: by

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.