Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
How do I wrap and align text in an excel work sheet using vb.net?
Posted 13-Jul-10 3:14am
Edited 13-Jul-10 3:37am
Johnny J.112.9K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here is one i made earlier, for a similiar question asked in the VB forums only a few weeks ago;
 
    Private Sub doSomething()
 
        Dim xlApp As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application()
        Dim xlWk As Microsoft.Office.Interop.Excel.Workbook = xlApp.Workbooks.Add()
        Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet = xlWk.Worksheets(1)
        xlApp.Visible = True
 
        xlSheet.Range("A1").Value = "Some Text Value on 1 line"
 
        xlSheet.Range("A5").Value = "Some text value on" + vbCrLf + "2 lines"
 
        xlSheet.Columns().AutoFit()
        xlSheet.Rows().AutoFit()
 
        xlSheet.Range("B10").Value = "Some text aligned to the center"
        xlSheet.Range("B10").ColumnWidth = 120
        xlSheet.Range("B10").CurrentRegion.HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter
 
    End Sub
 
NOTE: there are other HorizontalAlignment constants available in the object model,e.g. HorizontalAlignment.Left (.Right) (.Center) but these do not work, you must use the one shown above.
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

xlBottom = -4107
xlCenter = -4108
xlJustify = -4130
xlLeft = -4131
xlRight = -4152
xlTop = -4160
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,935
1 OriginalGriff 6,987
2 CPallini 5,845
3 George Jonsson 4,015
4 Gihan Liyanage 3,266


Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 31 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100