チェックボックス型セルの値を int 型で処理する(WorkBook/Sheet)
対象製品
El Tabelle for .NET 3.0J
詳細
C# でチェックボックス型セルを使用するとき、値を直接 int 型に変換すると例外が発生します。
[C#]
これは、チェックボックス型セルは null を許容するため、値型の int 型に変換できないことが原因です。
値を int 型に変換するには、次のように Object 型と string 型を経由します。
[C#]
なお、Visual Basic では、チェックボックス型セルの値を直接 int 型に変換して使用できます。
[Visual Basic]
[C#]
GrapeCity.Win.ElTabelle.Editors.CheckBoxEditor objCheckBoxEditor =
new GrapeCity.Win.ElTabelle.Editors.CheckBoxEditor();
sheet1[0, 0].Editor = objCheckBoxEditor;
int value = (int)sheet1[0, 0].Value; // <-例外が発生する
new GrapeCity.Win.ElTabelle.Editors.CheckBoxEditor();
sheet1[0, 0].Editor = objCheckBoxEditor;
int value = (int)sheet1[0, 0].Value; // <-例外が発生する
これは、チェックボックス型セルは null を許容するため、値型の int 型に変換できないことが原因です。
値を int 型に変換するには、次のように Object 型と string 型を経由します。
[C#]
GrapeCity.Win.ElTabelle.Editors.CheckBoxEditor objCheckBoxEditor =
new GrapeCity.Win.ElTabelle.Editors.CheckBoxEditor();
sheet1[0, 0].Editor = objCheckBoxEditor;
int value = 0;
if (sheet1[0, 0].Value != null)
{
value = int.Parse(sheet1[0, 0].Value.ToString());
}
Console.WriteLine(value);
new GrapeCity.Win.ElTabelle.Editors.CheckBoxEditor();
sheet1[0, 0].Editor = objCheckBoxEditor;
int value = 0;
if (sheet1[0, 0].Value != null)
{
value = int.Parse(sheet1[0, 0].Value.ToString());
}
Console.WriteLine(value);
なお、Visual Basic では、チェックボックス型セルの値を直接 int 型に変換して使用できます。
[Visual Basic]
Dim objCheckBoxEditor As GrapeCity.Win.ElTabelle.Editors.CheckBoxEditor = _
new GrapeCity.Win.ElTabelle.Editors.CheckBoxEditor()
Sheet1(0, 0).Editor = objCheckBoxEditor
Dim value As Integer = CType(Sheet1(0, 0).Value, Integer)
Console.WriteLine(value)
new GrapeCity.Win.ElTabelle.Editors.CheckBoxEditor()
Sheet1(0, 0).Editor = objCheckBoxEditor
Dim value As Integer = CType(Sheet1(0, 0).Value, Integer)
Console.WriteLine(value)
関連情報
キーワード
HowTo
この文書は、以前は次のFAQ IDで公開されていました : 7643