By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

Copying values from one spreadsheet to another

P: 3
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
Share this Question
Share on Google+
1 Reply


P: 9
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.