【Excel】Excelファイルにエスポート時、倍精度型セルのDecimalDigits プロパティの設定が正しく出力されない場合がある
対象製品
SPREAD for .NET 2.5J Web Forms Edition
発生環境
動作保証環境と同様
状況
修正済み
詳細
DecimalDigits プロパティの設定が異なる倍精度型セルが2つあると、一方の倍精度型セルのDecimalDigits プロパティの設定がもう一方の倍精度型セルにも適用された状態でExcelファイルにエスポートされます。
【手順】
1.新規WebフォームにSPREADとButtonを配置します
2.下記サンプルコードをコピーし、アプリケーションを実行します
3.Buttonを押下してExcelファイルを作成します
4.作成されたExcelファイルのC列が小数点以下4桁で表示されます
【サンプルコード】
-------------------------
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 dct1 As FarPoint.Web.Spread.DoubleCellType = New FarPoint.Web.Spread.DoubleCellType
dct1.FixedPoint = True
dct1.DecimalDigits = 4
FpSpread1.ActiveSheetView.Columns(1).CellType = dct1
Dim dct2 As FarPoint.Web.Spread.DoubleCellType = New FarPoint.Web.Spread.DoubleCellType
dct2.FixedPoint = True
dct2.DecimalDigits = 1
FpSpread1.ActiveSheetView.Columns(2).CellType = dct2
FpSpread1.ActiveSheetView.Cells(0, 1).Value = 10.0123
FpSpread1.ActiveSheetView.Cells(0, 2).Value = 20.5
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pathname As String = HttpContext.Current.Server.MapPath(Request.ApplicationPath & "/")
FpSpread1.SaveExcel(pathname + "test.xls")
End Sub
【手順】
1.新規WebフォームにSPREADとButtonを配置します
2.下記サンプルコードをコピーし、アプリケーションを実行します
3.Buttonを押下してExcelファイルを作成します
4.作成されたExcelファイルのC列が小数点以下4桁で表示されます
【サンプルコード】
-------------------------
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 dct1 As FarPoint.Web.Spread.DoubleCellType = New FarPoint.Web.Spread.DoubleCellType
dct1.FixedPoint = True
dct1.DecimalDigits = 4
FpSpread1.ActiveSheetView.Columns(1).CellType = dct1
Dim dct2 As FarPoint.Web.Spread.DoubleCellType = New FarPoint.Web.Spread.DoubleCellType
dct2.FixedPoint = True
dct2.DecimalDigits = 1
FpSpread1.ActiveSheetView.Columns(2).CellType = dct2
FpSpread1.ActiveSheetView.Cells(0, 1).Value = 10.0123
FpSpread1.ActiveSheetView.Cells(0, 2).Value = 20.5
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pathname As String = HttpContext.Current.Server.MapPath(Request.ApplicationPath & "/")
FpSpread1.SaveExcel(pathname + "test.xls")
End Sub
回避方法
2008/08/27版で修正済み。
2008/08/27版より前のバージョンでは次の回避方法が有効です。
それぞれの倍精度型セルでNumberFormat プロパティで表示する小数点以下の桁数を設定してください。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Return
End If
Dim ninfo1 As Globalization.NumberFormatInfo = CType(Globalization.CultureInfo.CurrentCulture.NumberFormat.Clone(), Globalization.NumberFormatInfo)
Dim ninfo2 As Globalization.NumberFormatInfo = CType(Globalization.CultureInfo.CurrentCulture.NumberFormat.Clone(), Globalization.NumberFormatInfo)
ninfo1.NumberGroupSizes = New Int32() {3}
ninfo1.NumberDecimalDigits = 4
ninfo2.NumberGroupSizes = New Int32() {3}
ninfo2.NumberDecimalDigits = 1
Dim dct1 As FarPoint.Web.Spread.DoubleCellType = New FarPoint.Web.Spread.DoubleCellType
dct1.FixedPoint = True
dct1.DecimalDigits = 4
dct1.NumberFormat = ninfo1
FpSpread1.ActiveSheetView.Columns(1).CellType = dct1
Dim dct2 As FarPoint.Web.Spread.DoubleCellType = New FarPoint.Web.Spread.DoubleCellType
dct2.FixedPoint = True
dct2.DecimalDigits = 1
dct2.NumberFormat = ninfo2
FpSpread1.ActiveSheetView.Columns(2).CellType = dct2
FpSpread1.ActiveSheetView.Cells(0, 1).Value = 10.0123
FpSpread1.ActiveSheetView.Cells(0, 2).Value = 20.5
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pathname As String = HttpContext.Current.Server.MapPath(Request.ApplicationPath & "/")
FpSpread1.SaveExcel(pathname + "test.xls")
End Sub
2008/08/27版より前のバージョンでは次の回避方法が有効です。
それぞれの倍精度型セルでNumberFormat プロパティで表示する小数点以下の桁数を設定してください。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Return
End If
Dim ninfo1 As Globalization.NumberFormatInfo = CType(Globalization.CultureInfo.CurrentCulture.NumberFormat.Clone(), Globalization.NumberFormatInfo)
Dim ninfo2 As Globalization.NumberFormatInfo = CType(Globalization.CultureInfo.CurrentCulture.NumberFormat.Clone(), Globalization.NumberFormatInfo)
ninfo1.NumberGroupSizes = New Int32() {3}
ninfo1.NumberDecimalDigits = 4
ninfo2.NumberGroupSizes = New Int32() {3}
ninfo2.NumberDecimalDigits = 1
Dim dct1 As FarPoint.Web.Spread.DoubleCellType = New FarPoint.Web.Spread.DoubleCellType
dct1.FixedPoint = True
dct1.DecimalDigits = 4
dct1.NumberFormat = ninfo1
FpSpread1.ActiveSheetView.Columns(1).CellType = dct1
Dim dct2 As FarPoint.Web.Spread.DoubleCellType = New FarPoint.Web.Spread.DoubleCellType
dct2.FixedPoint = True
dct2.DecimalDigits = 1
dct2.NumberFormat = ninfo2
FpSpread1.ActiveSheetView.Columns(2).CellType = dct2
FpSpread1.ActiveSheetView.Cells(0, 1).Value = 10.0123
FpSpread1.ActiveSheetView.Cells(0, 2).Value = 20.5
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pathname As String = HttpContext.Current.Server.MapPath(Request.ApplicationPath & "/")
FpSpread1.SaveExcel(pathname + "test.xls")
End Sub
キーワード
SPRN06886
この文書は、以前は次のバグレポートIDで公開されていました : 7568