[Tutor] Looping, and Win32com.client

Eduardo Vieira eduardo.susan at gmail.com
Fri Dec 19 17:23:53 CET 2008


Thank you, now it worked! I made these changes to my code:
for ficheiro in os.listdir(folder):
    file = os.path.join(folder, ficheiro) #added this
    if ficheiro.endswith('.xls'):
        wb = xl.Workbooks.Open(file, 2) # changed this

On Fri, Dec 19, 2008 at 8:57 AM, Tim Golden <mail at timgolden.me.uk> wrote:
> Eduardo Vieira wrote:
>>
>> Hello, this is my first post in this list and I'm not a programmer,
>> but am enjoying learning python.
>> I'm trying to make a script to add worksheets to excel files:
>> I managed to implement this code:
>>
>> import os
>> folder = 'C:\\Personal\\oldxlsformat\\'
>> from win32com.client import Dispatch
>> xl = Dispatch('Excel.Application')
>> xl.Application.AskToUpdateLinks = "False"
>> for ficheiro in os.listdir(folder):
>
>
> os.listdir returns a list of files relative to
> the directory in question. (Try it at the
> interpreter and see). Excel requires, pretty
> much, a list of absolute filenames. So try
> using something like os.path.join (folder, ficheiro)
> when opening in Excel.
>
> TJG
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list