469,323 Members | 1,447 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

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 6288
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.