I'm handling an excel file using visual studio 2013, visual basic, windows Forms.
How to change the column width
of b to be 30?
I don't need to use autofit
, cause it make text small to fit in cell with it's default width.
xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
xlBook = xlApp.Workbooks.Open(FileName)
SheetReport = CType(xlBook.Sheets.Add(), Excel.Worksheet)
SheetReport.Name = "Report"
SheetReport.Range("B2").Value = "Agent Name"
' need resize column b
Left-click the mouse button in the header between the columns or rows that you selected and drag the mouse to the left and right for columns and up and down for the rows to adjust the size of all of the selected columns at once. That's it.
To increase the width of multiple consecutive columns, select the columns you want to change. Click the header boundary of any selected column and drag to the right, like in the picture below. To decrease the width, drag to the left.
Simply:
SheetReport.Range("B2").ColumnWidth = 30
To learn the code with Excel API I'll give you a trick you can use; just open a Excel Sheet, start recording a Macro, and then do the thing you want to do programatically. Then stop the recording and look for the code recorded of the macro.
It will contain the instructions in VBA to make it possible. With a little modification, that's what you need to do in VB.NET with the Excel API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With