日付型セルの値が空のとき、今日の日付を使用するには?
対象製品
El Tabelle for .NET 3.0J
詳細
日付型セルで今日の日付を使用するには、EnterEdit イベントでセルの値をチェックし、空の場合に今日の日付を設定します。
WorkBook/Sheet の場合、次のようにコーディングします。
[Visual Basic]
[C#]
MultiRowSheet の場合、次のようにコーディングします。
[Visual Basic]
[C#]
なお、日付型セルの値を再び空に設定するには、セルの値を null (Visual Basic では Nothing)に設定します。
[Visual Basic]
[C#]
WorkBook/Sheet の場合、次のようにコーディングします。
[Visual Basic]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Sheet1(0, 0).Editor = New GrapeCity.Win.ElTabelle.Editors.DateEditor
End Sub
Private Sub Sheet1_EnterEdit(ByVal sender As Object, ByVal e As GrapeCity.Win.ElTabelle.EnterEditEventArgs) Handles Sheet1.EnterEdit
If TypeOf Sheet1.ActiveCell.Editor Is GrapeCity.Win.ElTabelle.Editors.DateEditor Then
If Sheet1.ActiveCell.Value Is Nothing Then
Sheet1.ActiveCell.Value = Date.Now
End If
End If
End Sub
Sheet1(0, 0).Editor = New GrapeCity.Win.ElTabelle.Editors.DateEditor
End Sub
Private Sub Sheet1_EnterEdit(ByVal sender As Object, ByVal e As GrapeCity.Win.ElTabelle.EnterEditEventArgs) Handles Sheet1.EnterEdit
If TypeOf Sheet1.ActiveCell.Editor Is GrapeCity.Win.ElTabelle.Editors.DateEditor Then
If Sheet1.ActiveCell.Value Is Nothing Then
Sheet1.ActiveCell.Value = Date.Now
End If
End If
End Sub
[C#]
private void Form1_Load(object sender, System.EventArgs e)
{
sheet1[0, 0].Editor = new GrapeCity.Win.ElTabelle.Editors.DateEditor();
}
private void sheet1_EnterEdit(object sender, GrapeCity.Win.ElTabelle.EnterEditEventArgs e)
{
if((sheet1.ActiveCell.Editor as
GrapeCity.Win.ElTabelle.Editors.DateEditor) != null)
{
if(sheet1.ActiveCell.Value == null)
{
sheet1.ActiveCell.Value = System.DateTime.Now;
}
}
}
{
sheet1[0, 0].Editor = new GrapeCity.Win.ElTabelle.Editors.DateEditor();
}
private void sheet1_EnterEdit(object sender, GrapeCity.Win.ElTabelle.EnterEditEventArgs e)
{
if((sheet1.ActiveCell.Editor as
GrapeCity.Win.ElTabelle.Editors.DateEditor) != null)
{
if(sheet1.ActiveCell.Value == null)
{
sheet1.ActiveCell.Value = System.DateTime.Now;
}
}
}
MultiRowSheet の場合、次のようにコーディングします。
[Visual Basic]
'Templateデザイナを使用して、予め日付型セルを作成します
Private Sub MultiRowSheet1_EnterEdit(ByVal sender As Object, ByVal e As GrapeCity.Win.ElTabelle.MEnterEditEventArgs) Handles MultiRowSheet1.EnterEdit
If TypeOf MultiRowSheet1.ActiveCell.Editor Is GrapeCity.Win.ElTabelle.Editors.DateEditor Then
If MultiRowSheet1.ActiveCell.Value Is Nothing Then
MultiRowSheet1.ActiveCell.Value = Date.Now
End If
End If
End Sub
Private Sub MultiRowSheet1_EnterEdit(ByVal sender As Object, ByVal e As GrapeCity.Win.ElTabelle.MEnterEditEventArgs) Handles MultiRowSheet1.EnterEdit
If TypeOf MultiRowSheet1.ActiveCell.Editor Is GrapeCity.Win.ElTabelle.Editors.DateEditor Then
If MultiRowSheet1.ActiveCell.Value Is Nothing Then
MultiRowSheet1.ActiveCell.Value = Date.Now
End If
End If
End Sub
[C#]
//Templateデザイナを使用して、予め日付型セルを作成します
private void multiRowSheet1_EnterEdit(object sender, GrapeCity.Win.ElTabelle.MEnterEditEventArgs e)
{
if((multiRowSheet1.ActiveCell.Editor as
GrapeCity.Win.ElTabelle.Editors.DateEditor) != null)
{
if(multiRowSheet1.ActiveCell.Value == null)
{
multiRowSheet1.ActiveCell.Value = System.DateTime.Now;
}
}
}
private void multiRowSheet1_EnterEdit(object sender, GrapeCity.Win.ElTabelle.MEnterEditEventArgs e)
{
if((multiRowSheet1.ActiveCell.Editor as
GrapeCity.Win.ElTabelle.Editors.DateEditor) != null)
{
if(multiRowSheet1.ActiveCell.Value == null)
{
multiRowSheet1.ActiveCell.Value = System.DateTime.Now;
}
}
}
なお、日付型セルの値を再び空に設定するには、セルの値を null (Visual Basic では Nothing)に設定します。
[Visual Basic]
Sheet1.ActiveCell.Value = Nothing
または
MultiRowSheet1.ActiveCell.Value = Nothing
または
MultiRowSheet1.ActiveCell.Value = Nothing
[C#]
sheet1.ActiveCell.Value = null;
または
multiRowSheet1.ActiveCell.Value = null;
または
multiRowSheet1.ActiveCell.Value = null;
キーワード
HowTo
この文書は、以前は次のFAQ IDで公開されていました : 7559