March 12th, 2005, 02:17 PM
writting to Excel sheet
I am writting a script (in Python), that writes to an Excel sheet. I can use '\t' in my script to make tab deliminations. or '\n' to go to the next row.
My question is how to perform what I usually do with Alt+Enter when I want to be in the same cell but continue on the next line of the same cell. This as I said is done with Alt+Enter. But how would I code this in my script?
Thanks alot for your help.
March 12th, 2005, 03:28 PM
to do the "alt-enter" thing for a cell just put that cell in quotes and use \n still.
for example this:
would look like this in excel: view attached image.
Comments on this post
March 12th, 2005, 03:29 PM
Thanks alot Jacktasia, that's exactly what I wanted.
March 13th, 2005, 03:45 AM
What do you mean by 'write to an excel sheet'?
* Are you creating a tab-delimited file that is then loaded into excel?
* Are you sending keystrokes to an instance of excel through the Windows API?
* Are you using COM to control Excel?
If you just want to create a data file that can be read by Excel then I suggest using CSV. Python has a CSV module as part of its standard library, so is a quick and easy solution.
If you want more control over Excel then COM is the way to go. This will allow you to reference cells by coordinates, change the format of cells, and do pretty much anything you can do through the Excel GUI. The excellent book "Python Programming on Win32" by Mark Hammond and Andy Robinson has a chapter on controlling Excel through Python, including a module to make the whole process easier.
Sending keystrokes to an application is fragile at best, and should be avoided.
Dave - The Developers' Coach