Pywin32: How to import data into Excel?
Duncan Booth
duncan.booth at invalid.invalid
Tue Nov 8 07:59:55 EST 2005
Tim Golden wrote:
> [Dmytro Lesnyak]
>> I need to import some big data into Excel from my
>> Python script. I have TXT file (~7,5 Mb). I'm using
>> Pywin32 library for that, but if I first try to read
>> the TXT file and then save the values one by one like
>> xlBook.Sheets(sheet_name).Cells(i,j).Value = value_from_TXT_file
>> it takes about 10 hours to process whole data
>
> A few suggestions:
>
> + When trying to automate anything in Excel, it's
> usually illuminating to record a macro which does
> what you want, and then to translate that VBA code
> into Python.
>
Another suggestion: when automating Excel, turn off the automatic
recalculation (set Application.Calculation=xlManual) and then turn it back
on again when you have finished.
If you don't do this, Excel will attempt to recalculate the sheet after
every update to a cell. Even if you don't have any formulae referencing the
cells you change it still makes a big difference.
More information about the Python-list
mailing list