Copying values from one spreadsheet to another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alagalah
    New Member
    • Feb 2009
    • 3

    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
  • MojaveKid
    New Member
    • Sep 2007
    • 9

    #2
    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('Exce l.Application')
    xlBook = xlApp.Workbooks .Open("file.xls ")

    sheet1 = xlBook.Workshee ts["sheet 1"]
    sheet2 = xlBook.Workshee ts["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(in dex,col).Value = sheet1.Cells(in dex,col).Value

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

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

    ...hope this helps

    Comment

    Working...