#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    330
    Rep Power
    15

    writting to Excel sheet


    Hello,

    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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
    to do the "alt-enter" thing for a cell just put that cell in quotes and use \n still.

    for example this:

    Code:
    '1\t2\t3\t4\t5\t6\t"7\n77"\n'
    would look like this in excel: view attached image.

    Comments on this post

    • sam_kh918 agrees : It was helpful
    Attached Images
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    330
    Rep Power
    15
    Thanks alot Jacktasia, that's exactly what I wanted.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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

IMN logo majestic logo threadwatch logo seochat tools logo