我一直在努力调整Excel单元格文本值。我尝试过更常见的xlLeft
,xlRight
,但这似乎不起作用。错误是xlLeft
未声明。我正在使用Visual Studios并使用VB创建一个aspx页面。
以下是我的代码示例:
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
'Start a new workbook in Excel
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
'Add data to cells of the first worksheet in the new workbook
oSheet = oBook.Worksheets(1)
oSheet.Range("A1:E1").Merge()
oSheet.Range("A1").Value = "Hello"
oSheet.Range("A2:E2").Merge()
oSheet.Range("A2").Value = "There "
oSheet.Range("A1:A4").Font.Bold = True
oSheet.Range("A1").HorizontalAlignment = -4131
答案 0 :(得分:20)
VerticalAlignment
:
Top: -4160
Center: -4108
Bottom: -4107
HorizontalAlignment
:
Left: -4131
Center: -4108
Right: -4152
答案 1 :(得分:5)
您可以使用xlLeft:
Imports Microsoft.Office.Interop.Excel
...
oSheet.Range("A1").HorizontalAlignment = Constants.xlLeft
答案 2 :(得分:1)
xcl.Range("J:J").EntireColumn.HorizontalAlignment = _
Microsoft.Office.Interop.Excel.Constants.xlCenter