A1 参照形式によるセルの指定

Cellクラスで、A1,B1のようにA1参照形式でセル指定を行う。

書式1 Public Cell(ByVal cell As String)
書式2 Public Cell(ByVal cell As String, ByVal cx As Integer, ByVal cy As Integer)


セルの値を取得するサンプル

ExcelFile左のExcelファイルのセル値を取得します

Dim xlsCr As New ExcelCreator.XlsCreator
'ExcelFileを開く
If xlsCr.ReadBook("c:\セル設定.xls") > -1 Then

	'1番目のシートを操作対象とする
    xlsCr.SheetNo = 0

    '文字列を取得
    Dim strA1 As String = xlsCr.Cell("A1").Str
    '整数を取得
    Dim intA2 As Integer = xlsCr.Cell("A2").Long
    '実数を取得
    Dim dblA3 As Double = xlsCr.Cell("A3").Double

    'ExcelFileを閉じる
     xlsCr.CloseBook(False)

     MessageBox.Show("A1 = " & strA1 & vbCrLf & _
                     "A2 = " & intA2.ToString & vbCrLf & _
                     "A3 = " & dblA3.ToString & vbCrLf & _
					 "A1 参照形式によるセルの指定")

End If
Dim xlsCr As New ExcelCreator.XlsCreator
'ExcelFileを開く
If xlsCr.ReadBook("c:\セル設定.xls") > -1 Then

	'1番目のシートを操作対象とする
    xlsCr.SheetNo = 0

    '文字列を取得
    Dim strA1 As String = xlsCr.Cell("A1", 0, 0).Str
    '整数を取得
    Dim intA2 As Integer = xlsCr.Cell("A1", 0, 1).Long
    '実数を取得
    Dim dblA3 As Double = xlsCr.Cell("A1", 0, 2).Double

    '閉じる
    xlsCr.CloseBook(False)
	MessageBox.Show("A1 = " & strA1 & vbCrLf & _
                    "A2 = " & intA2.ToString & vbCrLf & _
                    "A3 = " & dblA3.ToString, _
                    "A1 参照形式によるセルの指定")
End If
xlsCr.Dispose()

実行結果は以下の通り
結果

セルの値を設定するサンプル

実行前 実行後
ExcelFile ExcelFile 結果
Dim xlsCr As New ExcelCreator.XlsCreator
'ExcelFileを開く
If xlsCr.OpenBook("c:\セル設定.xls", "") > -1 Then

   	'1番目のシートを選択(操作対象とする)
    xlsCr.SheetNo = 0

    '文字列をセット
    xlsCr.Cell("B1").Str = "JeffBeckも好きだ"
    '整数をセット
    xlsCr.Cell("B2").Long = 150000
    '実数をセット
    xlsCr.Cell("B3").Double = 135500000.123

    '保存して閉じる
    xlsCr.CloseBook(True)

End If
xlsCr.Dispose()

履歴

2011/09/24
公開
Loading