アプリ版:「スタンプのみでお礼する」機能のリリースについて

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

A 回答 (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
    • good
    • 0
この回答へのお礼

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

お礼日時:2006/07/07 16:55

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています