2016-05-23 6 views
2

現在Open XMLフレームワークを使用してExcelファイルをエクスポートする必要があります。私が持っている問題は、このスプレッドシートの列の1つが合計を許さなければならない形式(#、###。##)の小数でなければならないということです。私は、次の方法を使用して、この形式で完全にExcelをエクスポートすることができます:あなたが見ることができるように、私は私が言及したフォーマットを適用するStyleIndexを指定していOpenXMLでFormat(#、###。##)を使用して10進数のCellValueを作成する方法

private static Cell CreateTextCell(string header, UInt32 index, object text, CellStyleIndex cellStyle) 
{ 
    var cell = new Cell 
    { 
     DataType = CellValues.InlineString, 
     CellReference = header + index, 
     StyleIndex = (UInt32)cellStyle 
    }; 

    var istring = new InlineString(); 
    var t = new Text { Text = text.ToString() }; 
    istring.AppendChild(t); 
    cell.AppendChild(istring); 
    return cell; 
} 

。しかし、これに伴う問題は、Excelがテキストとして、この値を認識していることである:

:私はできるだけ早く私は、ファイル内の小数点以下を作成したい呼び出される新しいメソッドを作成しようとしましたている理由

enter image description here

これにより

private static Cell CreateValueCell(string header, UInt32 index, decimal value, CellStyleIndex cellStyle) 
{ 
    var cell = new Cell 
    { 
     DataType = CellValues.Number, 
     CellReference = header + index, 
     StyleIndex = (UInt32)cellStyle, 
     CellValue = new CellValue(value.ToString()) 
    }; 

    return cell; 
} 

は、私が数として変換する方法達していますが、次の画像で見ることができるように私は小数点以下を失う:

enter image description here

DecimalValueという名前のクラスを見ましたが、セルに追加する方法を理解できませんでした。どのようにそれを解決するための任意の考えですか?

答えて

4

that articleをお読みください。

メインコンセプトはNumberingFormatでカスタムCellFormatを使用している:

var nformat4Decimal = new NumberingFormat 
        { 
         NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++), 
         FormatCode = StringValue.FromString("#,##0.0000") 
        }; 
関連する問題