none
Changing width of Excel Column In Visual Basic RRS feed

  • Question

  • I am  using excel to store data entered into my program. It is pretty nice but it is a little cramped when looking at all of the data. If the columns were just a little bigger it would make everything fit perfectly. Is there an easy way to do this in visual basic rather than have my users manually go into the file and change the width of each column?

    I also would like to center data in the columns.... Is it possible to do this as well in visual basic?

    • Moved by Youjun Tang Thursday, August 20, 2015 8:03 AM more appropriate
    Wednesday, August 19, 2015 3:15 PM

Answers

  • this is c# but it should be similar in VB

    assuming you are using the range object and Excel Interop this is what I would do
    thisRange.ColumnWidth = 30;

    and some other stuff you may find interesting

    thisRange.Font.Size = 10;

    thisRange.NumberFormat = "#0.0%";

    thisRange.HorizontalAlignment = Excel.Constants.xlRight;


    jnc

    Wednesday, August 19, 2015 6:29 PM

All replies

  • this is c# but it should be similar in VB

    assuming you are using the range object and Excel Interop this is what I would do
    thisRange.ColumnWidth = 30;

    and some other stuff you may find interesting

    thisRange.Font.Size = 10;

    thisRange.NumberFormat = "#0.0%";

    thisRange.HorizontalAlignment = Excel.Constants.xlRight;


    jnc

    Wednesday, August 19, 2015 6:29 PM
  • Hi Brettman21,

    As your issue is related to Excel development, I'll move the post to Excel forum for help.

    Regards,
    Youjun Tang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 20, 2015 8:02 AM