【セル型】 日本語の曜日設定を行ったカレンダー型セルで、曜日表記が英語になったり意図しない検証エラーが発生する
対象製品
SPREAD for ASP.NET 7.0J
状況
修正済み
詳細
日本語の曜日設定を行ったカレンダー型セルで、サーバー側で設定した日付の曜日表記が英語になったり、正しく入力された日付が検証エラーになる現象が発生します。
【現象1】
DateCalendarCellType型セルで曜日を日本語で表示すると検証でエラーになる。
【再現手順】
1.新規WebフォームにSPREAD、ボタン1、ボタン2、ToolkitScriptManagerをひとつずつ配置する
2.Webフォームに下記の再現コードを貼り付け、Web フォームを起動する
3.セル(0,0)を編集状態にし、カレンダーを表示して任意の日付を選択する
4.ボタン1を押下する
--- セル(0,0)の入力内容が赤字表記となり、検証エラーとして表示される
【現象2】
DateCalendarCellType型セルでValueプロパティにDateTime構造体を設定すると、曜日が英語で表示される。
【再現手順】
1.新規WebフォームにSPREAD、ボタン1、ボタン2、ToolkitScriptManagerをひとつずつ配置する
2.Webフォームに下記の再現コードを貼り付け、Web フォームを起動する
3.ボタン2を押下する
--- セル(0,0)の入力内容について、曜日が英語となる
【再現コード】
------------------------------------
Webフォームクラス
------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Return
End If
Dim calendarCellYmd As New FarPoint.Web.Spread.Extender.DateCalendarCellType()
calendarCellYmd.DateFormat = "yyyy/MM/dd(ddd)"
calendarCellYmd.ShowEditor = False
calendarCellYmd.TodaysDateFormat = "yyyy年MM月dd日"
calendarCellYmd.DaysModeTitleFormat = "yyyy年MM月"
FpSpread1.Sheets(0).Cells(0, 0).CellType = calendarCellYmd
End Sub
Protected Overrides Sub InitializeCulture()
' アプリケーションのカルチャの変更
Dim cInfo As New System.Globalization.CultureInfo("ja-JP")
Dim gc As New System.Globalization.GregorianCalendar()
cInfo.DateTimeFormat.Calendar = gc
System.Threading.Thread.CurrentThread.CurrentCulture = cInfo
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
FpSpread1.SaveChanges()
End Sub
Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
FpSpread1.Sheets(0).Cells(0, 0).Value = DateTime.Today
End Sub
【現象1】
DateCalendarCellType型セルで曜日を日本語で表示すると検証でエラーになる。
【再現手順】
1.新規WebフォームにSPREAD、ボタン1、ボタン2、ToolkitScriptManagerをひとつずつ配置する
2.Webフォームに下記の再現コードを貼り付け、Web フォームを起動する
3.セル(0,0)を編集状態にし、カレンダーを表示して任意の日付を選択する
4.ボタン1を押下する
--- セル(0,0)の入力内容が赤字表記となり、検証エラーとして表示される
【現象2】
DateCalendarCellType型セルでValueプロパティにDateTime構造体を設定すると、曜日が英語で表示される。
【再現手順】
1.新規WebフォームにSPREAD、ボタン1、ボタン2、ToolkitScriptManagerをひとつずつ配置する
2.Webフォームに下記の再現コードを貼り付け、Web フォームを起動する
3.ボタン2を押下する
--- セル(0,0)の入力内容について、曜日が英語となる
【再現コード】
------------------------------------
Webフォームクラス
------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Return
End If
Dim calendarCellYmd As New FarPoint.Web.Spread.Extender.DateCalendarCellType()
calendarCellYmd.DateFormat = "yyyy/MM/dd(ddd)"
calendarCellYmd.ShowEditor = False
calendarCellYmd.TodaysDateFormat = "yyyy年MM月dd日"
calendarCellYmd.DaysModeTitleFormat = "yyyy年MM月"
FpSpread1.Sheets(0).Cells(0, 0).CellType = calendarCellYmd
End Sub
Protected Overrides Sub InitializeCulture()
' アプリケーションのカルチャの変更
Dim cInfo As New System.Globalization.CultureInfo("ja-JP")
Dim gc As New System.Globalization.GregorianCalendar()
cInfo.DateTimeFormat.Calendar = gc
System.Threading.Thread.CurrentThread.CurrentCulture = cInfo
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
FpSpread1.SaveChanges()
End Sub
Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
FpSpread1.Sheets(0).Cells(0, 0).Value = DateTime.Today
End Sub
回避方法
Service Pack 3(v7.0.4017.2010)で修正済み。
Service Pack 3(v7.0.4017.2010)より前のバージョンでは次の回避方法が有効です。
------------------------------------------
カレンダー型セルに代わってカスタムセルを使用することで回避することが可能です。
public class MyDateCalendarCellType : DateCalendarCellType
{
public override string ValidateEditorValue(object value)
{
if (value == null || string.Empty.Equals(value))
return null;
DateTime dt;
string errorMessage = base.ValidateEditorValue("error");
if (!DateTime.TryParseExact((string)value, DateFormat, System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dt))
{
return errorMessage;
}
return null;
}
public override object Parse(string s)
{
if (s == null || s.Length == 0) return null;
DateTime dt;
if (DateTime.TryParseExact(s, DateFormat, System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dt))
return dt;
return null;
}
public override string Format(object o)
{
if (o == null)
return "";
if (o is DateTime)
return ((DateTime)o).ToString(DateFormat, System.Globalization.CultureInfo.CurrentCulture);
else if (o is TimeSpan)
return ((TimeSpan)o).ToString();
else if (o is string && ((string)o).Length > 0)
{
try
{
double v;
if (!double.TryParse((string)o, out v)) return (string)o;
DateTime dt = DateTime.FromOADate(v);
return dt.ToString(DateFormat, System.Globalization.CultureInfo.CurrentCulture);
}
catch
{
return (string)o;
}
}
else
{
try
{
base.Format(o);
}
catch (ArgumentException ae)
{
throw ae;
}
double dbl = 0.0;
try { dbl = Convert.ToDouble(o); }
catch
{
}
DateTime dt = DateTime.FromOADate(dbl);
return dt.ToString(DateFormat, System.Globalization.CultureInfo.CurrentCulture);
}
}
}
Service Pack 3(v7.0.4017.2010)より前のバージョンでは次の回避方法が有効です。
------------------------------------------
カレンダー型セルに代わってカスタムセルを使用することで回避することが可能です。
public class MyDateCalendarCellType : DateCalendarCellType
{
public override string ValidateEditorValue(object value)
{
if (value == null || string.Empty.Equals(value))
return null;
DateTime dt;
string errorMessage = base.ValidateEditorValue("error");
if (!DateTime.TryParseExact((string)value, DateFormat, System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dt))
{
return errorMessage;
}
return null;
}
public override object Parse(string s)
{
if (s == null || s.Length == 0) return null;
DateTime dt;
if (DateTime.TryParseExact(s, DateFormat, System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dt))
return dt;
return null;
}
public override string Format(object o)
{
if (o == null)
return "";
if (o is DateTime)
return ((DateTime)o).ToString(DateFormat, System.Globalization.CultureInfo.CurrentCulture);
else if (o is TimeSpan)
return ((TimeSpan)o).ToString();
else if (o is string && ((string)o).Length > 0)
{
try
{
double v;
if (!double.TryParse((string)o, out v)) return (string)o;
DateTime dt = DateTime.FromOADate(v);
return dt.ToString(DateFormat, System.Globalization.CultureInfo.CurrentCulture);
}
catch
{
return (string)o;
}
}
else
{
try
{
base.Format(o);
}
catch (ArgumentException ae)
{
throw ae;
}
double dbl = 0.0;
try { dbl = Convert.ToDouble(o); }
catch
{
}
DateTime dt = DateTime.FromOADate(dbl);
return dt.ToString(DateFormat, System.Globalization.CultureInfo.CurrentCulture);
}
}
}