Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • adjust column width in Excel - putexcel

    Hello everyone,

    I would like to increase the column width in Excel when exporting results via "putexcel". I haven't found this in the options.

    A little piece of code:
    Code:
    sysuse auto, clear
    
    rename foreign foreign_has_a_long_name
    
    reg price mpg weight foreign_has_a_long_name
    mat res = r(table)'
    mat res = res[1...,1..4]
    matlist res
    
    putexcel set testfile.xlsx, sheet("T1") replace
    putexcel A1=matrix(res), names
    Any help would be appreciated - many thanks in advance!

    Boris


  • #2
    Hello Boris,

    I'm not an expert at putexcel, but as you've noted, I'm not sure if you can change the column with in Excel using putexcel.

    If you're comfortable with or willing to learn Mata, I believe you should be able to change the column width using Mata's xl() class.

    Search
    Code:
    help [M-5] xl()
    for more information.

    Best,
    Roger

    Comment


    • #3
      Hi Roger,

      Thanks for the pointer.
      You're right: xl() can be used to adjust the column width.

      Comment


      • #4
        Hello,

        does anyone actually managed to adjust the column width trough putexcel?

        An help would be greatly appreciated.
        Demetrio

        Comment


        • #5
          Hi, my sense is that you could use a different format of the values in the matrix to change the width of the excel. For example, %9.2f is wider than %6.2f. I hope it could help.

          Comment


          • #6
            Originally posted by Long Hong View Post
            Hi, my sense is that you could use a different format of the values in the matrix to change the width of the excel. For example, %9.2f is wider than %6.2f. I hope it could help.
            Unfortunately in this way you are only changhing the width of the stata viewer but once I export in excel the columns will keep the default excel width.

            Any other suggestion?

            Comment


            • #7
              Originally posted by Demetrio Guzzardi View Post
              Hello,

              does anyone actually managed to adjust the column width trough putexcel?

              An help would be greatly appreciated.
              Demetrio
              Hi Demetrio,

              I can't see either how you can change the width in Excel from stata. I'm pretty sure it's impossible for now. However, I think that merging cells will do the job.

              Comment


              • #8
                I had the same issue. Mata is the solution. Here is the example that I found useful.

                https://opensdp.github.io/human-capi...at_excel_cells

                Comment

                Working...
                X