使用VB.Net在Excel工作表中换行 [英] Wrap text in Excel sheet using VB.Net
本文介绍了使用VB.Net在Excel工作表中换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用vb.net在Excel工作表中包装和对齐文本?
How do I wrap and align text in an excel work sheet using vb.net?
推荐答案
以下是我先前提出的一个类似的问题VB论坛仅在几周前;
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
注意:在对象模型中还有其他HorizontalAlignment常量可用,例如HorizontalAlignment.Left (.Right) (.Center)
,但是这些命令不起作用,您必须使用上面显示的那个.
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.
xlBottom = -4107
xlCenter = -4108
xlJustify = -4130
xlLeft = -4131
xlRight = -4152
xlTop = -4160
这篇关于使用VB.Net在Excel工作表中换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文