• 締切済み

VB.NETで、EXCELの右寄せ

VB.NETで、EXCELのセルに貼り付けたいのです。 .SetValue(rowIndex2, 3, "ABC") と、しました。これを右寄せにするには どうすれば良いのでしょうか? 宜しくお願い致します。

みんなの回答

回答No.1

お世話になります。 質問者さんの > VB.NETで、EXCELのセルに貼り付けたいのです。 > .SetValue(rowIndex2, 3, "ABC") この文章が、 VisualBasic のどのバージョンと Excel のどのバージョンで どういった方法でやっているのか、 何に対して SetValue メソッドを実行しているのか さっぱり解りませんが、 COM を使った方法だと、こんな感じです。 (VB 2005、Excel 2003) Imports Microsoft.Office.Interop Public Class Form1   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click     Dim xlApplication As New Excel.Application()     Dim xlBooks As Excel.Workbooks     xlBooks = xlApplication.Workbooks     Dim xlBook As Excel.Workbook = xlBooks.Add()     Dim xlSheets As Excel.Sheets = xlBook.Worksheets     Dim xlSheet As Excel.Worksheet = DirectCast(xlSheets.Item(1), Excel.Worksheet)     Dim xlCells As Excel.Range = xlSheet.Cells     Dim xlRange As Excel.Range     xlRange = DirectCast(xlCells(1, 2), Excel.Range)     xlRange.Value = "ABC"     ' 右寄せ     xlRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight     xlApplication.Visible = True     System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)     System.Runtime.InteropServices.Marshal.ReleaseComObject(xlCells)     System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)     System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets)     System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)     System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks)     System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApplication)   End Sub End Class

m-toshi
質問者

お礼

お返事が遅くなり申し訳ございません。 なんとか、できました。 ありがとうございました。 今後ともよろしくお願い致します。

すると、全ての回答が全文表示されます。

関連するQ&A