Python-Excel: How to paste selected cells (range) to different location on the same sheet in Excel

zxo102 zxo102 at gmail.com
Thu Aug 4 01:51:44 EDT 2005


I found the solution for this. It needs to select a new location and
paste from "sh". Thank you for your reading this.

import win32com.client
xl=win32com.client.Dispatch("E­xcel.Application")
xl.Visible=1
wb = xl.Workbooks.Add( )
sh=wb.Worksheets(1)
sh.Cells(1,1).Value = "Hello World!"
sh.Cells(3,3).Value = "Hello World!"
sh.Range(sh.Cells(1,1),sh.Cell­s(3,3)).Select()
sh.Range(sh.Cells(1,1),sh.Cell­s(3,3)).Copy()
sh.Cells(4,1).Select()
sh.Paste() 


Ouyang




More information about the Python-list mailing list